Skip to content

Commit

Permalink
Changed E2 spawn behavior to try to run only once
Browse files Browse the repository at this point in the history
  • Loading branch information
Denneisk committed Dec 11, 2024
1 parent fbe1bed commit 9df9ba1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions lua/entities/gmod_wire_expression2/core/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ local function dupefinished( TimedPasteData, TimedPasteDataCurrent )
v.dupefinished = true
v:Execute()
v.dupefinished = nil
v.duped = nil
end
end
end
Expand Down
29 changes: 23 additions & 6 deletions lua/entities/gmod_wire_expression2/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down

0 comments on commit 9df9ba1

Please sign in to comment.