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