Server
Last updated on
The vehicles contract on the server — register, list, spawn and store owned vehicles.
local vehicles = OPX.Api.Get('vehicles')From server code inside opx_infinity. Every function that reads the database yields: call it from a CreateThread.
A vehicle table has plate, citizenId, record, appearance, garage, state (0 out, 1 stored, 2 impounded), health, damage, paint, metadata, fuel (litres; nil for a car never measured).
Register
Yields. Creates a row under a fresh plate, state stored, in options.garage or DEFAULT_GARAGE.
vehicles.Register(citizenId, record, options)Parameters
- citizenId:
string - record:
string— the vehicle record, max 256 characters - options?:
tableappearance,garage,paint,metadata
Returns
Result— the vehicle; errorsvehicle.limit(atPER_CHARACTER),vehicle.registering(another registration for this character held the turn over 5 s),vehicle.badRecord(over 256 characters),vehicle.plateExhausted(after 5 colliding draws)
CreateThread(function()
local made = vehicles.Register(citizenId, 'Vehicle.v_standard2_archer_hella_player')
if made.ok then print(made.value.plate) end
end)List
Yields. Every row the character owns, oldest first.
vehicles.List(citizenId)Parameters
- citizenId:
string
Returns
Result—vehicle[]
Get
Yields. One row, plus spawned (boolean) and id (runtime id when out).
vehicles.Get(plate)Parameters
- plate:
string
Returns
Result— the vehicle;vehicle.notFoundwhen no row
PlateOf
No yield. Only vehicles this module has out.
vehicles.PlateOf(vehicleId)Parameters
- vehicleId:
number
Returns
string?,string?—plate, citizenId, ornil, nil
LiveId
No yield, no database. Says nothing about ownership.
vehicles.LiveId(plate)Parameters
- plate:
string
Returns
number?— the runtime id, ornil
Occupied
No yield. The owned vehicle the player sits in, read from the host's seat assignment.
vehicles.Occupied(source)Parameters
- source:
number
Returns
Result—{ plate, id }, or valuenilon foot or in a car they do not own
Spawn
Yields. Ownership is proved from the loaded character. Stored damage and flags are re-applied.
vehicles.Spawn(source, plate, at)Parameters
- source:
number - plate:
string - at?:
table{ x, y, z, yaw?, bucket? }. Without it the car appearsSPAWN_OFFSETm beside the player; if it is already out the answer isalreadyOut = trueand nothing moves.- With it the car is created exactly there; a car already out is stored first and created again at
at(recalled = true), or refusedvehicle.occupiedif anyone sits in it.
Returns
Result—{ plate, id, recalled?, alreadyOut? }
Spawn with a named place moves a car that is already out. That is how a garage marker "recalls" a car parked elsewhere.
CreateThread(function()
local out = vehicles.Spawn(source, '12ABC345', { x = -1442.2, y = 127.4, z = 18.0, yaw = 90.0 })
if not out.ok then print(out.error) end
end)Store
Yields. Writes condition back and removes the car. No ownership check: the caller must prove it.
vehicles.Store(plate, garage)Parameters
- plate:
string - garage?:
string— re-files it
Returns
Result—{ plate }
SetState
Yields. A car that is out is put away first; refused with vehicle.occupied while anyone sits in it. Takes the same per-plate claim as Spawn (vehicle.busy while one runs). Audited vehicle.state.
vehicles.SetState(plate, state, garage)Parameters
- plate:
string - state:
string'stored'or'impounded'(outcannot be set: onlySpawncreates a car).
- garage?:
string— refiles it
Returns
Result—{ plate, state, garage }
CreateThread(function() vehicles.SetState('12ABC345', 'impounded', 'impound') end)StoreAll
Yields. Stores every out vehicle of one character, or of everyone when nil.
vehicles.StoreAll(citizenId)Parameters
- citizenId?:
string
Returns
integer— how many were stored