Skip to content

Commit d8c9590

Browse files
authored
Merge pull request #14 from TehZarathustra/master
timers.lua: fix arg1 as string
2 parents 56dd106 + 520c9b7 commit d8c9590

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/vscripts/lib/timers.lua

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ function Timers:CreateTimer(arg1, arg2, context)
234234
timer = {callback = arg1}
235235
elseif type(arg1) == "table" then
236236
timer = arg1
237+
elseif type(arg1) == "string" then
238+
timer = arg2
239+
timer.name = arg1
237240
elseif type(arg1) == "number" then
238241
timer = {endTime = arg1, callback = arg2}
239242
end
@@ -268,14 +271,17 @@ end
268271

269272
function Timers:RemoveTimer(name)
270273
local timerHeap = self.gameTimeHeap
271-
if name.useGameTime ~= nil and name.useGameTime == false then
274+
local runningTimer = Timers.runningTimer
275+
local hasMatch = runningTimer == name or runningTimer.name == name
276+
277+
if not hasMatch then return end
278+
279+
if runningTimer.useGameTime ~= nil and runningTimer.useGameTime == false then
272280
timerHeap = self.realTimeHeap
273281
end
274282

275-
timerHeap:Remove(name)
276-
if Timers.runningTimer == name then
277-
Timers.removeSelf = true
278-
end
283+
timerHeap:Remove(runningTimer)
284+
Timers.removeSelf = true
279285
end
280286

281287
function Timers:InitializeTimers()
@@ -285,4 +291,4 @@ end
285291

286292
if not Timers.started then Timers:start() end
287293

288-
GameRules.Timers = Timers
294+
GameRules.Timers = Timers

0 commit comments

Comments
 (0)