Add promise:new() for qb/esx progressbars

This stops them instantly returning `false` and actually waits for the results

This fixes issues with players being unable to complete tasks determined by progressbars eg. installing items on a vehicle and it fails instantly
This commit is contained in:
Jim Shield
2025-08-30 12:15:09 +01:00
parent 1e5d4800fc
commit be5449b100

View File

@@ -4,7 +4,8 @@ local storedPID = nil
local progressFunc = {
ox = {
start = function(data)
start =
function(data)
local options = {
duration = debugMode and 1000 or data.time,
label = data.label,
@@ -51,17 +52,20 @@ local progressFunc = {
if exports[OXLibExport]:progressBar(options) then
return true
else
return false
print("^1progressBar was not successful")
end
end
end,
stop = function()
stop =
function()
exports[OXLibExport]:cancelProgress()
end,
},
qb = {
start = function(data)
start =
function(data)
local p = promise.new()
Core.Functions.Progressbar("progbar",
data.label,
debugMode and 1000 or data.time,
@@ -80,19 +84,20 @@ local progressFunc = {
task = data.task
},
{}, {},
function()
return true
end, function()
return false
end, data.icon)
function() p:resolve(true) end,
function() p:resolve(false) end,
data.icon)
return Citizen.Await(p)
end,
stop = function()
stop =
function()
TriggerEvent("progressbar:client:cancel")
end,
},
qs = {
start = function(data)
start =
function(data)
if exports['qs-interface']:ProgressBar({
duration = debugMode and 1000 or data.time,
label = data.label,
@@ -112,14 +117,17 @@ local progressFunc = {
return false
end
end,
stop = function()
stop =
function()
--??
TriggerEvent("progressbar:client:cancel")
end,
},
esx = {
start = function(data)
start =
function(data)
local p = promise.new()
ESX.Progressbar(data.label, debugMode and 1000 or data.time, {
FreezePlayer = true,
animation = {
@@ -128,20 +136,24 @@ local progressFunc = {
scenario = data.task,
},
onFinish = function()
return true
p:resolve(true)
end,
onCancel = function()
p:resolve(false)
return false
end
})
return Citizen.Await(p)
end,
stop = function()
stop =
function()
ESX.CancelProgressbar()
end,
},
lation = {
start = function(data)
start =
function(data)
if exports.lation_ui:progressBar({
label = data.label,
description = nil,
@@ -170,13 +182,15 @@ local progressFunc = {
return false
end
end,
stop = function()
stop =
function()
exports.lation_ui:cancelProgress()
end,
},
red = {
start = function(data)
start =
function(data)
if exports.jim_bridge:redProgressBar({
label = data.label,
time = debugMode and 1000 or data.time,
@@ -192,14 +206,15 @@ local progressFunc = {
return false
end
end,
stop = function()
stop =
function()
exports.jim_bridge:stopProgressBar()
end,
},
gta = {
start = function(data)
start =
function(data)
if exports.jim_bridge:gtaProgressBar({
label = data.label,
time = debugMode and 1000 or data.time,
@@ -215,7 +230,8 @@ local progressFunc = {
return false
end
end,
stop = function()
stop =
function()
exports.jim_bridge:stopProgressBar()
end,
},
@@ -254,7 +270,11 @@ local progressFunc = {
--- cancel = true,
--- })
--- ```
local progresssBarActive = false
function progressBar(data)
if progresssBarActive then return else progresssBarActive = true end
local ped = PlayerPedId()
if data.shared then
debugPrint("^6Bridge^7: ^6Sharing progressBar to player^7: ^6"..data.shared.pid.."^7")
@@ -294,6 +314,7 @@ function progressBar(data)
TriggerServerEvent(getScript()..":clearAuthToken")
currentToken = triggerCallback(AuthEvent)
end
progresssBarActive = false
return result
end
@@ -302,6 +323,7 @@ end
--- This function cancels the progress bar based on the configured progress bar system, handling any necessary cleanup.
function stopProgressBar()
progressFunc[Config.System.ProgressBar].stop()
progresssBarActive = false
end
-- System to handle sending/sharing progress bars between players --