From 520c9b76c4397d3ea344b047141d749c0c46e053 Mon Sep 17 00:00:00 2001 From: tehzarathustra Date: Tue, 15 Oct 2024 23:27:42 +0200 Subject: [PATCH] timers.lua: fix arg1 as string --- src/vscripts/lib/timers.lua | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/vscripts/lib/timers.lua b/src/vscripts/lib/timers.lua index 2da9b36..dc8c0f0 100644 --- a/src/vscripts/lib/timers.lua +++ b/src/vscripts/lib/timers.lua @@ -234,6 +234,9 @@ function Timers:CreateTimer(arg1, arg2, context) timer = {callback = arg1} elseif type(arg1) == "table" then timer = arg1 + elseif type(arg1) == "string" then + timer = arg2 + timer.name = arg1 elseif type(arg1) == "number" then timer = {endTime = arg1, callback = arg2} end @@ -268,14 +271,17 @@ end function Timers:RemoveTimer(name) local timerHeap = self.gameTimeHeap - if name.useGameTime ~= nil and name.useGameTime == false then + local runningTimer = Timers.runningTimer + local hasMatch = runningTimer == name or runningTimer.name == name + + if not hasMatch then return end + + if runningTimer.useGameTime ~= nil and runningTimer.useGameTime == false then timerHeap = self.realTimeHeap end - timerHeap:Remove(name) - if Timers.runningTimer == name then - Timers.removeSelf = true - end + timerHeap:Remove(runningTimer) + Timers.removeSelf = true end function Timers:InitializeTimers() @@ -285,4 +291,4 @@ end if not Timers.started then Timers:start() end -GameRules.Timers = Timers \ No newline at end of file +GameRules.Timers = Timers