Vehicles
cobalt_core exports: vehicles.
| Export | Side | What it does |
|---|---|---|
SpawnVehicle | Server | Spawns a vehicle with CreateVehicleServerSetter, so no player needs to be near the coords. |
GeneratePlate | Server | A random eight-character plate that no player_vehicles row uses. |
GetVehicleOwnerByPlate | Server | The citizenid owning a plate, and that vehicle's player_vehicles id. |
GetVehiclesByCitizenId | Server | Rows of player_vehicles owned by a character, without the trunk and glovebox inventory columns. |
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. |
GetPlate | Client | The vehicle's plate with surrounding spaces trimmed. |
GetVehicleLabel | Client | The vehicle's display name from the game's text labels, such as Sultan. |
SetVehicles | Server | Adds vehicles to data/vehicles.lua or changes fields on existing ones, then saves the file. |
SpawnVehicle
ServerSpawns 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)| Parameter | Type | Optional | Description |
|---|---|---|---|
source | integer | No | |
model | integer | string | No | |
coords | vector3 | vector4 | Yes | defaults to the player's position |
warp | boolean | Yes | seat the player as the driver; the vehicle is deleted when that fails within 5 seconds |
vehicleType | string | Yes | setter type such as automobile; looked up with GetVehicleType when left out |
| Returns | Description |
|---|---|
integer? | vehicle |
string? | plate |
local vehicle, plate = exports.cobalt_core:SpawnVehicle(
source,
1,
vector3(215.8, -810.1, 30.7),
true,
'vehicleType'
)GeneratePlate
ServerA random eight-character plate that no player_vehicles row uses. Errors when ten tries all hit taken plates.
exports.cobalt_core:GeneratePlate()| Returns | Description |
|---|---|
string |
local result = exports.cobalt_core:GeneratePlate()GetVehicleOwnerByPlate
ServerThe citizenid owning a plate, and that vehicle's player_vehicles id.
exports.cobalt_core:GetVehicleOwnerByPlate(plate)| Parameter | Type | Optional | Description |
|---|---|---|---|
plate | string | No |
| Returns | Description |
|---|---|
string? | citizenid |
integer? | vehicleId |
local citizenid, vehicleId = exports.cobalt_core:GetVehicleOwnerByPlate('COBALT01')GetVehiclesByCitizenId
ServerRows 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)| Parameter | Type | Optional | Description |
|---|---|---|---|
citizenid | string | No | |
fields | string[] | Yes | column names, such as { 'plate' }; every column but trunk and glovebox when left out |
| Returns | Description |
|---|---|
table[] |
local vehiclesByCitizenId = exports.cobalt_core:GetVehiclesByCitizenId('ABC12345', { 'fields' })GetVehicleType
ServerThe 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)| Parameter | Type | Optional | Description |
|---|---|---|---|
source | integer | No | |
model | string | No |
| Returns | Description |
|---|---|
string? |
local vehicleType = exports.cobalt_core:GetVehicleType(source, 'sultan')GetPlate
ClientThe vehicle's plate with surrounding spaces trimmed. Nil for no vehicle.
exports.cobalt_core:GetPlate(vehicle)| Parameter | Type | Optional | Description |
|---|---|---|---|
vehicle | integer | No |
| Returns | Description |
|---|---|
string? |
local plate = exports.cobalt_core:GetPlate(vehicle)GetVehicleLabel
ClientThe vehicle's display name from the game's text labels, such as Sultan. Nil for no vehicle.
exports.cobalt_core:GetVehicleLabel(vehicle)| Parameter | Type | Optional | Description |
|---|---|---|---|
vehicle | integer | No |
| Returns | Description |
|---|---|
string? |
local vehicleLabel = exports.cobalt_core:GetVehicleLabel(vehicle)SetVehicles
ServerAdds 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)| Parameter | Type | Optional | Description |
|---|---|---|---|
vehicles | table<string, { name?: string, brand?: string, category?: string, price?: integer, type?: string, shops?: string[], image?: string, enabled?: boolean }> | No | fields by model |
| Returns | Description |
|---|---|
string[] | changed the models added or updated, sorted |
local changed = exports.cobalt_core:SetVehicles({})