Server exports
Server exports for Vehicle Keys. Call them as exports.MrNewbVehicleKeys:Name(...).
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
| Export | Params | Returns |
|---|---|---|
GiveKeys | src, 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 / AddKeysByPlate | src, plate, autoKeyring? | boolean. Use when the vehicle is not spawned |
GiveKeysCustom | src, netid, plate, keyType, keyoptions, autoStart, spawnLocked, addToKeyring | boolean |
RemoveKeys | src, netid, includeKeyring? | boolean |
RemoveKeysByPlate | src, plate, includeKeyring? | boolean |
TransferKey | src, targetSrc, plate | boolean |
DuplicateKey | src, targetSrc, plate | boolean. Target gets a copy, original stays |
UpdateKey | src, oldPlate, newPlate | boolean. Re-plates one player’s key |
MigratePlate | oldPlate, newPlate | boolean. Moves the saved key profile. Item keys only. Does not touch held keys |
GrantRental | src, plate, modelName, netid, rentalLocation? | boolean. Keys plus rental_paperwork |
RemoveRental | src, plate, netid | boolean |
ClearSharedKeys | plate | number. 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 |
RemoveAllKeys | plate | number. 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
| Export | Params | Returns |
|---|---|---|
HasKeys / HaveKeys | src, netid | boolean |
HasKeysByPlate | src, plate | boolean |
GetPlayerKeys / GetVehicleKeyList | src | table of held keys |
CanAccessVehicle | src, netid, plate? | boolean. Key, temp key, or shared job access |
VerifyOwnership | src, plate | boolean |
GetVehicleInfo | plate | table or nil |
GetLockProfile | plate | table or false. Item keys only |
IsItemBasedMode / KeyType | none | boolean. true when keys are items |
IsInsertModeEnabled | none | boolean |
GetKeySystem | none | The live key system object. For deep integrations only |
HasPhoneKey / GetPhoneKeys | src, plate / src | boolean / table. Keys saved to the player's phone, for the companion phone app |
IsNpcLocksmithAvailable | none | boolean. true when the walk-up locksmith is out, false while staff of the locksmith job are online and hiding it |
GetApiVersion | none | number, currently 3. The level of this export surface, for companion resources to check |
Vehicle state
| Export | Params | Returns |
|---|---|---|
SetVehicleLock | netid, lockStatus | boolean. 1 unlocked, 2 locked |
RemoteLock | src, plate, lockStatus | boolean. As if that player used the fob |
DisableLockpickingVehicle | netid, status | boolean. true makes it lockpick-proof |
SetVehicleHotwireImmune | netid, immune | boolean. true uses up the hotwire attempts so the vehicle cannot be hotwired, false clears them |
IsKeyInIgnition | netid | boolean |
SetKeyInIgnition | netid, inserted, metadata? | boolean |
SearchForKeys | src, netId | boolean |
Temporary keys
A temp key works without an item. durationMs = nil means it does not expire.
| Export | Params | Returns |
|---|---|---|
SetTempKey | src, plate, durationMs? | boolean |
RemoveTempKey | src, plate | boolean |
SetTempKeyForPlayers | players, plate, durationMs? | count |
RemoveTempKeyForPlayers | players, plate | count |
SetTempKeyForJob | jobName, plate, durationMs? | count |
RemoveTempKeyForJob | jobName, plate | count |
HasTempKey | src, plate | boolean |
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
| Export | Arguments | Returns |
|---|---|---|
FlagVehicle | plate, reason, setBy? | boolean. reason is 'stolen' or 'warrant', and nil clears the flag. For MDT, phone and dispatch scripts |
GetVehicleFlag | plate | 'stolen', 'warrant' or nil |
TransferVehicleSecurity | oldPlate, newPlate | boolean, 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 |
