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.lua104
1 files changed, 41 insertions, 63 deletions
diff --git a/gamemode/core/combat/sv_weaponswing.lua b/gamemode/core/combat/sv_weaponswing.lua
index b3361f7..9dd1924 100644
--- a/gamemode/core/combat/sv_weaponswing.lua
+++ b/gamemode/core/combat/sv_weaponswing.lua
@@ -3,6 +3,7 @@
]]
local itm = nrequire("core/inventory/item.lua")
local inv = nrequire("core/inventory/inventory.lua")
+local wep = nrequire("core/inventory/common/weapons.lua")
local ws = {}
--Cache swing hits, if we used one once, we'll probably use it again soon
@@ -17,6 +18,8 @@ local recordqueue = {}
util.AddNetworkString("artery_notifyserverofswing")
util.AddNetworkString("artery_doanimation")
+util.AddNetworkString("artery_weaponswing")
+util.AddNetworkString("artery_setswingdebug")
net.Receive("artery_notifyserverofswing",function()
local weapon = net.ReadString()
@@ -47,45 +50,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)
- --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()
+function ws.doSwing(weapon,ply)
+ local dir = wep.playermovedir(ply)
+ local fdata = file.Read("artery/dynamic/swingdata/" .. weapon.Name .. ".txt")
+ local swingtbl = util.JSONToTable(util.Decompress(fdata))
+ print("swingtable was", swingtbl)
+ PrintTable(swingtbl)
+ print("dir was",dir)
+ if swingtbl[dir] == nil then return end
+ local tswing = swingtbl[dir]
+ for k,v in pairs(tswing) do
+ v:Rotate(ply:EyeAngles())
+ end
+ local timedelay = weapon.attacks[dir].waittime
+ local hitthings = {}
+ net.Start("artery_weaponswing")
+ net.WriteString(weapon.attacks[dir].anim)
+ net.WriteEntity(ply)
+ net.WriteDouble(weapon.attacks[dir].time)
+ net.Broadcast()
+ timer.Simple(timedelay,function()
+ net.Start("artery_setswingdebug")
+ net.WriteTable(tswing)
+ net.Broadcast()
+ local pp = ply:GetPos()
+ for i = 2, #tswing do
+ local s = tswing[i] + pp
+ local e = tswing[i-1] + pp
+ local tr = util.TraceLine({
+ start = s,
+ endpos = e,
+ filter = ply
+ })
+ if tr.Hit then
+ hitthings[#hitthings + 1] = tr.Entity
+ end
end
- end)
- timer.Simple(5,function()
- --assert(IsValid(einv),"Npc's inventory is no longer valid!")
- einv:Remove(spot)
+ print("Hit:")
+ PrintTable(hitthings)
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)
- --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))
+ e:SetEyeAngles(Angle(0,0,0))
--Add everything in swingables to a queue to be recorded
for k,v in pairs(swingable) do
@@ -147,38 +157,6 @@ concommand.Add("artery_recordanimations",function(ply,cmd,args)
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
- --equip the right item
-
- print("equipable inventory:")
- local eqi = ply.data.inventories[1]
- print(ply.data.inventories[1])
- local itm = eqi:Get({v.Equipable})
- if itm ~= nil then
- eqi:Remove({v.Equipable})
- end
- eqi:Put({v.Equipable},v)
-
- --queue up each attack for the player to do
- for i,j in pairs(v.attacks) do
- timer.Simple(animqueuetime,function()
- print("Doing attack:")
- print(i,":",j)
- net.Start("artery_doanimation")
- 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)