OPX//77
opx_infinityvehiclekeys

Server

Last updated on

The vehiclekeys contract on the server — plates, cutting and revoking keys, and turning the lock.

local keys = OPX.Api.Get('vehiclekeys')

From server code inside opx_infinity. Functions that read the bag may yield: call them from a thread. target is a player source or a citizen id.

Identity

The vehicle's plate; mints a TMP- plate when it has none.

keys.Identity(vehicleId)

Parameters

  • vehicleId: number | string — the host's vehicle id

Returns

  • Result — { plate, record, owned, label, owner? }
    • owned is true for a vehicles plate (owner = citizen id)

Count

Keys to that plate in the bag of target.

keys.Count(target, plate)

Parameters

  • target: number | string
  • plate: string

Returns

  • integer — 0 without inventory

Holds

Whether the bag of target holds a key to a live vehicle. Looks the plate up and never mints one: a vehicle nobody cut a key for answers false. For deciding whether a vehicle is the player's to use without turning its lock.

keys.Holds(target, vehicleId)

Parameters

  • target: number | string
  • vehicleId: number | string — the host's vehicle id

Returns

  • boolean
Example
if not keys.Holds(source, vehicleId) then return Result.Err('not_your_trunk') end

Give

Always adds one key.

keys.Give(target, plate, model)

Parameters

  • target: number | string
  • plate: string
  • model?: string
    • A label or a TweakDB record, used for the key label.

Returns

  • Result — { plate, label }
Example
local cut = keys.Give(source, '12ABC345', 'Villefort Cortes')
if not cut.ok then print(cut.error) end

GiveFor

Resolves the plate from the live vehicle (Identity), then Give.

keys.GiveFor(target, vehicleId, model)

Parameters

  • target: number | string
  • vehicleId: number | string — the host's vehicle id
  • model?: string

Returns

  • Result — { plate, label }

Ensure

Adds a key only when the bag holds none.

keys.Ensure(target, plate, model)

Parameters

  • target: number | string
  • plate: string
  • model?: string

Returns

  • Result — { given, plate, label }; given says whether one was added

Revoke

Yields for an offline bag. Takes every key to that plate out of one bag, whatever its label. Keys in stashes or trunks are not touched. Needs the inventory's RemoveWhere (else vehiclekeys.unavailable).

keys.Revoke(target, plate)

Parameters

  • target: number | string
  • plate: string

Returns

  • Result — { plate, removed }

RevokeAll

Revoke on the bag of every loaded character; offline bags are not walked. To re-key a car for good, change its plate. Audited vehiclekeys.revokeAll.

keys.RevokeAll(plate)

Parameters

  • plate: string

Returns

  • Result — { plate, removed, holders }

Toggle

Locks or unlocks for a player who holds the key and is in reach. Does not mint a plate.

keys.Toggle(source, vehicleId)

Parameters

  • source: number
  • vehicleId: number | string — the host's vehicle id

Returns

  • Result — { locked, label }; locked is the new state

On this page