Skip to Content
Cobalt

Vehicles

cobalt_core exports: vehicles.

ExportSideWhat it does
SpawnVehicleServerSpawns a vehicle with CreateVehicleServerSetter, so no player needs to be near the coords.
GeneratePlateServerA random eight-character plate that no player_vehicles row uses.
GetVehicleOwnerByPlateServerThe citizenid owning a plate, and that vehicle's player_vehicles id.
GetVehiclesByCitizenIdServerRows of player_vehicles owned by a character, without the trunk and glovebox inventory columns.
GetVehicleTypeServerThe CreateVehicleServerSetter type of a model (automobile, bike, boat, heli, plane, submarine, train), read from the shared vehicle list, or asked of source's client for models not in it.
GetPlateClientThe vehicle's plate with surrounding spaces trimmed.
GetVehicleLabelClientThe vehicle's display name from the game's text labels, such as Sultan.
SetVehiclesServerAdds vehicles to data/vehicles.lua or changes fields on existing ones, then saves the file.

SpawnVehicle

Server

Spawns a vehicle with CreateVehicleServerSetter, so no player needs to be near the coords. It gets a random plate and full fuel.

exports.cobalt_core:SpawnVehicle(source, model, coords, warp, vehicleType)
ParameterTypeOptionalDescription
sourceintegerNo
modelinteger | stringNo
coordsvector3 | vector4Yesdefaults to the player's position
warpbooleanYesseat the player as the driver; the vehicle is deleted when that fails within 5 seconds
vehicleTypestringYessetter type such as automobile; looked up with GetVehicleType when left out
ReturnsDescription
integer?vehicle
string?plate
Example
local vehicle, plate = exports.cobalt_core:SpawnVehicle(
    source,
    1,
    vector3(215.8, -810.1, 30.7),
    true,
    'vehicleType'
)

GeneratePlate

Server

A random eight-character plate that no player_vehicles row uses. Errors when ten tries all hit taken plates.

exports.cobalt_core:GeneratePlate()
ReturnsDescription
string
Example
local result = exports.cobalt_core:GeneratePlate()

GetVehicleOwnerByPlate

Server

The citizenid owning a plate, and that vehicle's player_vehicles id.

exports.cobalt_core:GetVehicleOwnerByPlate(plate)
ParameterTypeOptionalDescription
platestringNo
ReturnsDescription
string?citizenid
integer?vehicleId
Example
local citizenid, vehicleId = exports.cobalt_core:GetVehicleOwnerByPlate('COBALT01')

GetVehiclesByCitizenId

Server

Rows of player_vehicles owned by a character, without the trunk and glovebox inventory columns. Pass fields to select only those columns; an unknown or inventory column raises an error.

exports.cobalt_core:GetVehiclesByCitizenId(citizenid, fields)
ParameterTypeOptionalDescription
citizenidstringNo
fieldsstring[]Yescolumn names, such as { 'plate' }; every column but trunk and glovebox when left out
ReturnsDescription
table[]
Example
local vehiclesByCitizenId = exports.cobalt_core:GetVehiclesByCitizenId('ABC12345', { 'fields' })

GetVehicleType

Server

The CreateVehicleServerSetter type of a model (automobile, bike, boat, heli, plane, submarine, train), read from the shared vehicle list, or asked of source's client for models not in it. Nil when the model is unknown or the client doesn't answer.

exports.cobalt_core:GetVehicleType(source, model)
ParameterTypeOptionalDescription
sourceintegerNo
modelstringNo
ReturnsDescription
string?
Example
local vehicleType = exports.cobalt_core:GetVehicleType(source, 'sultan')

GetPlate

Client

The vehicle's plate with surrounding spaces trimmed. Nil for no vehicle.

exports.cobalt_core:GetPlate(vehicle)
ParameterTypeOptionalDescription
vehicleintegerNo
ReturnsDescription
string?
Example
local plate = exports.cobalt_core:GetPlate(vehicle)

GetVehicleLabel

Client

The vehicle's display name from the game's text labels, such as Sultan. Nil for no vehicle.

exports.cobalt_core:GetVehicleLabel(vehicle)
ParameterTypeOptionalDescription
vehicleintegerNo
ReturnsDescription
string?
Example
local vehicleLabel = exports.cobalt_core:GetVehicleLabel(vehicle)

SetVehicles

Server

Adds vehicles to data/vehicles.lua or changes fields on existing ones, then saves the file. A new vehicle needs name, category, price and type. Players who joined before the change see it after their next join.

exports.cobalt_core:SetVehicles(vehicles)
ParameterTypeOptionalDescription
vehiclestable<string, { name?: string, brand?: string, category?: string, price?: integer, type?: string, shops?: string[], image?: string, enabled?: boolean }>Nofields by model
ReturnsDescription
string[]changed the models added or updated, sorted
Example
local changed = exports.cobalt_core:SetVehicles({})

On this page