From d691e4162b9dd214eb678d5d5400c4d4b868cb64 Mon Sep 17 00:00:00 2001 From: Luna <24762027+SpaxscE@users.noreply.github.com> Date: Mon, 16 Sep 2024 00:52:59 +0200 Subject: [PATCH] bring back holoanim/setpose the way it was before 2019 incident reverts https://github.com/wiremod/wire-extras/pull/64 fixes https://github.com/wiremod/wire-extras/issues/110 --- .../core/custom/holoanim.lua | 99 +++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 lua/entities/gmod_wire_expression2/core/custom/holoanim.lua diff --git a/lua/entities/gmod_wire_expression2/core/custom/holoanim.lua b/lua/entities/gmod_wire_expression2/core/custom/holoanim.lua new file mode 100644 index 00000000..283fbab8 --- /dev/null +++ b/lua/entities/gmod_wire_expression2/core/custom/holoanim.lua @@ -0,0 +1,99 @@ +-- holoAnim E2 Extension +-- Originally by dlb (ben1066) + +-- To Enable, run 'wire_expression2_extension_enable holoanim' + +E2Lib.RegisterExtension("holoanim", false) + +local CheckIndex +registerCallback("postinit",function() + CheckIndex = wire_holograms.CheckIndex +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)) + -- over 12 is clamped by the engine, negative values break cycle value + Holo.ent:SetPlaybackRate(math.Clamp(Rate,0,12)) + end +end + +e2function void holoAnim(index, string animation) + local Holo = CheckIndex(self, index) + if not Holo then return end + + SetHoloAnim(Holo, Holo.ent:LookupSequence(animation), 0, 1) +end + +e2function void holoAnim(index, string animation, frame) + local Holo = CheckIndex(self, index) + if not Holo then return 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 + + SetHoloAnim(Holo, Holo.ent:LookupSequence(animation), frame, rate) +end + +e2function void holoAnim(index, animation) + local Holo = CheckIndex(self, index) + + SetHoloAnim(Holo, animation, 0, 1) +end + +e2function void holoAnim(index, animation, frame) + local Holo = CheckIndex(self, index) + + SetHoloAnim(Holo, animation, frame, 1) +end + +e2function void holoAnim(index, animation, frame, rate) + local Holo = CheckIndex(self, index) + + SetHoloAnim(Holo, animation, frame, rate) +end + +e2function number holoAnimLength(index) + local Holo = CheckIndex(self, index) + if not Holo then return 0 end + + return Holo.ent:SequenceDuration() +end + +e2function number holoAnimNum(index, string animation) + local Holo = CheckIndex(self, index) + if not Holo then return 0 end + + return Holo.ent:LookupSequence(animation) or 0 +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 + + return Holo.ent:GetPoseParameter( pose ) +end \ No newline at end of file