From 9df9ba19eddc60a97fda813b5bf9b0732c3b6f1e Mon Sep 17 00:00:00 2001 From: Denneisk <20892685+Denneisk@users.noreply.github.com> Date: Wed, 11 Dec 2024 14:19:49 -0500 Subject: [PATCH] Changed E2 spawn behavior to try to run only once --- .../gmod_wire_expression2/core/core.lua | 1 + lua/entities/gmod_wire_expression2/init.lua | 29 +++++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/core.lua b/lua/entities/gmod_wire_expression2/core/core.lua index e4f33b96f4..a5eb106d82 100644 --- a/lua/entities/gmod_wire_expression2/core/core.lua +++ b/lua/entities/gmod_wire_expression2/core/core.lua @@ -73,6 +73,7 @@ local function dupefinished( TimedPasteData, TimedPasteDataCurrent ) v.dupefinished = true v:Execute() v.dupefinished = nil + v.duped = nil end end end diff --git a/lua/entities/gmod_wire_expression2/init.lua b/lua/entities/gmod_wire_expression2/init.lua index b21b3db219..64fd31dbba 100644 --- a/lua/entities/gmod_wire_expression2/init.lua +++ b/lua/entities/gmod_wire_expression2/init.lua @@ -552,8 +552,6 @@ function ENT:Setup(buffer, includes, restore, forcecompile, filepath) return end - self.duped = false - if not restore then self.first = true self:Execute() @@ -646,6 +644,28 @@ function ENT:TriggerOutputs(force) end end +--- Helper function that operates slightly differently if AdvDupe2 exists or not +local apply_duped +do + local function runDuped(e2) + e2.duped = true + e2:Execute() + e2:Think() + e2.duped = nil + end + + ---@diagnostic disable-next-line:undefined-global + if AdvDupe2 then -- Prevent duped() if dupeFinished() can be called instead + apply_duped = function(e2) + if not e2.directives.strict then + runDuped(e2) + end + end + else -- Always run duped() without AdvDupe(2) + apply_duped = runDuped + end +end + function ENT:ApplyDupeInfo(ply, ent, info, GetEntByID, GetConstByID) self:Setup(self.buffer, self.inc_files, true) @@ -664,10 +684,7 @@ function ENT:ApplyDupeInfo(ply, ent, info, GetEntByID, GetConstByID) end self.dupevars = nil - self.duped = true - self:Execute() - self:Think() - self.duped = false + apply_duped(self) end BaseClass.ApplyDupeInfo(self, ply, ent, info, GetEntByID, GetConstByID)