mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-16 22:46:03 +01:00
@@ -31,7 +31,6 @@ function timer:constructor(time, onEnd, async)
|
||||
self.private.startTime = 0
|
||||
self.private.paused = false
|
||||
self.private.onEnd = onEnd
|
||||
self.private.triggerOnEnd = true
|
||||
|
||||
self:start(async)
|
||||
end
|
||||
@@ -42,22 +41,22 @@ function timer:start(async)
|
||||
self.private.startTime = GetGameTimer()
|
||||
|
||||
local function tick()
|
||||
while self:getTimeLeft('ms') > 0 do
|
||||
while self:isPaused() do
|
||||
Wait(0)
|
||||
end
|
||||
while self:isPaused() or self:getTimeLeft('ms') > 0 do
|
||||
Wait(0)
|
||||
end
|
||||
self:onEnd()
|
||||
|
||||
if self.private.triggerOnEnd then
|
||||
self:onEnd()
|
||||
end
|
||||
|
||||
self.private.triggerOnEnd = true
|
||||
end
|
||||
|
||||
if async then
|
||||
Citizen.CreateThreadNow(function()
|
||||
tick()
|
||||
end)
|
||||
else
|
||||
if not async then return tick() end
|
||||
|
||||
Citizen.CreateThreadNow(function()
|
||||
tick()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function timer:onEnd()
|
||||
@@ -70,14 +69,17 @@ end
|
||||
|
||||
function timer:forceEnd(triggerOnEnd)
|
||||
if self:getTimeLeft('ms') <= 0 then return end
|
||||
self.private.triggerOnEnd = triggerOnEnd
|
||||
|
||||
self.private.paused = false
|
||||
self.private.currentTimeLeft = 0
|
||||
self.private.triggerOnEnd = triggerOnEnd
|
||||
|
||||
Wait(0)
|
||||
end
|
||||
|
||||
function timer:pause()
|
||||
if self.private.paused then return end
|
||||
|
||||
self.private.currentTimeLeft = self:getTimeLeft('ms') --[[@as number]]
|
||||
self.private.paused = true
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user