diff --git a/[core]/es_extended/server/functions.lua b/[core]/es_extended/server/functions.lua index 5ba47867..9b20c92f 100644 --- a/[core]/es_extended/server/functions.lua +++ b/[core]/es_extended/server/functions.lua @@ -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