ai-vehiclekeys for developers
Server exports of ai-vehiclekeys, the qbx_vehiclekeys API it answers, and its events.
To give, take or check keys from your own script, use the lib's vehicleKeys.give(source, vehicle, purpose), vehicleKeys.remove and vehicleKeys.has (server). They go through ai-core's key layer and work with whichever key script the server runs. The exports below are what that layer calls while ai-vehiclekeys is the active key system.
All exports are on the server, synchronous, and answer under both ai-vehiclekeys and qbx_vehiclekeys. A vehicle is a server entity handle (number) or a plate (text). Plates are compared normalized (spaces and case do not matter).
import { resourceExport, callExport } from "@aicore-fivem/lib/server";
const keys = resourceExport("ai-vehiclekeys"); // typed: HasKeys, GiveKeys, RemoveKeys
// SetLockState and IsPlayerNearVehicle are not typed: callExport("ai-vehiclekeys", "SetLockState", vehicle, "lock")Server exports
HasKeys
Whether a player holds the key to a vehicle: as its owner, as a member of the owning job or gang, or through a key given this session.
Side: Server · Waits: no
HasKeys(source: number, vehicle: number | string): booleanlocal has = exports['ai-vehiclekeys']:HasKeys(source, vehicle)Parameters
Prop
Type
Returns
true when the player has the key. false otherwise, also for an entity that does not exist.
Example
import { resourceExport } from "@aicore-fivem/lib/server";
const keys = resourceExport("ai-vehiclekeys");
onNet("myscript:openTrunk", (netId: number) => {
const source = globalThis.source;
const vehicle = NetworkGetEntityFromNetworkId(netId);
if (!keys.HasKeys(source, vehicle)) return;
// ... open the trunk
});GiveKeys
Gives a player a key for this session. The player keeps it until they leave the server or switch character. Giving a key the player already holds does nothing.
Side: Server · Waits: no
GiveKeys(source: number, vehicle: number | string): voidexports['ai-vehiclekeys']:GiveKeys(source, vehicle)Parameters
Prop
Type
Returns
Nothing. If the player sits in that vehicle right now, their client is told (ai-vehiclekeys:client:granted): the engine block ends and the engine starts.
RemoveKeys
Takes a session key from a player. Ownership keys (owner, job or gang fleet) cannot be removed: they follow the vehicle's owner.
Side: Server · Waits: no
RemoveKeys(source: number, vehicle: number | string): voidexports['ai-vehiclekeys']:RemoveKeys(source, vehicle)Returns
Nothing.
SetLockState
Locks or unlocks a vehicle on the server, without any key check.
Side: Server · Waits: no
SetLockState(vehicle: number, state: "lock" | "unlock" | boolean | number): voidexports['ai-vehiclekeys']:SetLockState(vehicle, 'lock')Parameters
Prop
Type
Returns
Nothing. An entity that does not exist does nothing.
IsPlayerNearVehicle
Whether a player stands within 5 m of a vehicle.
Side: Server · Waits: no
IsPlayerNearVehicle(source: number, vehicle: number): booleanlocal near = exports['ai-vehiclekeys']:IsPlayerNearVehicle(source, vehicle)Returns
true within 5 m. false when farther, or when either argument is not a number.
Events
ai-vehiclekeys' own events are internal (client callbacks between its client and server). Do not call them from other scripts.
| Name | Kind | What it does |
|---|---|---|
ai-vehiclekeys:check | client callback | (netId) -> boolean: whether the player holds a key, asked when they take a seat. |
ai-vehiclekeys:toggleLock | client callback | (netId) -> { ok, locked? }: the lock key. |
ai-vehiclekeys:giveNearest | client callback | (netId) -> { ok }: hand over the keys to the nearest player. |
ai-vehiclekeys:client:granted | server to client | (netId): a key arrived while sitting in that vehicle; the engine may start. |
Usable item
lockpick is registered as a usable item through ai-core's inventory layer. The item is used up only when it breaks.