Skip to content

Commit

Permalink
Fix some lua errors
Browse files Browse the repository at this point in the history
  • Loading branch information
thegrb93 committed Aug 29, 2023
1 parent a0d377f commit 8bc7232
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
1 change: 0 additions & 1 deletion lua/starfall/libs_sv/nextbot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 15 additions & 5 deletions lua/starfall/sflib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 8bc7232

Please sign in to comment.