aboutsummaryrefslogtreecommitdiff
path: root/gamemode/core/combat/sv_weaponswing.lua
diff options
context:
space:
mode:
Diffstat (limited to 'gamemode/core/combat/sv_weaponswing.lua')
-rw-r--r--gamemode/core/combat/sv_weaponswing.lua53
1 files changed, 49 insertions, 4 deletions
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)