diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2017-08-17 14:58:30 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2017-08-17 14:58:30 -0400 |
| commit | 7854175815e88b0d25cd4f0c0f170602ffb8169f (patch) | |
| tree | 5d03fe92d59a92df6bad9f09083e470a5b23ccfc /gamemode | |
| parent | 77b2974db2a719fbc92734cc88df73b1f1c41b0a (diff) | |
| download | artery-7854175815e88b0d25cd4f0c0f170602ffb8169f.tar.gz artery-7854175815e88b0d25cd4f0c0f170602ffb8169f.tar.bz2 artery-7854175815e88b0d25cd4f0c0f170602ffb8169f.zip | |
Added methods for weapons to use recorded swings
Diffstat (limited to 'gamemode')
| -rw-r--r-- | gamemode/core/combat/cl_weaponswing.lua | 17 | ||||
| -rw-r--r-- | gamemode/core/combat/sv_weaponswing.lua | 104 |
2 files changed, 57 insertions, 64 deletions
diff --git a/gamemode/core/combat/cl_weaponswing.lua b/gamemode/core/combat/cl_weaponswing.lua index 54f7dee..74365b1 100644 --- a/gamemode/core/combat/cl_weaponswing.lua +++ b/gamemode/core/combat/cl_weaponswing.lua @@ -24,6 +24,10 @@ local tracking = false local animent local swingtodraw = nil +net.Receive("artery_setswingdebug",function() + swingtodraw = net.ReadTable() +end) + hook.Add("PreDrawTranslucentRenderables","draw_wepswing",function() local lpp = LocalPlayer():GetPos() if swingtodraw ~= nil then @@ -34,6 +38,17 @@ hook.Add("PreDrawTranslucentRenderables","draw_wepswing",function() end end) +net.Receive("artery_weaponswing",function() + local animname = net.ReadString() + local who = net.ReadEntity() + local duration = net.ReadDouble() + who:SetLuaAnimation(animname) + timer.Simple(duration,function() + who:StopLuaAnimation(animname) + end) + +end) + net.Receive("artery_doanimation",function() local animname = net.ReadString() local animtime = net.ReadDouble() @@ -61,7 +76,7 @@ net.Receive("artery_doanimation",function() who:StopLuaAnimation(animname) net.Start("artery_notifyserverofswing") net.WriteString(wepname) - net.WriteString(animname) + net.WriteString(animdir) net.WriteTable(swingtbl) net.SendToServer() swingtodraw = swingtbl 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) |
