Fix progressbar always return false|nil

This commit is contained in:
JustGod
2024-10-25 23:35:54 +02:00
parent 64e9a2cd83
commit 5f660bcfac
+33 -15
View File
@@ -1,5 +1,36 @@
---@class ProgressBarAnimation
---@field public type "anim" | "Scenario"
---@field public dict? string
---@field public lib? string
---@class ProgressBarOptions
---@field public animation ProgressBarAnimation
---@field public FreezePlayer? boolean
---@field public onFinish? function
local CurrentProgress = nil
local function startProcessing()
while (CurrentProgress ~= nil) do
if CurrentProgress.length > 0 then
CurrentProgress.length = CurrentProgress.length - 1000
else
ClearPedTasks(ESX.PlayerData.ped)
if CurrentProgress.FreezePlayer then
FreezeEntityPosition(ESX.PlayerData.ped, false)
end
if CurrentProgress.onFinish then
CurrentProgress.onFinish()
end
CurrentProgress = nil
end
Wait(1000)
end
end
---@param message string
---@param length? number Timeout in milliseconds
---@param Options? ProgressBarOptions
local function Progressbar(message, length, Options)
if CurrentProgress then
return false
@@ -24,21 +55,8 @@ local function Progressbar(message, length, Options)
message = message or "ESX-Framework",
})
CurrentProgress.length = length or 3000
while CurrentProgress ~= nil do
if CurrentProgress.length > 0 then
CurrentProgress.length = CurrentProgress.length - 1000
else
ClearPedTasks(ESX.PlayerData.ped)
if CurrentProgress.FreezePlayer then
FreezeEntityPosition(ESX.PlayerData.ped, false)
end
if CurrentProgress.onFinish then
CurrentProgress.onFinish()
end
CurrentProgress = nil
end
Wait(1000)
end
CreateThread(startProcessing);
return true;
end
local function CancelProgressbar()