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