ADD - expose garage vehicles to NUI

This commit is contained in:
Leon.Schmidt
2026-08-08 18:53:37 +02:00
parent 4a6984ae81
commit 1cafdbdff4
+41
View File
@@ -275,6 +275,47 @@ RegisterNUICallback("weather:get", function(_, cb)
})
end)
local function garage_vehicle_kind(model_hash, fallback)
if IsThisModelABoat(model_hash) then
return "boat"
end
if IsThisModelAPlane(model_hash) then
return "plane"
end
if IsThisModelAHeli(model_hash) then
return "helicopter"
end
if IsThisModelABike(model_hash) or IsThisModelABicycle(model_hash) then
return "bike"
end
return fallback
end
RegisterNUICallback("garage:vehicles", function(data, cb)
local result = Bridge.Callbacks.Trigger("sky_phone:garage:vehicles", data)
if not result or not result.success or type(result.data) ~= "table" then
cb(result or { success = false, error = "request_failed" })
return
end
for _, vehicle in ipairs(result.data.vehicles or {}) do
local model_hash = tonumber(vehicle.model)
if not model_hash and type(vehicle.model) == "string" and vehicle.model ~= "" then
model_hash = joaat(vehicle.model)
end
if model_hash then
local display_name = GetDisplayNameFromVehicleModel(model_hash)
local label = display_name and GetLabelText(display_name) or nil
if label and label ~= "NULL" and label ~= "CARNOTFOUND" then
vehicle.name = label
elseif type(vehicle.model) == "string" and vehicle.model ~= "" then
vehicle.name = vehicle.model
end
vehicle.kind = garage_vehicle_kind(model_hash, vehicle.kind)
end
end
cb(result)
end)
for _, callback_name in ipairs(server_callbacks) do
RegisterNUICallback(callback_name, function(data, cb)
local result = Bridge.Callbacks.Trigger("sky_phone:" .. callback_name, data)