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.lua113
1 files changed, 88 insertions, 25 deletions
diff --git a/gamemode/core/combat/sv_weaponswing.lua b/gamemode/core/combat/sv_weaponswing.lua
index 408e7d2..b3361f7 100644
--- a/gamemode/core/combat/sv_weaponswing.lua
+++ b/gamemode/core/combat/sv_weaponswing.lua
@@ -12,6 +12,9 @@ local swingcache = {} --Swing arc cache
--A table of all the items that are swingable
local swingable = {}
+--A queue of {pac, animation_name, animation_time, mapping,item_tbl}
+local recordqueue = {}
+
util.AddNetworkString("artery_notifyserverofswing")
util.AddNetworkString("artery_doanimation")
@@ -36,6 +39,8 @@ net.Receive("artery_notifyserverofswing",function()
end)
function ws.makeSwingable(tbl)
+ print("Makeing a swingable out of:")
+ PrintTable(tbl)
assert(tbl.Name,"Tried to make a swingable weapon out of an item with no name!")
assert(tbl.attacks,"Tried to make a swingable weapon out of an item with no attacks! See rustyaxe.lua for example")
assert(tbl.pacname,"Tried to make a swingable weapon without a pac name! see rustyaxe.lua for example")
@@ -49,16 +54,19 @@ local function record_animations_for(swingable, e)
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
+ --Give the client time to download the pac & apply it
+ timer.Simple(1.1,function()
+ 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
+ end)
timer.Simple(5,function()
--assert(IsValid(einv),"Npc's inventory is no longer valid!")
einv:Remove(spot)
@@ -67,22 +75,78 @@ 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
+ --Create an npc with the equipment inventory
+ -- 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 e = ply
+ e:SetAngles(Angle(0,0,0))
+
+ --Add everything in swingables to a queue to be recorded
for k,v in pairs(swingable) do
- timer.Simple(5*i,function()
- record_animations_for(v,e)
- end)
- i = i + 1
+ for i,j in pairs(v.attacks) do
+ local tn = {
+ v.pacname,
+ j.anim,
+ j.time,
+ i,
+ v,
+ j.waittime
+ }
+ recordqueue[#recordqueue + 1] = tn
+ end
end
+ --Create timers for everything
+ local timefromnow = 0
+ for k,v in ipairs(recordqueue) do
+ timefromnow = timefromnow + 1
+ print("timefromnow 1 is",timefromnow)
+ --Put the item into the inventory
+ local tfunc = function(nowtime)
+ local whentoremove = nowtime + 1 + v[3] + 1
+ timer.Simple(nowtime,function()
+ print("timefromnow 2 is",nowtime)
+ local einv = e.data.inventories[1]
+ local spot = einv:FindPlaceFor(v[5])
+ assert(spot != nil, "Could not equip the npc with " .. v[5].Name)
+ einv:Put(spot,v[5])
+ print("Placed item in inventory")
+ --Wait 1 second to de-apply the pac and remove the item
+ print("I will remove the item in", v[3])
+ timer.Simple(v[3],function()
+ print("removeing equiped...")
+ einv:Remove(spot)
+ end)
+ end)
+ end
+ tfunc(timefromnow)
+ print("timefromnow 3 is",timefromnow)
+ local tfunc2 = function(nowtime)
+ timer.Simple(nowtime,function()
+ print("timefromnow 4 is",nowtime)
+ net.Start("artery_doanimation")
+ net.WriteString(v[2])
+ net.WriteDouble(v[3])
+ net.WriteString(v[5].Name)
+ net.WriteString(v[1])
+ net.WriteString(v[4])
+ net.WriteEntity(e)
+ net.WriteDouble(v[6])
+ net.Broadcast()
+ end)
+ end
+ --Wait 1 second for the pac to apply
+ timefromnow = timefromnow + 1
+ tfunc2(timefromnow)
+ timefromnow = timefromnow + 1 + v[3] + 1 --Wait for anim to be recorded, and the thing to be removed
+ end
+ recordqueue = {}
--[[
local animqueuetime = 0
for k,v in pairs(swingable) do
@@ -124,7 +188,7 @@ concommand.Add("artery_checkSwingable",function(ply,cmd,args)
local noswingdata = {}
for k,v in pairs(swingable) do
--Make sure we have a weapon path for everything
- if file.Exists( "artery/dynamic/swingdata/" .. k, "DATA" ) then
+ if file.Exists( "artery/dynamic/swingdata/" .. k .. ".txt", "DATA" ) then
MsgC(Color(0,255,0),"Found data for " .. k .. "\n")
else
MsgC(Color(255,0,0),"Couldn't find data for " .. k .. "\n")
@@ -140,5 +204,4 @@ concommand.Add("artery_clearswingable",function(ply,cmd,args)
swingable = {}
end)
-
return ws