From d5a98659d51c40e82304ada84674154bfbed4aa6 Mon Sep 17 00:00:00 2001 From: unknao Date: Sat, 3 Aug 2024 18:53:46 +0300 Subject: [PATCH 1/4] added holoAnim functions --- .../gmod_wire_expression2/core/hologram.lua | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) diff --git a/lua/entities/gmod_wire_expression2/core/hologram.lua b/lua/entities/gmod_wire_expression2/core/hologram.lua index eff492bc5f..581f8e0f92 100644 --- a/lua/entities/gmod_wire_expression2/core/hologram.lua +++ b/lua/entities/gmod_wire_expression2/core/hologram.lua @@ -328,10 +328,12 @@ local function flush_player_color_queue() net.Broadcast() end + registerCallback("postexecute", function(self) if timer.Exists("wire_hologram_postexecute_"..self.uid) then return end timer.Create("wire_hologram_postexecute_"..self.uid,0.1,1,function() if not IsValid(self.entity) then return end + flush_scale_queue() flush_bone_scale_queue() flush_clip_queue() @@ -1276,6 +1278,165 @@ end -- ----------------------------------------------------------------------------- +local function SetHoloAnim(Holo, Animation, Frame, Rate) + if (Holo and Animation and Frame and Rate) then + if not Holo.ent.Animated then + -- This must be run once on entities that will be animated + Holo.ent.Animated = true + Holo.ent.AutomaticFrameAdvance = true + + local OldThink = Holo.ent.Think + function Holo.ent:Think() + OldThink(self) + self:NextThink(CurTime()) + return true + end + end + Holo.ent:ResetSequence(Animation) + Holo.ent:SetCycle(math.Clamp(Frame, 0, 1)) + --Something mustve changed between the time holoAnim core was made and now, negative values no longer affect the "Frame" value + Holo.ent:SetPlaybackRate(math.Clamp(Rate, -12, 12)) + end +end + +__e2setcost(15) +e2function void holoAnim(index, string animation) + local Holo = CheckIndex(self, index) + if not Holo then return end + local anim = Holo.ent:LookupSequence(animation) + if anim == -1 then self:throw("'" .. animation .. "' does not exist on this model!", 0) end + + SetHoloAnim(Holo, anim, 0, 1) +end + +e2function void holoAnim(index, string animation, frame) + local Holo = CheckIndex(self, index) + if not Holo then return end + local anim = Holo.ent:LookupSequence(animation) + if anim == -1 then self:throw("'" .. animation .. "' does not exist on this model!", 0) end + + SetHoloAnim(Holo, Holo.ent:LookupSequence(animation), frame, 1) +end + +e2function void holoAnim(index, string animation, frame, rate) + local Holo = CheckIndex(self, index) + if not Holo then return end + local anim = Holo.ent:LookupSequence(animation) + if anim == -1 then self:throw("'" .. animation .. "' does not exist on this model!", 0) end + + SetHoloAnim(Holo, Holo.ent:LookupSequence(animation), frame, rate) +end + +e2function void holoAnim(index, animation) + local Holo = CheckIndex(self, index) + if not Holo then return end + + SetHoloAnim(Holo, animation, 0, 1) +end + +e2function void holoAnim(index, animation, frame) + local Holo = CheckIndex(self, index) + if not Holo then return end + + SetHoloAnim(Holo, animation, frame, 1) +end + +e2function number holoGetAnimFrame(index) + local Holo = CheckIndex(self, index) + if not Holo then return end + + return Holo.ent:GetCycle() +end + +e2function void holoAnim(index, animation, frame, rate) + local Holo = CheckIndex(self, index) + if not Holo then return end + + SetHoloAnim(Holo, animation, frame, rate) +end + +e2function array holoGetAnims(index) + local Holo = CheckIndex(self, index) + if not Holo then return end + + return Holo.ent:GetSequenceList() +end + +e2function number holoAnimLength(index) + local Holo = CheckIndex(self, index) + if not Holo then return end + + return Holo.ent:SequenceDuration() +end + +e2function number holoAnimNum(index, string animation) + local Holo = CheckIndex(self, index) + if not Holo then return end + + return Holo.ent:LookupSequence(animation) or 0 +end + +e2function number holoGetAnimGroundSpeed(index, string animation) + local Holo = CheckIndex(self, index) + if not Holo then return end + local anim = Holo.ent:LookupSequence(animation) + if anim == -1 then self:throw("'" .. animation .. "' does not exist on this model!", 0) end + + return Holo.ent:GetSequenceGroundSpeed(anim) +end + +e2function number holoGetAnimGroundSpeed(index, animation) + local Holo = CheckIndex(self, index) + if not Holo then return end + + return Holo.ent:GetSequenceGroundSpeed(animation) +end + +e2function void holoSetPose(index, string pose, value) + local Holo = CheckIndex(self, index) + if not Holo then return end + + Holo.ent:SetPoseParameter(pose, value) +end + +e2function number holoGetPose(index, string pose) + local Holo = CheckIndex(self, index) + if not Holo then return end + + local pose_param = Holo.ent:LookupPoseParameter(pose) + if pose_param == -1 then self:throw("'" .. pose .. "' pose parameter does not exist on this model!", 0) end + return Holo.ent:GetPoseParameter(pose_param) +end + +e2function array holoGetPoses(index) + local Holo = CheckIndex(self, index) + if not Holo then return end + + local tbl = {} + for i = 0, Holo.ent:GetNumPoseParameters() - 1 do + table.insert(tbl, Holo.ent:GetPoseParameterName(i)) + end + return tbl +end + +e2function vector2 holoGetPoseRange(index, string pose) + local Holo = CheckIndex(self, index) + if not Holo then return end + + local pose_param = Holo.ent:LookupPoseParameter(pose) + if pose_param == -1 then self:throw("'" .. pose .. "' pose parameter doesn't exist on this model!", 0) end + return { Holo.ent:GetPoseParameterRange(pose_param) } +end + +e2function void holoClearPoses(index) + local Holo = CheckIndex(self, index) + if not Holo then return end + + Holo.ent:ClearPoseParameters() +end + +-- ----------------------------------------------------------------------------- + registerCallback("construct", function(self) if not E2HoloRepo[self.uid] then E2HoloRepo[self.uid] = {} From d0d49d79ae359ae8f4fc32bcbbc46baabfd0133a Mon Sep 17 00:00:00 2001 From: unknao Date: Sat, 3 Aug 2024 19:52:42 +0300 Subject: [PATCH 2/4] removed redundancy & added e2helper descriptions --- .../gmod_wire_expression2/core/hologram.lua | 10 ++++------ lua/wire/client/e2descriptions.lua | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/hologram.lua b/lua/entities/gmod_wire_expression2/core/hologram.lua index 581f8e0f92..4b9244f534 100644 --- a/lua/entities/gmod_wire_expression2/core/hologram.lua +++ b/lua/entities/gmod_wire_expression2/core/hologram.lua @@ -1312,19 +1312,17 @@ end e2function void holoAnim(index, string animation, frame) local Holo = CheckIndex(self, index) if not Holo then return end - local anim = Holo.ent:LookupSequence(animation) - if anim == -1 then self:throw("'" .. animation .. "' does not exist on this model!", 0) end + if Holo.ent:LookupSequence(animation) == -1 then self:throw("'" .. animation .. "' does not exist on this model!", 0) end - SetHoloAnim(Holo, Holo.ent:LookupSequence(animation), frame, 1) + SetHoloAnim(Holo, animation, frame, 1) end e2function void holoAnim(index, string animation, frame, rate) local Holo = CheckIndex(self, index) if not Holo then return end - local anim = Holo.ent:LookupSequence(animation) - if anim == -1 then self:throw("'" .. animation .. "' does not exist on this model!", 0) end + if Holo.ent:LookupSequence(animation) == -1 then self:throw("'" .. animation .. "' does not exist on this model!", 0) end - SetHoloAnim(Holo, Holo.ent:LookupSequence(animation), frame, rate) + SetHoloAnim(Holo, animation, frame, rate) end e2function void holoAnim(index, animation) diff --git a/lua/wire/client/e2descriptions.lua b/lua/wire/client/e2descriptions.lua index ac1fc0f7de..a883598aec 100644 --- a/lua/wire/client/e2descriptions.lua +++ b/lua/wire/client/e2descriptions.lua @@ -1302,6 +1302,23 @@ E2Helper.Descriptions["holoClipsAvailable()"] = "Returns the maximum number of c E2Helper.Descriptions["holoInvertModel(nn)"] = "If not 0, inverts the model of the hologram" E2Helper.Descriptions["holoRenderFX(nn)"] = "Changes the RenderFX for a hologram" E2Helper.Descriptions["holoSkin(nn)"] = "Changes the skin of a hologram" +E2Helper.Descriptions["holoAnim(nsnn)"] = "Plays animation on the hologram specified by the index, the speed and starting point of which is determined by frame (ranging from 0 to 1) and rate (ranging from -12 to 12) values respectively" +E2Helper.Descriptions["holoAnim(nnnn)"] = "Plays animation on the hologram specified by the index, the speed and starting point of which is determined by frame (ranging from 0 to 1) and rate (ranging from -12 to 12) values respectively" +E2Helper.Descriptions["holoAnim(ns)"] = "Plays animation on the hologram specified by the index from frame 0 at the speed of 1" +E2Helper.Descriptions["holoAnim(nn)"] = "Plays animation on the hologram specified by the index from frame 0 at the speed of 1" +E2Helper.Descriptions["holoAnim(nnn"] = "Plays animation on the hologram specified by the index from the desired frame (ranging from 0 to 1) at the speed of 1" +E2Helper.Descriptions["holoAnim(nsn"] = "Plays animation on the hologram specified by the index from the desired frame (ranging from 0 to 1) at the speed of 1" +E2Helper.Descriptions["holoAnimLength(n)"] = "Returns the duration of the currently playing animation index hologram" +E2Helper.Descriptions["holoAnimNum(ns)"] = "Returns the number value of the animation string on the index hologram" +E2Helper.Descriptions["holoGetAnimFrame(n)"] = "Returns the current frame of the playing animation (ranging from 0 to 1) on the index hologram" +E2Helper.Descriptions["holoGetAnimGroundSpeed(ns)"] = "Returns the ground speed of the string animation on the index hologram" +E2Helper.Descriptions["holoGetAnimGroundSpeed(nn)"] = "Returns the ground speed of the number animation on the index hologram" +E2Helper.Descriptions["holoGetAnims(n)"] = "Returns the number value of the animation string" +E2Helper.Descriptions["holoClearPoses(n)"] = "Sets all pose parameters of the hologram specified by the index to 0" +E2Helper.Descriptions["holoGetPose(ns)"] = "Returns the pose parameter specified by the string on the hologram specified by the index" +E2Helper.Descriptions["holoGetPoseRange(ns)"] = "Returns the range of the pose parameter specified by the string on the hologram specified by the index" +E2Helper.Descriptions["holoGetPoses(n)"] = "Returns all existing pose parameters on the hologram specified by the index" +E2Helper.Descriptions["holoSetPose(nsn)"] = "Sets the string pose parameter on the index hologram by the number value, the range of which can be found with holoGetPoseRange()" -- File E2Helper.Descriptions["fileLoaded()"] = "DEPRECATED. Use 'event fileLoaded(FilePath:string, Data:string)' instead! Returns whether or not the file has been loaded onto the server" From b749cae08295b1d6de5dee67a18b0bc977ac3e3b Mon Sep 17 00:00:00 2001 From: unknao Date: Tue, 6 Aug 2024 16:58:12 +0300 Subject: [PATCH 3/4] Moved Think logic to the hologram entity & added more animation functions --- .../gmod_wire_expression2/core/hologram.lua | 21 ++++++++++++------- lua/entities/gmod_wire_hologram.lua | 6 ++++++ lua/wire/client/e2descriptions.lua | 2 ++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/hologram.lua b/lua/entities/gmod_wire_expression2/core/hologram.lua index 4b9244f534..d855e6fc29 100644 --- a/lua/entities/gmod_wire_expression2/core/hologram.lua +++ b/lua/entities/gmod_wire_expression2/core/hologram.lua @@ -1284,13 +1284,6 @@ local function SetHoloAnim(Holo, Animation, Frame, Rate) -- This must be run once on entities that will be animated Holo.ent.Animated = true Holo.ent.AutomaticFrameAdvance = true - - local OldThink = Holo.ent.Think - function Holo.ent:Think() - OldThink(self) - self:NextThink(CurTime()) - return true - end end Holo.ent:ResetSequence(Animation) Holo.ent:SetCycle(math.Clamp(Frame, 0, 1)) @@ -1383,6 +1376,20 @@ e2function number holoGetAnimGroundSpeed(index, string animation) return Holo.ent:GetSequenceGroundSpeed(anim) end +e2function void holoSetAnimFrame(index, frame) + local Holo = CheckIndex(self, index) + if not Holo then return end + + Holo.ent:SetCycle(math.Clamp(frame, 0, 1)) +end + +e2function void holoSetAnimSpeed(index, rate) + local Holo = CheckIndex(self, index) + if not Holo then return end + + Holo.ent:SetPlaybackRate(math.Clamp(rate, -12, 12)) +end + e2function number holoGetAnimGroundSpeed(index, animation) local Holo = CheckIndex(self, index) if not Holo then return end diff --git a/lua/entities/gmod_wire_hologram.lua b/lua/entities/gmod_wire_hologram.lua index 91881e0252..3f2be085af 100644 --- a/lua/entities/gmod_wire_hologram.lua +++ b/lua/entities/gmod_wire_hologram.lua @@ -65,6 +65,12 @@ if CLIENT then self:DoPlayerColor() end + function ENT:Think() + if self.Animated then + self:NextThink(CurTime()) + return true + end + end hook.Add("PlayerBindPress", "wire_hologram_scale_setup", function() -- For initial spawn for _, ent in ipairs(ents.FindByClass("gmod_wire_hologram")) do if ent:IsValid() and ent.DoScale then diff --git a/lua/wire/client/e2descriptions.lua b/lua/wire/client/e2descriptions.lua index a883598aec..39b6a0e5db 100644 --- a/lua/wire/client/e2descriptions.lua +++ b/lua/wire/client/e2descriptions.lua @@ -1314,6 +1314,8 @@ E2Helper.Descriptions["holoGetAnimFrame(n)"] = "Returns the current frame of the E2Helper.Descriptions["holoGetAnimGroundSpeed(ns)"] = "Returns the ground speed of the string animation on the index hologram" E2Helper.Descriptions["holoGetAnimGroundSpeed(nn)"] = "Returns the ground speed of the number animation on the index hologram" E2Helper.Descriptions["holoGetAnims(n)"] = "Returns the number value of the animation string" +E2Helper.Descriptions["holoSetAnimFrame(nn)"] = "Sets the frame of the active animation of the index hologram (ranging from 0 to 1)" +E2Helper.Descriptions["holoSetAnimSpeed(nn)"] = "Sets the active animation speed of the index hologram (ranging from -12 and 12)" E2Helper.Descriptions["holoClearPoses(n)"] = "Sets all pose parameters of the hologram specified by the index to 0" E2Helper.Descriptions["holoGetPose(ns)"] = "Returns the pose parameter specified by the string on the hologram specified by the index" E2Helper.Descriptions["holoGetPoseRange(ns)"] = "Returns the range of the pose parameter specified by the string on the hologram specified by the index" From f57876425ffc96d664f8603d34391bc6e5b25ea2 Mon Sep 17 00:00:00 2001 From: unknao Date: Tue, 6 Aug 2024 17:12:43 +0300 Subject: [PATCH 4/4] moved the think to the serverside --- lua/entities/gmod_wire_hologram.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lua/entities/gmod_wire_hologram.lua b/lua/entities/gmod_wire_hologram.lua index 3f2be085af..c789e4ce31 100644 --- a/lua/entities/gmod_wire_hologram.lua +++ b/lua/entities/gmod_wire_hologram.lua @@ -65,12 +65,6 @@ if CLIENT then self:DoPlayerColor() end - function ENT:Think() - if self.Animated then - self:NextThink(CurTime()) - return true - end - end hook.Add("PlayerBindPress", "wire_hologram_scale_setup", function() -- For initial spawn for _, ent in ipairs(ents.FindByClass("gmod_wire_hologram")) do if ent:IsValid() and ent.DoScale then @@ -432,6 +426,13 @@ function ENT:OnRemove() net.Broadcast() end +function ENT:Think() + if self.Animated then + self:NextThink(CurTime()) + return true + end +end + function ENT:Initialize() self.steamid = "" self:SetSolid(SOLID_NONE)