mirror of
https://github.com/sky-systems/sky_phone.git
synced 2026-09-04 09:13:24 +00:00
ADD - expose garage vehicles to NUI
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user