Merge pull request #1428 from JustGodWork/main

Fix progress bar return behavior in esx_progressbar
This commit is contained in:
Kasey Fitton
2024-10-25 22:54:29 +01:00
committed by GitHub
2 changed files with 44 additions and 17 deletions
+10 -2
View File
@@ -107,8 +107,16 @@ function ESX.SpawnPlayer(skin, coords, cb)
cb()
end
function ESX.Progressbar(...)
return IsResourceFound('esx_progressbar') and exports['esx_progressbar']:Progressbar(...)
---@param message string
---@param length? number Timeout in milliseconds
---@param options? ProgressBarOptions
---@return boolean Success Whether the progress bar was successfully created or not
function ESX.Progressbar(message, length, options)
return IsResourceFound('esx_progressbar') and exports['esx_progressbar']:Progressbar(message, length, options)
end
function ESX.CancelProgressbar()
return IsResourceFound('esx_progressbar') and exports['esx_progressbar']:CancelProgressbar()
end
---@param message string The message to show
+34 -15
View File
@@ -1,5 +1,37 @@
---@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
---@return boolean Success
local function Progressbar(message, length, Options)
if CurrentProgress then
return false
@@ -24,21 +56,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()