Files
esx_core/[core]/esx_progressbar/Progress.lua
T
FekyDEV 349bb41e73 Added option to externally cancel progress bar
Personally, I think this feature should have been here a long time ago. I hope that adding this code will help players in the future and if anyone here has a suggestion for a code change feel free to comment.
2023-05-12 22:55:40 +02:00

56 lines
2.0 KiB
Lua

local CurrentProgress = nil
local function Progressbar(message,length,Options)
if CurrentProgress then
return false
end
CurrentProgress = Options or {}
if CurrentProgress.animation then
if CurrentProgress.animation.type == "anim" then
ESX.Streaming.RequestAnimDict(CurrentProgress.animation.dict, function()
TaskPlayAnim(ESX.PlayerData.ped, CurrentProgress.animation.dict, CurrentProgress.animation.lib, 1.0, 1.0, length, 1, 1.0, false,false,false)
RemoveAnimDict(CurrentProgress.animation.dict)
end)
elseif CurrentProgress.animation.type == "Scenario" then
TaskStartScenarioInPlace(ESX.PlayerData.ped, CurrentProgress.animation.Scenario, 0, true)
end
end
if CurrentProgress.FreezePlayer then FreezeEntityPosition(PlayerPedId(), CurrentProgress.FreezePlayer) end
SendNUIMessage({
type = "Progressbar",
length = length or 3000,
message = message or "ESX-Framework"
})
CurrentProgress.length = length or 3000
while CurrentProgress ~= nil do
if CurrentProgress.length > 0 then
CurrentProgress.length -= 1000
else
ClearPedTasks(ESX.PlayerData.ped)
if CurrentProgress.FreezePlayer then FreezeEntityPosition(PlayerPedId(), false) end
if CurrentProgress.onFinish then CurrentProgress.onFinish() end
CurrentProgress = nil
end
Wait(1000)
end
end
local function CancelProgressbar()
if not CurrentProgress then return end
SendNUIMessage({
type = "Close"
})
ClearPedTasks(ESX.PlayerData.ped)
if CurrentProgress.FreezePlayer then FreezeEntityPosition(PlayerPedId(), false) end
CurrentProgress.canceled = true
CurrentProgress.length = 0
CurrentProgress = nil
end
ESX.RegisterInput("cancelprog", "[ProgressBar] Cancel Progressbar", "keyboard", "BACK", function()
CancelProgressbar()
end)
exports('Progressbar', Progressbar)
exports('CancelProgressbar', CancelProgressbar)