From 5f660bcfacace4648b722404229c1c7a77c74243 Mon Sep 17 00:00:00 2001 From: JustGod <85418813+JustGodWork@users.noreply.github.com> Date: Fri, 25 Oct 2024 23:35:54 +0200 Subject: [PATCH] Fix progressbar always return false|nil --- [core]/esx_progressbar/Progress.lua | 48 ++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/[core]/esx_progressbar/Progress.lua b/[core]/esx_progressbar/Progress.lua index 0f018f5f..fcb81898 100644 --- a/[core]/esx_progressbar/Progress.lua +++ b/[core]/esx_progressbar/Progress.lua @@ -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()