mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-28 17:01:14 +00:00
Merge pull request #1842 from seltonmt012/fix/progressbar-timing
fix(esx_progressbar): honour the requested duration and ignore cancelled runs
This commit is contained in:
@@ -9,11 +9,12 @@
|
|||||||
---@field public onFinish? function
|
---@field public onFinish? function
|
||||||
|
|
||||||
local CurrentProgress = nil
|
local CurrentProgress = nil
|
||||||
|
local progressCount = 0
|
||||||
|
|
||||||
local function startProcessing()
|
local function startProcessing(id)
|
||||||
while (CurrentProgress ~= nil) do
|
while CurrentProgress ~= nil and CurrentProgress.id == id do
|
||||||
if CurrentProgress.length > 0 then
|
if GetGameTimer() < CurrentProgress.finishAt then
|
||||||
CurrentProgress.length = CurrentProgress.length - 1000
|
Wait(50)
|
||||||
else
|
else
|
||||||
ClearPedTasks(ESX.PlayerData.ped)
|
ClearPedTasks(ESX.PlayerData.ped)
|
||||||
if CurrentProgress.FreezePlayer then
|
if CurrentProgress.FreezePlayer then
|
||||||
@@ -24,7 +25,6 @@ local function startProcessing()
|
|||||||
end
|
end
|
||||||
CurrentProgress = nil
|
CurrentProgress = nil
|
||||||
end
|
end
|
||||||
Wait(1000)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -55,8 +55,15 @@ local function Progressbar(message, length, Options)
|
|||||||
length = length or 3000,
|
length = length or 3000,
|
||||||
message = message or "ESX-Framework",
|
message = message or "ESX-Framework",
|
||||||
})
|
})
|
||||||
|
progressCount = progressCount + 1
|
||||||
|
CurrentProgress.id = progressCount
|
||||||
CurrentProgress.length = length or 3000
|
CurrentProgress.length = length or 3000
|
||||||
CreateThread(startProcessing);
|
CurrentProgress.finishAt = GetGameTimer() + CurrentProgress.length
|
||||||
|
|
||||||
|
local id = progressCount
|
||||||
|
CreateThread(function()
|
||||||
|
startProcessing(id)
|
||||||
|
end)
|
||||||
return true;
|
return true;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user