From 81d3d4eb333e226432a591461b84ed12f5ac9a3f Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sat, 21 Jul 2018 19:08:34 -0400 Subject: Various updates * Animation api now allows sequences to be played * items now have a .inv attribute that is set when they are added to shaped or equipment inventories * Refactored the way skill inventory is structured * Added some more methods to cl_common to move items around on a player * Minor update to nrequire to display purple message when asked to include a file that dosn't exist. --- gamemode/core/animation/cl_animate.lua | 23 +++++++++++++++++++++ gamemode/core/animation/sh_animations.lua | 20 +++++++++++++++++++ gamemode/core/animation/sv_animate.lua | 33 +++++++++++++++++++++++++++++++ gamemode/core/inventory/cl_invtracker.lua | 3 ++- gamemode/core/inventory/sv_invtracker.lua | 14 +++++++++++++ gamemode/core/pac/cl_pac.lua | 8 +++++--- 6 files changed, 97 insertions(+), 4 deletions(-) (limited to 'gamemode/core') diff --git a/gamemode/core/animation/cl_animate.lua b/gamemode/core/animation/cl_animate.lua index fd322a1..c7dc19d 100644 --- a/gamemode/core/animation/cl_animate.lua +++ b/gamemode/core/animation/cl_animate.lua @@ -11,3 +11,26 @@ net.Receive("art_stop_animation",function() local anim = net.ReadString() what:StopLuaAnimation(anim) end) + +local sequences = {} +net.Receive("art_start_sequence",function() + local who = net.ReadEntity() + local seq = net.ReadUInt(31) + local time = net.ReadFloat() + local untilstoped = net.ReadBool() + local speed = net.ReadFloat() + sequences[who] = sequences[who] or {} + who:SetCycle(0) + if untilstoped then + sequences[who] = {CurTime() + 9999999, seq, speed} + else + sequences[who] = {CurTime() + time, seq, speed} + end +end) + +net.Receive("art_end_sequence",function() + local who = net.ReadEntity() + sequences[who] = nil +end) + +return sequences diff --git a/gamemode/core/animation/sh_animations.lua b/gamemode/core/animation/sh_animations.lua index 3846fcc..a1430a5 100644 --- a/gamemode/core/animation/sh_animations.lua +++ b/gamemode/core/animation/sh_animations.lua @@ -2,3 +2,23 @@ if not RegisterLuaAnimation then error("JetBoom's libanimbone is required for animations. (It's bundeled with PAC3)") return end + +local sequences +local log = nrequire("log.lua") +if SERVER then + sequences = nrequire("core/animation/sv_animate.lua") +else -- CLIENT + sequences = nrequire("core/animation/cl_animate.lua") +end + +hook.Add("UpdateAnimation","art_updateanim",function(ply,vel,mgs) + if sequences and ply and sequences[ply] and CurTime() < sequences[ply][1] then + ply:SetPlaybackRate(sequences[ply][3]) + end +end) + +hook.Add("CalcMainActivity","art_swing",function(ply,vel) + if sequences and ply and sequences[ply] and CurTime() < sequences[ply][1] then + return -1, sequences[ply][2] + end +end) diff --git a/gamemode/core/animation/sv_animate.lua b/gamemode/core/animation/sv_animate.lua index 24d0ed0..b8cec56 100644 --- a/gamemode/core/animation/sv_animate.lua +++ b/gamemode/core/animation/sv_animate.lua @@ -5,6 +5,8 @@ local meta = FindMetaTable("Player") util.AddNetworkString("art_start_animation") util.AddNetworkString("art_stop_animation") +util.AddNetworkString("art_start_sequence") +util.AddNetworkString("art_end_sequence") function meta:StartAnimation(name) net.Start("art_start_animation") @@ -19,3 +21,34 @@ function meta:StopAnimation(name) net.WriteString(name) net.Broadcast() end + +local sequences = {} + +function meta:StartSequence(name,untilstoped,speed) + untilstoped = untilstoped or false + speed = speed or 1 + local seq, time = self:LookupSequence(name) + sequences[self] = sequences[self] or {} + if untilstoped then + sequences[self] = {CurTime() + 9999999, seq, speed} + else + sequences[self] = {CurTime() + time, seq, speed} + end + self:SetCycle(0) + net.Start("art_start_sequence") + net.WriteEntity(self) + net.WriteUInt(seq,31) + net.WriteFloat(time) + net.WriteBool(untilstoped) + net.WriteFloat(speed) + net.Broadcast() +end + +function meta:EndSequence(name) + sequences[self] = nil + net.Start("art_end_sequence") + net.WriteEntity(self) + net.Broadcast() +end + +return sequences diff --git a/gamemode/core/inventory/cl_invtracker.lua b/gamemode/core/inventory/cl_invtracker.lua index dac1cc2..e6633f9 100644 --- a/gamemode/core/inventory/cl_invtracker.lua +++ b/gamemode/core/inventory/cl_invtracker.lua @@ -4,7 +4,7 @@ local inv = nrequire("inventory/inventory.lua") local itm = nrequire("item.lua") -nrequire("cl_loadglobals.lua") +-- nrequire("cl_loadglobals.lua") --local state = nrequire("cl_state.lua") local q = {} @@ -98,6 +98,7 @@ net.Receive("art_UpdateInventory",function() local item_data = net.ReadData(net.ReadUInt(32)) local item = itm.GetItemFromData(item_name,item_data) known_inventories[id]:Put(position,item) + item.inv = known_inventories[id] --print("Inventorie's observers:") --PrintTable(known_inventories[id].observers) --print("Inventory is now") diff --git a/gamemode/core/inventory/sv_invtracker.lua b/gamemode/core/inventory/sv_invtracker.lua index ed5da4a..b6f6b52 100644 --- a/gamemode/core/inventory/sv_invtracker.lua +++ b/gamemode/core/inventory/sv_invtracker.lua @@ -223,6 +223,20 @@ function plymeta:HasItem(ptr) return false end +--- Gets a refrence to an item without removeing it +-- Gets an item, if you want to look at the fields without changing them. +-- If you do need to change fields, remove the item, change the field, then +-- re-give the item. +--@metamethod player:GetItem(loc) +--@tparam table loc The position of the item (returned by plymeta:HasItem()) +--@treturn itemtbl The item at the location +function plymeta:GetItem(loc) + local nid = loc[1] + local pos = loc[2] + local item = self.data.inventories[nid]:Get(pos) + return item +end + ---A shortcut to remove an item from a player. -- Removes an item from a player and returns the item --@metamethod player:RemoveItem(tbl) diff --git a/gamemode/core/pac/cl_pac.lua b/gamemode/core/pac/cl_pac.lua index 477d65d..69e993a 100644 --- a/gamemode/core/pac/cl_pac.lua +++ b/gamemode/core/pac/cl_pac.lua @@ -1,4 +1,5 @@ +local log = nrequire("log.lua") --As soon as the client connects, request the names of all the pac's on the server --If the player dosen't have PAC3 installed, then overwrite all pac-related network events to display an error. @@ -42,12 +43,12 @@ local function loadpac(ent,name,hash) return end end - if filetext and (tonumber(util.CRC(filetext)) == hash) then + if filetext and tonumber(util.CRC(filetext)) 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...") + log.debug(string.format("File out of date (%d vs %d) Re-downloading...", filetext and tonumber(util.CRC(filetext)) or 0 , hash)) net.Start("artery_requestpac") net.WriteString(name) net.SendToServer() @@ -68,7 +69,8 @@ end net.Receive("artery_downloadpac",function() local pac_name = net.ReadString() local pac_txt = net.ReadString() - --local pac_hash = net.ReadUInt(32) + local pac_hash = net.ReadUInt(32) + log.debug(string.format("Received file %s with hash %d", pac_name, pac_hash)) local filepath = string.format(CLIENT_PAC_DIR .. "/%s.txt",pac_name) file.Write(filepath,pac_txt) end) -- cgit v1.2.3-70-g09d2