feat(es_extended/server/functions): add promise support for ESX.GetVehicleType

This commit is contained in:
Kenshin13
2025-04-28 18:01:28 +02:00
parent 60deeda635
commit 5722873472
+22 -3
View File
@@ -386,19 +386,38 @@ end
---@param model string|number
---@param player number
---@param cb function
---@param cb function?
---@diagnostic disable-next-line: duplicate-set-field
---@return string?
function ESX.GetVehicleType(model, player, cb)
if cb and not ESX.IsFunctionReference(cb) then
error("Invalid callback function")
end
local promise = not cb and promise.new()
local function resolve(result)
if promise then
promise:resolve(result)
elseif cb then
cb(result)
end
end
model = type(model) == "string" and joaat(model) or model
if Core.vehicleTypesByModel[model] then
return cb(Core.vehicleTypesByModel[model])
return resolve(Core.vehicleTypesByModel[model])
end
ESX.TriggerClientCallback(player, "esx:GetVehicleType", function(vehicleType)
Core.vehicleTypesByModel[model] = vehicleType
cb(vehicleType)
resolve(vehicleType)
end, model)
if promise then
return Citizen.Await(promise)
end
end
---@param name string