Skip to content

Commit 017e692

Browse files
authored
Per-player quota fixes (#3562)
Fixes a bug where BaseClass.OnRemove wasn't called if the owner was invalid Don't reset E2Lib.PlayerChips on autorefresh
1 parent 98571dc commit 017e692

File tree

1 file changed

+8
-6
lines changed
  • lua/entities/gmod_wire_expression2

1 file changed

+8
-6
lines changed

lua/entities/gmod_wire_expression2/init.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ function PlayerChips:checkCpuTime()
343343

344344
while total_time > e2_timequota do
345345
local max_chip, max_time = self:findMaxTimeChip()
346+
346347
if max_chip then
347348
total_time = total_time - max_time
348349
max_chip:Error("Expression 2 (" .. max_chip.name .. "): Per-player time quota exceeded", "per-player time quota exceeded")
@@ -367,7 +368,7 @@ function PlayerChips:remove(remove_chip)
367368
end
368369
end
369370

370-
E2Lib.PlayerChips = setmetatable({}, {__index = function(self, ply) local chips = PlayerChips:new() self[ply] = chips return chips end})
371+
E2Lib.PlayerChips = E2Lib.PlayerChips or setmetatable({}, {__index = function(self, ply) local chips = PlayerChips:new() self[ply] = chips return chips end})
371372

372373
hook.Add("Think", "E2_Think", function()
373374
if e2_timequota > 0 then
@@ -391,13 +392,14 @@ function ENT:OnRemove()
391392
end
392393

393394
local owner = self.player
394-
if not IsValid(owner) then return end
395395

396-
local chips = E2Lib.PlayerChips[owner]
397-
chips:remove(self)
396+
if IsValid(owner) then
397+
local chips = E2Lib.PlayerChips[owner]
398+
chips:remove(self)
398399

399-
if #chips == 0 then
400-
E2Lib.PlayerChips[owner] = nil
400+
if #chips == 0 then
401+
E2Lib.PlayerChips[owner] = nil
402+
end
401403
end
402404

403405
BaseClass.OnRemove(self)

0 commit comments

Comments
 (0)