From e935a9a6b6506cf6d474bc18f44670542e5ba190 Mon Sep 17 00:00:00 2001 From: Mycroft Date: Sun, 7 Aug 2022 00:06:47 +0100 Subject: [PATCH] readme didnt update for some reason :( --- [esx]/esx_progressbar/Progress.lua | 70 +++++++++++++++--------------- [esx]/esx_progressbar/readme.md | 39 ++++++++++++++++- 2 files changed, 73 insertions(+), 36 deletions(-) diff --git a/[esx]/esx_progressbar/Progress.lua b/[esx]/esx_progressbar/Progress.lua index 1fdd42f0..b0217415 100644 --- a/[esx]/esx_progressbar/Progress.lua +++ b/[esx]/esx_progressbar/Progress.lua @@ -1,46 +1,48 @@ +local InProgress = false local function Progressbar(message,length,Options) - if Options.animation then - if Options.animation.type == "anim" then - ESX.Streaming.RequestAnimDict(Options.animation.dict, function() - TaskPlayAnim(ESX.PlayerData.ped, Options.animation.dict, Options.animation.lib, 1.0, 1.0, length, 1, 1.0, false,false,false) - RemoveAnimDict(Options.animation.dict) - end) - elseif Options.animation.type == "Scenario" then - TaskStartScenarioInPlace(ESX.PlayerData.ped, Options.animation.Scenario, 0, true) - end - end - if Options.FreezePlayer then FreezeEntityPosition(PlayerPedId(),Options.FreezePlayer) end - SendNuiMessage(json.encode({ - type = "Progressbar", - length = length or 3000, - message = message or "ESX-Framework" - })) - if Options.onCancel then - local le = length or 3000 - while le > 0 do - Wait(0) - le -= 1 - if IsControlJustPressed(0, 178) then - Options.onCancel() - break + if not InProgress then + if Options.animation then + if Options.animation.type == "anim" then + ESX.Streaming.RequestAnimDict(Options.animation.dict, function() + TaskPlayAnim(ESX.PlayerData.ped, Options.animation.dict, Options.animation.lib, 1.0, 1.0, length, 1, 1.0, false,false,false) + RemoveAnimDict(Options.animation.dict) + end) + elseif Options.animation.type == "Scenario" then + TaskStartScenarioInPlace(ESX.PlayerData.ped, Options.animation.Scenario, 0, true) end end + if Options.FreezePlayer then FreezeEntityPosition(PlayerPedId(),Options.FreezePlayer) end SendNuiMessage(json.encode({ - type = "Close" + type = "Progressbar", + length = length or 3000, + message = message or "ESX-Framework" })) - ClearPedTasks(ESX.PlayerData.ped) - if Options.FreezePlayer then FreezeEntityPosition(PlayerPedId(), false) end - if Options.onFinish then Options.onFinish() end - else - SetTimeout(length, function() + if Options.onCancel then + local le = length or 3000 + while le > 0 do + Wait(0) + le -= 1 + if IsControlJustPressed(0, 178) then + SendNuiMessage(json.encode({ + type = "Close" + })) + Options.onCancel() + break + end + end ClearPedTasks(ESX.PlayerData.ped) if Options.FreezePlayer then FreezeEntityPosition(PlayerPedId(), false) end if Options.onFinish then Options.onFinish() end - end) + InProgress = false + else + SetTimeout(length, function() + ClearPedTasks(ESX.PlayerData.ped) + if Options.FreezePlayer then FreezeEntityPosition(PlayerPedId(), false) end + if Options.onFinish then Options.onFinish() end + InProgress = false + end) + end end - - - end exports('Progressbar', Progressbar) diff --git a/[esx]/esx_progressbar/readme.md b/[esx]/esx_progressbar/readme.md index e01762be..c99b59f6 100644 --- a/[esx]/esx_progressbar/readme.md +++ b/[esx]/esx_progressbar/readme.md @@ -16,6 +16,7 @@ ``` * Export + ```lua exports["esx_progressbar"]:Progressbar("Unlocking Storage", 3000,{ FreezePlayer = true, @@ -27,5 +28,39 @@ onFinish = function() --Code here end}) - - ``` +``` + +* Cancel + +```lua + ESX.Progressbar("Unlocking Storage", 3000,{ + FreezePlayer = true, + animation ={ + type = "anim", + dict = "anim@mp_player_intmenu@key_fob@", + lib ="fob_click" + }, + onFinish = function() + --Code here + end, OnCancel = function() + --Code here + end + }) +``` + +* Scenario + +```lua + ESX.Progressbar("Unlocking Storage", 3000,{ + FreezePlayer = true, + animation ={ + type = "Scenario", + Scenario = "PROP_HUMAN_BUM_BIN", + }, + onFinish = function() + --Code here + end, OnCancel = function() + --Code here + end + }) +``` \ No newline at end of file