OPX//77
opx_infinityvehicles

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?: table
    • appearance, garage, paint, metadata

Returns

  • Result — the vehicle; errors vehicle.limit (at PER_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)
Example
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.notFound when no row

PlateOf

No yield. Only vehicles this module has out.

vehicles.PlateOf(vehicleId)

Parameters

  • vehicleId: number

Returns

  • string?, string? — plate, citizenId, or nil, nil

LiveId

No yield, no database. Says nothing about ownership.

vehicles.LiveId(plate)

Parameters

  • plate: string

Returns

  • number? — the runtime id, or nil

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 value nil on 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 appears SPAWN_OFFSET m beside the player; if it is already out the answer is alreadyOut = true and 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 refused vehicle.occupied if 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.

Example
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' (out cannot be set: only Spawn creates a car).
  • garage?: string — refiles it

Returns

  • Result — { plate, state, garage }
Example
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

On this page