diff --git a/[esx]/esx_progressbar/Progress.lua b/[esx]/esx_progressbar/Progress.lua index 797d357d..b89e56fa 100644 --- a/[esx]/esx_progressbar/Progress.lua +++ b/[esx]/esx_progressbar/Progress.lua @@ -1,7 +1,8 @@ -local InProgress = false +local CurrentProgress = nil local function Progressbar(message,length,Options) local Canceled = false - if not InProgress then + if not CurrentProgress then + CurrentProgress = Options if Options.animation then if Options.animation.type == "anim" then ESX.Streaming.RequestAnimDict(Options.animation.dict, function() @@ -18,30 +19,32 @@ local function Progressbar(message,length,Options) length = length or 3000, message = message or "ESX-Framework" })) - local le = length or 3000 - while le > 0 do - Wait(0) - le -= 1 - if IsControlJustPressed(0, 194) and Options.onCancel then - SendNuiMessage(json.encode({ - type = "Close" - })) - Canceled = true - ClearPedTasksImmediately(ESX.PlayerData.ped) + CurrentProgress.length = length or 3000 + while CurrentProgress ~= nil do + if CurrentProgress.length > 0 then + CurrentProgress.length -= 1000 + else + ClearPedTasks(ESX.PlayerData.ped) if Options.FreezePlayer then FreezeEntityPosition(PlayerPedId(), false) end - InProgress = false - le = 0 - Options.onCancel() + if Options.onFinish then Options.onFinish() end + CurrentProgress = nil end - end - if not Canceled then - ClearPedTasks(ESX.PlayerData.ped) - if Options.FreezePlayer then FreezeEntityPosition(PlayerPedId(), false) end - if Options.onFinish then Options.onFinish() end - InProgress = false + Wait(1000) end end end -exports('Progressbar', Progressbar) - +ESX.RegisterInput("cancelprog", "[ProgressBar] Cancel Progressbar", "keyboard", "BACK", function() + if not CurrentProgress then return end + if not CurrentProgress.onCancel then return end + SendNuiMessage(json.encode({ + type = "Close" + })) + ClearPedTasks(ESX.PlayerData.ped) + if CurrentProgress.FreezePlayer then FreezeEntityPosition(PlayerPedId(), false) end + CurrentProgress.canceled = true + CurrentProgress.length = 0 + CurrentProgress.onCancel() + CurrentProgress = nil +end) +exports('Progressbar', Progressbar) \ No newline at end of file diff --git a/[esx]/esx_progressbar/nui/js/script.js b/[esx]/esx_progressbar/nui/js/script.js index de331b93..b362b306 100644 --- a/[esx]/esx_progressbar/nui/js/script.js +++ b/[esx]/esx_progressbar/nui/js/script.js @@ -40,7 +40,7 @@ $(function () { $(".text").text(message) doc.getElementById("notifyInfo").style.display = "block"; const start = new Date(); - const maxTime = e.data.length + const maxTime = e.data.length; const timeoutValue = Math.floor(maxTime/100); animUpdate(); @@ -54,13 +54,16 @@ $(function () { const prc = Math.round((timeoutDiff/maxTime)*100); if (prc <= 100) { updateProg(prc); - setTimeout(animUpdate, timeoutValue); + this.timeoutID = setTimeout(animUpdate, timeoutValue); } else { doc.getElementById('notifyInfo').style.display = "none"; } } } else { doc.getElementById("notifyInfo").style.display = "none" + clearTimeout(this.timeoutID); + timeoutValue = 0; + } }) })