Server exports

Server exports for Vehicle Keys. Call them as exports.MrNewbVehicleKeys:Name(...).

In-development version. These docs cover the testing build of VehicleKeys. The official release is still documented on the GitBook linked in its README.

Call them as exports.MrNewbVehicleKeys:Name(...). They return false (or an empty table / 0 for lists and counts) if the key system is not ready yet. Wait until the resource is started. plate is trimmed for you. netid is a vehicle network id.

Giving and removing

ExportParamsReturns
GiveKeyssrc, netid, autoKeyring?boolean. autoKeyring = true puts it on their keyring. A plate string in place of netid is read as a jg-vehiclekeys call and returns that script's result table
GiveKeysByPlate / AddKeysByPlatesrc, plate, autoKeyring?boolean. Use when the vehicle is not spawned
GiveKeysCustomsrc, netid, plate, keyType, keyoptions, autoStart, spawnLocked, addToKeyringboolean
RemoveKeyssrc, netid, includeKeyring?boolean
RemoveKeysByPlatesrc, plate, includeKeyring?boolean
TransferKeysrc, targetSrc, plateboolean
DuplicateKeysrc, targetSrc, plateboolean. Target gets a copy, original stays
UpdateKeysrc, oldPlate, newPlateboolean. Re-plates one player’s key
MigratePlateoldPlate, newPlateboolean. Moves the saved key profile. Item keys only. Does not touch held keys
GrantRentalsrc, plate, modelName, netid, rentalLocation?boolean. Keys plus rental_paperwork
RemoveRentalsrc, plate, netidboolean
ClearSharedKeysplatenumber. Ends every keyring share of that car right away and returns how many people lost access. Shares also end on their own when the owner no longer owns the car
RemoveAllKeysplatenumber. Takes every key on that plate from every online player and returns how many lost access. See Remove all keys for what it cannot reach

keyType is smart, luxury, basic, boat, or motorcycle (classic, display, and bike are aliases). keyoptions is a list of fob module ids.

exports.MrNewbVehicleKeys:GiveKeys(src, NetworkGetNetworkIdFromEntity(veh))
exports.MrNewbVehicleKeys:GiveKeysByPlate(src, plate)
exports.MrNewbVehicleKeys:RemoveKeysByPlate(src, plate, true)
exports.MrNewbVehicleKeys:GiveKeysCustom(src, netid, plate, 'smart', {}, true, false, true)

Remove all keys

Use RemoveAllKeys when a car is scrapped, wiped or reset and nobody should keep access.

local lost = exports.MrNewbVehicleKeys:RemoveAllKeys(plate)

For every player who is online it removes:

  • key items for that plate, including keyring and phone copies
  • the virtual key, when keys are not items
  • shared keyring access (those players get the "shared key revoked" notice)
  • a temporary key

It returns how many online players lost access. It does not remove the car itself or its saved key profile.

Limits

  • It only reaches players who are online. Keys in the inventory of an offline player stay where they are.
  • It cannot see key items stored in stashes, trunks and gloveboxes, or dropped on the ground. Those stay valid.
  • The saved key profile of the plate is left alone, so a leftover key item that turns up later still matches the plate. Re-issuing or resetting the plate's profile is a separate step.
  • It is a server export. A plate that is not a string returns 0.

Checking

ExportParamsReturns
HasKeys / HaveKeyssrc, netidboolean
HasKeysByPlatesrc, plateboolean
GetPlayerKeys / GetVehicleKeyListsrctable of held keys
CanAccessVehiclesrc, netid, plate?boolean. Key, temp key, or shared job access
VerifyOwnershipsrc, plateboolean
GetVehicleInfoplatetable or nil
GetLockProfileplatetable or false. Item keys only
IsItemBasedMode / KeyTypenoneboolean. true when keys are items
IsInsertModeEnablednoneboolean
GetKeySystemnoneThe live key system object. For deep integrations only
HasPhoneKey / GetPhoneKeyssrc, plate / srcboolean / table. Keys saved to the player's phone, for the companion phone app
IsNpcLocksmithAvailablenoneboolean. true when the walk-up locksmith is out, false while staff of the locksmith job are online and hiding it
GetApiVersionnonenumber, currently 3. The level of this export surface, for companion resources to check

Vehicle state

ExportParamsReturns
SetVehicleLocknetid, lockStatusboolean. 1 unlocked, 2 locked
RemoteLocksrc, plate, lockStatusboolean. As if that player used the fob
DisableLockpickingVehiclenetid, statusboolean. true makes it lockpick-proof
SetVehicleHotwireImmunenetid, immuneboolean. true uses up the hotwire attempts so the vehicle cannot be hotwired, false clears them
IsKeyInIgnitionnetidboolean
SetKeyInIgnitionnetid, inserted, metadata?boolean
SearchForKeyssrc, netIdboolean

Temporary keys

A temp key works without an item. durationMs = nil means it does not expire.

ExportParamsReturns
SetTempKeysrc, plate, durationMs?boolean
RemoveTempKeysrc, plateboolean
SetTempKeyForPlayersplayers, plate, durationMs?count
RemoveTempKeyForPlayersplayers, platecount
SetTempKeyForJobjobName, plate, durationMs?count
RemoveTempKeyForJobjobName, platecount
HasTempKeysrc, plateboolean
exports.MrNewbVehicleKeys:SetTempKeyForJob('mechanic', plate, 30 * 60 * 1000)

Events other scripts already fire

When that resource is switched on under General > Other key scripts, these keep working: qb-vehiclekeys:server:AcquireVehicleKeys, :GiveVehicleKeys, :RemoveVehicleKeys, the client AcquireVehicleKeys / AddKeys / RemoveKeys, vehiclekeys:client:SetOwner, and the garage store events that take the key back (qb-garages, esx_garage, qbx park). Boosting, AdvancedParking, ak47 car dealer, and jobs_creator garage events are handled when that resource is present.

For your own server scripts, use the exports. They are not gated on the sender standing next to the car.

Vehicle transferred

When a car changes hands, tell the keys script so shared keys on it end at once:

TriggerEvent('MrNewbVehicleKeys:Server:VehicleTransferred', plate)

That does the same as the ClearSharedKeys export. Without it, a sweep that runs every 10 minutes ends the shares for the standard framework vehicle tables.

Every other MrNewbVehicleKeys:Server:* and MrNewbVehicleKeys:Client:* event is internal. Client exports: Client exports.

Police flags

ExportArgumentsReturns
FlagVehicleplate, reason, setBy?boolean. reason is 'stolen' or 'warrant', and nil clears the flag. For MDT, phone and dispatch scripts
GetVehicleFlagplate'stolen', 'warrant' or nil
TransferVehicleSecurityoldPlate, newPlateboolean, true when something moved. Call it when a car's plate changes (a plate changer, a garage) so it keeps its alarm tier, immobiliser kind and police flag. A keypad lock keeps its place but not its PIN, because the PIN is tied to the plate: the next key holder chooses a new one. Safe to call more than once for the same change

On this page