From 8bc723236a762fc4c57f477a591b72745224c362 Mon Sep 17 00:00:00 2001 From: Garrett Brown Date: Mon, 28 Aug 2023 20:47:50 -0400 Subject: [PATCH] Fix some lua errors --- lua/starfall/libs_sv/nextbot.lua | 1 - lua/starfall/sflib.lua | 20 +++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lua/starfall/libs_sv/nextbot.lua b/lua/starfall/libs_sv/nextbot.lua index 0877b885e..7569b68e3 100644 --- a/lua/starfall/libs_sv/nextbot.lua +++ b/lua/starfall/libs_sv/nextbot.lua @@ -92,7 +92,6 @@ function nextbot_library.create(pos, mdl) entList:checkuse(ply, 1) local nb = ents.Create("starfall_cnextbot") - register(nb, instance) nb:SetPos(upos) nb:SetModel(mdl) nb.chip = instance.entity diff --git a/lua/starfall/sflib.lua b/lua/starfall/sflib.lua index 659f88a80..f0ddd48bf 100644 --- a/lua/starfall/sflib.lua +++ b/lua/starfall/sflib.lua @@ -290,20 +290,30 @@ setmetatable(SF.LimitObject, SF.LimitObject) SF.EntManager = { __index = { register = function(self, instance, ent) - ent:CallOnRemove("starfall_entity_onremove", self.onremove, self, instance) + local function sf_on_remove() self:onremove(instance, ent) end + ent.sf_on_remove = sf_on_remove + + local callOnRemove = ent.CallOnRemove + if callOnRemove then + callOnRemove(ent, "starfall_entity_onremove", sf_on_remove) + end + self.entsByInstance[instance][ent] = true self:free(instance.player, -1) end, remove = function(self, instance, ent) if ent:IsValid() then -- The die function is called the next frame after 'Remove' which is too slow so call it ourself - local diefunc = ent.OnDieFunctions.starfall_entity_onremove - diefunc.Function(ent, unpack(diefunc.Args)) - ent:RemoveCallOnRemove("starfall_entity_onremove") + local removeCallOnRemove = ent.RemoveCallOnRemove + if removeCallOnRemove then + removeCallOnRemove(ent, "starfall_entity_onremove") + end + ent.sf_on_remove() + ent:Remove() end end, - onremove = function(ent, self, instance) + onremove = function(self, instance, ent) self.entsByInstance[instance][ent] = nil self:free(instance.player, 1) end,