Phone Integration for Developers
This page explains how phone developers can make their phone garage apps work with cd_garage.
If your phone script has a garage app, it should read vehicle status and garage data from the vehicle database table.
- ESX usually uses
owned_vehicles - QBCore/Qbox usually uses
player_vehicles
Vehicle Status
Use the in_garage column to check where the vehicle is.
in_garage = 0 -- Vehicle is on the streets
in_garage = 1 -- Vehicle is in a garage
in_garage = 2 -- Vehicle is in impoundYour phone script should use this value to show the correct vehicle status in the phone garage app.
Garage ID and Garage Label
The garage_id column is the garage’s unique ID.
Do not show garage_id directly to players.
Use this export to get the garage label from the garage ID:
local garageId = '0ZDV-42KH-8OSX'
local garageLabel = exports.cd_garage:GetGarageLabelFromGarageId(garageId)
print(garageLabel)
-- Example output:
-- Legion GarageThis makes sure the phone app shows a clean garage name, such as Legion Garage, instead of a raw garage ID.
What Phone Scripts Should Do
- Read vehicle data from
owned_vehicles/player_vehicles. - Use
in_garagefor the vehicle status. - Use
in_garage = 2for impounded vehicles. - Do not show
garage_iddirectly to players. - Use
GetGarageLabelFromGarageIdto show the garage name.
Example: Get Vehicles From Database
This example gets the player’s vehicles from the database, converts the garage ID into a garage label, and formats the data for a phone garage app.
Example Function
function GetVehicles(source)
local Player = QBCore.Functions.GetPlayer(source)
if not Player then return end
local vehicles = {}
local result = MySQL.query.await('SELECT * FROM player_vehicles WHERE citizenid = ?', {
Player.PlayerData.citizenid
})
if not result or not result[1] then
return
end
for i = 1, #result do
local v = result[i]
local vehicleData = QBCore.Shared.Vehicles[v.vehicle]
if vehicleData then
local props = json.decode(v.mods or '{}')
local state = 'Out On Streets'
if v.in_garage == 1 then
state = 'In Garage'
elseif v.in_garage == 2 then
state = 'In Impound'
end
local fullname = vehicleData.name
if vehicleData.brand then
fullname = vehicleData.brand .. ' ' .. vehicleData.name
end
vehicles[#vehicles + 1] = {
fullname = fullname,
brand = vehicleData.brand,
model = vehicleData.name,
plate = v.plate,
garage = exports.cd_garage:GetGarageLabelFromGarageId(v.garage_id),
state = state,
fuel = props.fuelLevel,
engine = props.engineHealth,
body = props.bodyHealth
}
end
end
return vehicles
endin_garageis used to show if the vehicle is out, garaged, or impounded.GetGarageLabelFromGarageIdis used so the phone app shows the garage name instead of the raw garage ID.- This example uses QBCore and
player_vehicles, but the same idea can be used with ESX andowned_vehicles.