From 461a29d8fdb2fd6c86a77912e9c2232e1f101ca8 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Mon, 19 Jun 2017 00:07:01 -0400 Subject: Massive updates Lots of stuff was updated, mostly to support addons. Inventory tracking is also updated a little and a bug fixed in inventory. Nrequire now probably won't crash the client, no matter how many times it's used. --- gamemode/core/combat/cl_weaponswing.lua | 25 ++++++++++++---- gamemode/core/combat/sv_weaponswing.lua | 53 ++++++++++++++++++++++++++++++--- 2 files changed, 69 insertions(+), 9 deletions(-) (limited to 'gamemode/core/combat') diff --git a/gamemode/core/combat/cl_weaponswing.lua b/gamemode/core/combat/cl_weaponswing.lua index 8ed9637..46603ba 100644 --- a/gamemode/core/combat/cl_weaponswing.lua +++ b/gamemode/core/combat/cl_weaponswing.lua @@ -1,5 +1,5 @@ local CLIENT_PAC_DIR = "artery/client/pacs" - +local itm = nrequire("item.lua") local ball function finddmgpoint(name) local filepath = string.format(CLIENT_PAC_DIR .. "/%s.txt",name) @@ -8,6 +8,16 @@ function finddmgpoint(name) ball = LocalPlayer():FindPACPart(outfit, "wep_point") print("point is",ball,type(ball)) end +function finddmgbox(who,name) + local filepath = string.format(CLIENT_PAC_DIR .. "/%s.txt",name) + local filetext = file.Read(filepath,"DATA") + assert(filetext ~= nil, string.format("Could not find a pac file for name %q (%s)",name,filepath)) + local outfit = CompileString(string.format("return {%s}",filetext),name)() + assert(outfit ~= nil, string.format("Failed to compile %q",filetext)) + ball = who:FindPACPart(outfit, "wep_box") + print("box is", ball,type(ball)) + assert(ball ~= pac.NULL, string.format("Could not find a prop called %q on pac %q","web_box",name)) +end local swingtbl = {} local tracking = false @@ -16,16 +26,19 @@ net.Receive("artery_doanimation",function() local animname = net.ReadString() local animtime = net.ReadDouble() local wepname = net.ReadString() + local pacname = net.ReadString() local animdir = net.ReadString() + local who = net.ReadEntity() swingtbl = {} + --pac.SetupENT(who) + finddmgbox(who,pacname) tracking = true - finddmgpoint(wepname) print("Doing animation:",animname,animtime,echoname) - LocalPlayer():SetLuaAnimation(animname) + who:SetLuaAnimation(animname) timer.Simple(animtime,function() tracking = false - LocalPlayer():StopLuaAnimation(animname) + who:StopLuaAnimation(animname) net.Start("artery_notifyserverofswing") net.WriteString(wepname) net.WriteString(animdir) @@ -44,9 +57,10 @@ concommand.Add("artery_startanimation",function(ply,cmd,args) end) end) +--[[ local lastpos hook.Add("Tick","trace_weppos",function() - if not ball then return end + if not ball or not ball.Entity then return end if lastpos == nil then lastpos = ball.Entity:GetPos() end --`print("Distance between ", ball.Entity:GetPos(), "and", lastpos, " is" ,ball.Entity:GetPos():Distance(lastpos)) if ball.Entity:GetPos():Distance(lastpos) > 2 and tracking then @@ -55,3 +69,4 @@ hook.Add("Tick","trace_weppos",function() end lastpos = ball.Entity:GetPos() end) +]] diff --git a/gamemode/core/combat/sv_weaponswing.lua b/gamemode/core/combat/sv_weaponswing.lua index f238497..408e7d2 100644 --- a/gamemode/core/combat/sv_weaponswing.lua +++ b/gamemode/core/combat/sv_weaponswing.lua @@ -2,6 +2,7 @@ This file tells you what weapons need their swings recalculated ]] local itm = nrequire("core/inventory/item.lua") +local inv = nrequire("core/inventory/inventory.lua") local ws = {} --Cache swing hits, if we used one once, we'll probably use it again soon @@ -41,10 +42,52 @@ function ws.makeSwingable(tbl) swingable[tbl.Name] = tbl end +local function record_animations_for(swingable, e) + print("recording animations on", e) + PrintTable(swingable) + local einv = e.data.inventories[1] + local spot = einv:FindPlaceFor(swingable) + assert(spot != nil, "Could not equip the npc with that") + einv:Put(spot,swingable) + for k,v in pairs(swingable.attacks) do + net.Start("artery_doanimation") + net.WriteString(v.anim) + net.WriteDouble(v.time) + net.WriteString(swingable.Name) + net.WriteString(swingable.pacname) + net.WriteString(".") + net.WriteEntity(e) + net.Broadcast() + end + timer.Simple(5,function() + --assert(IsValid(einv),"Npc's inventory is no longer valid!") + einv:Remove(spot) + end) +end + +--Create a fake thing in front of the player, do the swing animations, and record them. concommand.Add("artery_recordanimations",function(ply,cmd,args) + e = ents.Create("npc_citizen") + e:SetPos(ply:GetEyeTrace().HitPos) + e:Spawn() + e.data = {inventories = {}} + local einv = inv.CreateInventory("Equipment") + einv.id = 1 + einv.Owner = e + e.data.inventories[einv.id] = einv + local i = 1 + for k,v in pairs(swingable) do + timer.Simple(5*i,function() + record_animations_for(v,e) + end) + i = i + 1 + end + + --[[ local animqueuetime = 0 for k,v in pairs(swingable) do --equip the right item + print("equipable inventory:") local eqi = ply.data.inventories[1] print(ply.data.inventories[1]) @@ -60,16 +103,18 @@ concommand.Add("artery_recordanimations",function(ply,cmd,args) print("Doing attack:") print(i,":",j) net.Start("artery_doanimation") - net.WriteString(j.anim) - net.WriteDouble(j.time) - net.WriteString(v.Name) - net.WriteString(i) + net.WriteString(j.anim) --Animation name (to return) + net.WriteDouble(j.time) --Timeing of the animation + net.WriteString(v.Name) --Name of the item (to return) + net.WriteString(v.pacname) --Name of the pac for this item + net.WriteString(i) --direction of the animation (to return) net.Send(ply) end) animqueuetime = animqueuetime + j.time + 1 end end + ]] end) -- cgit v1.2.3-70-g09d2