OPX//77
opx_infinityvehiclekeys

vehiclekeys

Last updated on

Vehicle keys as inventory items, and the host lock a key turns.

Makes a car key an inventory item. Each key is one vehicle_key item whose metadata names the plate it opens. A player holding the key can lock or unlock that car from the target eye (Lock / unlock) or by using the key from their bag, standing within 6 m or sitting in it. Keys are cut automatically when a car is bought or brought out of a garage, and staff can cut one for any vehicle. A locked car cannot be entered and its trunk will not open.

Sideboth
Requiresnone
Optionalvehicles, inventory, target
Contractvehiclekeys v1 — server
Confignone (constants in modules/vehiclekeys/module.lua)
Datanone of its own; keys are vehicle_key items in inventory
  • Without inventory (or an inventory without CountWhere) no key is ever cut and no lock can be turned.
  • Without vehicles every vehicle gets a minted plate.
  • Without target there is no row, but a key still works from the bag.

How keys work

  • The item. vehicle_key: weight 20, category tool, does not stack, using it consumes nothing. Metadata { plate, label }, where label is <model> · <plate> (for example Villefort Cortes · 12ABC345), or the plate alone. Only the server writes it.
  • The plate is the identity. An owned vehicle uses its real plate. A vehicle vehicles never registered (a staff spawn, a showroom car, another resource's car) gets a minted plate, TMP- plus six characters, the first time a key is cut for it. A minted plate is held in memory only and is forgotten when the host removes the vehicle; its keys then open nothing. Plates are matched exactly as written, byte for byte: nothing is upper-cased or trimmed, so a legacy plate such as ABC 123 keeps its space.
  • Who gets a key.
    • The buyer, on every dealership sale.
    • The owner, when a garage brings the car out and their bag holds no key to that plate.
    • The player a staff spawn was made for, and a staff member using /opx.admin.vehicle.key.
    • A full bag is told to the player (vehiclekeys.noRoom) and never refuses the sale or the take-out.
  • What a key does. It flips the host's replicated entry lock (Open77.vehicles.setLocked). The server checks: the vehicle exists, the player sits in it or stands within 6 m in the same bucket, and their bag holds a key whose plate is that vehicle's. A trunk or glovebox key does not count. On success the horn chirps and a toast says locked or unlocked. A locked vehicle's trunk is refused by the inventory module.
  • The target row is vehiclekeys.toggle (Lock / unlock), on vehicles, 6 m, shown only when the bag holds at least one key; its checkbox shows the replicated lock state.

Refusal codes

Each code is also a locale key (English and French).

CodeMeaning
vehiclekeys.noVehicleNo live vehicle with that id, or the used key has no plate.
vehiclekeys.notOutThe vehicle the used key opens is not in the world.
vehiclekeys.tooFarNot seated in it and further than 6 m plus REACH_SLACK (7 m by default), or in another bucket.
vehiclekeys.noKeyNo key to that vehicle in the bag.
vehiclekeys.lockRefusedThe host refused the lock change, cannot read the lock, or the lock native raised.
vehiclekeys.noRoomThe bag is full or too heavy for the key (detail: the key label).
vehiclekeys.unavailableNo inventory, or the item could not be added for another reason.
vehiclekeys.tooFastToggle cooldown (toast only).
error.incapacitatedThe player is down: no lock turned from the floor.
error.badRequestThe plate is not a valid plate: 1–16 printable ASCII characters, not only blanks.

On this page