diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2017-08-17 13:38:38 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2017-08-17 13:38:38 -0400 |
| commit | 77b2974db2a719fbc92734cc88df73b1f1c41b0a (patch) | |
| tree | ed54956006b8c37229ba5c0d86a0d3626f1928ad /gamemode | |
| parent | 0916a769c3fea30887dd90237d17095b456a7a9e (diff) | |
| download | artery-77b2974db2a719fbc92734cc88df73b1f1c41b0a.tar.gz artery-77b2974db2a719fbc92734cc88df73b1f1c41b0a.tar.bz2 artery-77b2974db2a719fbc92734cc88df73b1f1c41b0a.zip | |
Fixed recording weapon swings
Diffstat (limited to 'gamemode')
| -rw-r--r-- | gamemode/core/combat/cl_weaponswing.lua | 43 | ||||
| -rw-r--r-- | gamemode/core/combat/sv_weaponswing.lua | 113 | ||||
| -rw-r--r-- | gamemode/core/pac/cl_pac.lua | 2 | ||||
| -rw-r--r-- | gamemode/server/sv_mapchange.lua | 119 |
4 files changed, 237 insertions, 40 deletions
diff --git a/gamemode/core/combat/cl_weaponswing.lua b/gamemode/core/combat/cl_weaponswing.lua index 46603ba..54f7dee 100644 --- a/gamemode/core/combat/cl_weaponswing.lua +++ b/gamemode/core/combat/cl_weaponswing.lua @@ -1,5 +1,6 @@ local CLIENT_PAC_DIR = "artery/client/pacs" local itm = nrequire("item.lua") +local stt = nrequire("cl_state.lua") local ball function finddmgpoint(name) local filepath = string.format(CLIENT_PAC_DIR .. "/%s.txt",name) @@ -15,12 +16,23 @@ function finddmgbox(who,name) 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 +local animent + +local swingtodraw = nil +hook.Add("PreDrawTranslucentRenderables","draw_wepswing",function() + local lpp = LocalPlayer():GetPos() + if swingtodraw ~= nil then + for i = 2, #swingtodraw do + render.DrawLine( lpp + swingtodraw[i], lpp + swingtodraw[i-1], Color(255,0,0,255), false ) + render.DrawLine( lpp + swingtodraw[i], lpp + swingtodraw[i-1] + Vector(0,0,10), Color(0,255,0,255), false ) + end + end +end) net.Receive("artery_doanimation",function() local animname = net.ReadString() @@ -29,23 +41,30 @@ net.Receive("artery_doanimation",function() local pacname = net.ReadString() local animdir = net.ReadString() local who = net.ReadEntity() + local waittime = net.ReadDouble() swingtbl = {} --pac.SetupENT(who) finddmgbox(who,pacname) - tracking = true + animent = who print("Doing animation:",animname,animtime,echoname) + who:SetupBones() who:SetLuaAnimation(animname) + stt.invopen=true + timer.Simple(waittime,function() + tracking = true + end) timer.Simple(animtime,function() tracking = false + stt.invopen=false + print("Stopping animation",animname) who:StopLuaAnimation(animname) net.Start("artery_notifyserverofswing") net.WriteString(wepname) - net.WriteString(animdir) - print("Seding swingtbl:") - PrintTable(swingtbl) + net.WriteString(animname) net.WriteTable(swingtbl) net.SendToServer() + swingtodraw = swingtbl end) end) @@ -57,16 +76,14 @@ concommand.Add("artery_startanimation",function(ply,cmd,args) end) end) ---[[ local lastpos hook.Add("Tick","trace_weppos",function() - if not ball or not ball.Entity then return end + if not IsValid(ball) or not IsValid(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 - swingtbl[#swingtbl + 1] = ball.Entity:GetPos() - LocalPlayer():GetPos() - print(ball.Entity:GetPos() - LocalPlayer():GetPos()) + --print("Distance between ", ball.Entity:GetPos(), "and", lastpos, " is" ,ball.Entity:GetPos():Distance(lastpos)) + if --[[ball.Entity:GetPos():Distance(lastpos) > 0.5 and]] tracking then + swingtbl[#swingtbl + 1] = ball.Entity:GetPos() - animent:GetPos() + --print(ball.Entity:GetPos() - animent:GetPos()) + lastpos = ball.Entity:GetPos() end - lastpos = ball.Entity:GetPos() end) -]] 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 diff --git a/gamemode/core/pac/cl_pac.lua b/gamemode/core/pac/cl_pac.lua index 4f1890c..7e149ae 100644 --- a/gamemode/core/pac/cl_pac.lua +++ b/gamemode/core/pac/cl_pac.lua @@ -40,9 +40,11 @@ local function loadpac(ent,name,hash) assert(ent.AttachPACPart ~= nil,"Failed to set up ent",ent) end if filetext and (tonumber(util.CRC(filetext)) == hash) then + print("The file on our local system is up to date, applying!") local pactbl = CompileString(string.format("return {%s}",filetext),name)() ent:AttachPACPart(pactbl) else--Cache is old, download the new pac! + print("The file on our local system was out of date! Downloading...") net.Start("artery_requestpac") net.WriteString(name) net.SendToServer() diff --git a/gamemode/server/sv_mapchange.lua b/gamemode/server/sv_mapchange.lua index ede6962..d697a67 100644 --- a/gamemode/server/sv_mapchange.lua +++ b/gamemode/server/sv_mapchange.lua @@ -2,11 +2,70 @@ A script to move the player to a different map ]] local fn = nrequire("utility/fn.lua") -local q = nrequire("core/database/sv_queries.lua") +local q = nrequire("core/database/queries.lua") nrequire("sv_mysqlite.lua") local mapname = game.GetMap() local mapareasstr = file.Read("artery/maps/" .. mapname .. "/mapareas.txt") +--[=[ +local dontupdatedisconnect = {} + +hook.Add("InitPostEntity", "LoadMapChangePoints", function() + local transfers = string.Explode("\r?\n\r?\n",mapareasstr,true) + for k,v in pairs(transfers) do + local parts = string.Explode("\r?\n",v,true) + local vectortxt = string.Explode(" ",parts[1],false) + local svec = Vector(vectortxt[1],vectortxt[2],vectortxt[3]) + local name = parts[2] + local server = parts[3] + local model = parts[4] + local tvt = string.Explode(" ",parts[5],false) + + local sch = ents.Create("art_serverchanger") + sch.Model = model + sch.Pos = svec + sch.OnHit = function(self, coldata,collider) + print("Coldata") + PrintTable(coldata) + print("collider",collider) + if coldata.HitEntity:IsPlayer() then + dontupdatedisconnect[coldata.HitEntity] = true + local qc = table.concat({[[ + UPDATE playerdata SET MetaData="]], + tvt[1]," ", + tvt[2]," ", + tvt[3]," ", + [[" WHERE SteamID="]], + coldata.HitEntity:SteamID64(), + '"'}) + local query = [[ + UPDATE playerdata SET PlayerData='%s',MetaData='%s' WHERE SteamID=%.0f + ]] + local pdat = util.TableToJSON(coldata.HitEntity.data) + local pmet = util.TableToJSON({ + lastserver = server, + lastlocation = parts[5] + }) + print("pdat is", pdat) + print("pmet is", pmet) + local fquery = q.s_fmt(query,pdat,pmet,coldata.HitEntity:SteamID64()) + print("fquery was", fquery) + print("Running query:",qc) + MySQLite.query(fquery,function(data) + coldata.HitEntity:ConCommand("connect " .. server) + end,function(err,sql) + print("Query error:") + print("Query",sql) + print("Error",err) + end) + end + end + sch:Spawn() + print("Loading mapchange area",svec) + end +end) +]=] + local function SavePlayerData(ply) local query local pdat = q.serialize_player(ply) @@ -35,4 +94,60 @@ local function SavePlayerData(ply) end) end -hook.Add("PlayerDisconnected","SavePlayerData",SavePlayerData) +--[=[ +hook.Add("PlayerDisconnected","SavePlayerData",function(ply) + local qc + if dontupdatedisconnect[ply] then + dontupdatedisconnect[ply] = nil + qc = table.concat({ + [[UPDATE artery.playerdata SET + Inventory="]], + util.TableToJSON(ply.Inventory), + [[", + Skills="]], + util.TableToJSON(ply.Skills), + [[", + Quests="]], + util.TableToJSON(ply.Quests), + [[" + WHERE SteamID = "]], + ply:SteamID64(), + [[";]] + }) + else + local pp = ply:GetPos() + qc = table.concat({ + [[UPDATE artery.playerdata SET + Inventory="]], + util.TableToJSON(ply.Inventory), + [[", + Skills="]], + util.TableToJSON(ply.Skills), + [[", + Quests="]], + util.TableToJSON(ply.Quests), + [[", + WorldPosition="]], + pp[1]," ",pp[2]," ",pp[3], + [[", + World="]], + game.GetIPAddress(), + [[" + WHERE SteamID = "]], + ply:SteamID64(), + [[";]] + }) + end + local q = ART.database:query(qc) + function q:onSuccess(data) + print("Saveing player data successful") + PrintTable(data) + end + function q:onError(err, sql) + print("Saveing player data errored!") + print("Query",sql) + error(err) + end + q:start() +end) +]=] |
