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:
_Not_
2026-08-14 19:39:45 -05:00
committed by GitHub
+13 -6
View File
@@ -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