mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 01:08:54 +00:00
feat(es_extended/server/functions): add promise support for ESX.GetVehicleType
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user