Documentation

Exports & Events

All exports and events available to integrate this resource into others.

Identifiers

Vehicle Keys uses normalized plates as its public identity. Client key exports also accept a vehicle entity. When the identifier is omitted, they use the vehicle the player is currently driving.

Server Authority

Use the server exports for authoritative grants and persistent garage integrations. Client grants act on the calling player.

Suggestions?

If you wish to have any exports or events added, please head over to our Discord and create a suggestion post.

#Client Sided Exports

#Give Key

Gives the local player permanent access to a vehicle.

Example:

lua
---@param plateOrVehicle? string | integer @Plate or vehicle entity, defaults to the current vehicle
---@return boolean success
local success = exports["zyke_vehiclekeys"]:GiveKey(plateOrVehicle)

#Give Temporary Key

Gives the local player temporary access to a vehicle.

Example:

lua
---@param plateOrVehicle? string | integer @Plate or vehicle entity, defaults to the current vehicle
---@return boolean success
local success = exports["zyke_vehiclekeys"]:GiveTemporaryKey(plateOrVehicle)

#Give Temp Keys

Deprecated alias for GiveTemporaryKey.

Example:

lua
---@param plateOrVehicle? string | integer @Plate or vehicle entity, defaults to the current vehicle
---@return boolean success
local success = exports["zyke_vehiclekeys"]:GiveTempKeys(plateOrVehicle)

#Remove Key

Removes matching access from the local player.

Example:

lua
---@param plateOrVehicle? string | integer @Plate or vehicle entity, defaults to the current vehicle
---@return boolean success
local success = exports["zyke_vehiclekeys"]:RemoveKey(plateOrVehicle)

#Has Key

Checks whether the local player has access to a vehicle.

Example:

lua
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)

---@param plateOrVehicle? string | integer @Plate or vehicle entity, defaults to the current vehicle
---@return boolean hasKey
local hasKey = exports["zyke_vehiclekeys"]:HasKey(vehicle)

#Open Menu

Opens a specific plate's key fob or the full vehicle list when no plate is provided.

Example:

lua
---@param plate? string
exports["zyke_vehiclekeys"]:OpenMenu(plate)

#Set Lock State

Requests a server-validated lock state for a vehicle.

Example:

lua
---@param vehicle integer
---@param locked boolean
---@param keyFobAction? boolean @Play the configured key-fob feedback
---@return boolean success
local success = exports["zyke_vehiclekeys"]:SetLockState(vehicle, true, true)

#Set Engine State

Requests a server-validated engine state for a vehicle.

Example:

lua
---@param vehicle integer
---@param enabled boolean
---@param keyFobAction? boolean @Play the configured key-fob feedback
---@return boolean success
local success = exports["zyke_vehiclekeys"]:SetEngineState(vehicle, true, true)

#Play Key Fob Sound

Plays the configured player key-fob sound when zyke_sounds is available.

Example:

lua
---@return boolean success
local success = exports["zyke_vehiclekeys"]:PlayKeyFobSound()

#Start Searching Keys

Starts the configured NPC vehicle key-search flow.

Example:

lua
---@param vehicle integer
---@param method? string
---@param skipChallenge? boolean
---@return boolean success
local success = exports["zyke_vehiclekeys"]:StartSearchingKeys(vehicle, method, skipChallenge)

#Check Ped Witnesses

Checks whether an eligible pedestrian witnessed the supplied event and returns the matching witnesses.

data accepts coords and optional entity, netId, excluded ped or vehicle values, maxDistance, and fieldOfView.

Example:

lua
---@param data table
---@return boolean witnessed
---@return table[] witnesses
local witnessed, witnesses = exports["zyke_vehiclekeys"]:CheckPedWitnesses({
    coords = GetEntityCoords(PlayerPedId()),
    entity = vehicle,
})

#Get Item Label Settings

Returns the physical key-label configuration.

Example:

lua
---@return table settings @Contains base, allowCustom, and maxCharacters
local settings = exports["zyke_vehiclekeys"]:GetItemLabelSettings()

#Get Saved Item Label

Returns the local player's saved label template or the configured default.

Example:

lua
---@return string label
local label = exports["zyke_vehiclekeys"]:GetSavedItemLabel()

#Set Saved Item Label

Saves a custom physical key-label template for the local player.

Example:

lua
---@param label string
---@return boolean success
local success = exports["zyke_vehiclekeys"]:SetSavedItemLabel(label)

#Get Personal Settings

Returns the personal setting definitions and their current values.

Example:

lua
---@return table definitions
---@return table values
local definitions, values = exports["zyke_vehiclekeys"]:GetPersonalSettings()

#Set Personal Setting

Updates holdExitToKeepState or autoStartEngine when the setting is not forced by configuration.

Example:

lua
---@param name string
---@param value boolean
---@return boolean success
local success = exports["zyke_vehiclekeys"]:SetPersonalSetting(name, value)

#Get Keybinds

Returns translated action labels and the player's current mapped keys.

Example:

lua
---@return table[] keybinds
local keybinds = exports["zyke_vehiclekeys"]:GetKeybinds()

#Get Capabilities

Returns the active Vehicle Keys capability map.

Example:

lua
---@return table capabilities
local capabilities = exports["zyke_vehiclekeys"]:GetCapabilities()

#Server Sided Exports

#Give Key

Gives permanent physical or identifier access to a player.

player accepts a server ID or character identifier. context can contain vin, modelLabel, enforceLimit, and reconcileExisting.

Example:

lua
---@param player integer | string @Server ID or character identifier
---@param plate string
---@param allowFallback? boolean
---@param context? table
---@return boolean success
---@return string? reason
local success, reason = exports["zyke_vehiclekeys"]:GiveKey(player, plate, true, {
    modelLabel = "Sultan",
    enforceLimit = true,
})

#Give Temporary Key

Gives temporary access to a player.

Example:

lua
---@param player integer | string @Server ID or character identifier
---@param plate string
---@param skipCanGiveCheck? boolean
---@param allowFallback? boolean
---@return boolean success
---@return string? reason
local success, reason = exports["zyke_vehiclekeys"]:GiveTemporaryKey(player, plate, false, true)

#Give Temp Keys

Deprecated alias for GiveTemporaryKey.

Example:

lua
---@param player integer | string @Server ID or character identifier
---@param plate string
---@param skipCanGiveCheck? boolean
---@param allowFallback? boolean
---@return boolean success
---@return string? reason
local success, reason = exports["zyke_vehiclekeys"]:GiveTempKeys(player, plate, false, true)

#Remove Key

Removes the player's matching permanent, temporary, and physical-key access.

Example:

lua
---@param player integer | string @Server ID or character identifier
---@param plate string
---@return integer removed
local removed = exports["zyke_vehiclekeys"]:RemoveKey(player, plate)

#Remove All Keys

Alias for RemoveKey used by provider integrations.

Example:

lua
---@param player integer | string @Server ID or character identifier
---@param plate string
---@return integer removed
local removed = exports["zyke_vehiclekeys"]:RemoveAllKeys(player, plate)

#Has Key

Checks physical, persistent, garage-supplied, and runtime access for a player.

Example:

lua
---@param player integer | string @Server ID or character identifier
---@param plate string
---@return boolean hasKey
local hasKey = exports["zyke_vehiclekeys"]:HasKey(player, plate)

#Rotate Keys

Invalidates old physical keys, or clears direct identifier access, and resets the key counter.

Example:

lua
---@param plate string
---@return boolean success
local success = exports["zyke_vehiclekeys"]:RotateKeys(plate)

#Rename Plate

Moves the plate state and preserves an alias for offline physical keys.

Example:

lua
---@param oldPlate string
---@param newPlate string
---@return boolean success
local success = exports["zyke_vehiclekeys"]:RenamePlate(oldPlate, newPlate)

#Delete Vehicle

Clears access and retires plate frequencies before plate reuse.

Example:

lua
---@param plate string
---@return boolean success
local success = exports["zyke_vehiclekeys"]:DeleteVehicle(plate)

#Set Access

Replaces garage-supplied persistent entitlement for a plate.

identifiers accepts an array of identifiers or an identifier-to-boolean map.

Example:

lua
---@param plate string
---@param identifiers table
---@return boolean success
local success = exports["zyke_vehiclekeys"]:SetAccess(plate, identifiers)

#Set Temporary Access

Replaces provider-owned runtime access in identifier mode.

identifiers accepts an array of identifiers or an identifier-to-boolean map.

Example:

lua
---@param plate string
---@param identifiers table
---@return boolean success
local success = exports["zyke_vehiclekeys"]:SetTemporaryAccess(plate, identifiers)

#Import Vehicle State

Inserts legacy frequency, counter, and access without overwriting an existing plate row.

state accepts frequency or keyFreq, keyCounter or key_counter, and access.

Example:

lua
---@param plate string
---@param state table
---@return boolean success
local success = exports["zyke_vehiclekeys"]:ImportVehicleState(plate, state)

#Get Key Counter

Returns the tracked number of current permanent keys.

Example:

lua
---@param plate string
---@return integer keyCount
local keyCount = exports["zyke_vehiclekeys"]:GetKeyCounter(plate)

#Get Key Frequency

Returns the current physical-key frequency.

Example:

lua
---@param plate string
---@return integer frequency
local frequency = exports["zyke_vehiclekeys"]:GetKeyFrequency(plate)

#Increment Key Counter

Increments the tracked key counter.

Example:

lua
---@param plate string
---@return boolean success
local success = exports["zyke_vehiclekeys"]:IncrementKeyCounter(plate)

#Decrement Key Counter

Decrements the tracked key counter without going below zero.

Example:

lua
---@param plate string
---@param amount? integer
---@return boolean success
local success = exports["zyke_vehiclekeys"]:DecrementKeyCounter(plate, amount)

#Reset Key Counter

Resets the tracked key counter to zero.

Example:

lua
---@param plate string
---@return boolean success
local success = exports["zyke_vehiclekeys"]:ResetKeyCounter(plate)

#Get Accessible Plates

Returns sorted plates currently accessible to a player.

Example:

lua
---@param playerId integer
---@return string[] plates
local plates = exports["zyke_vehiclekeys"]:GetAccessiblePlates(playerId)

#Get Capabilities

Returns the supported provider operations and active access mode.

The result includes access mode, required and optional provider operations, UI and control support, server authority, and the configured maximum action distance.

Example:

lua
---@return table capabilities
local capabilities = exports["zyke_vehiclekeys"]:GetCapabilities()

#Notify Vehicle Action

Lets a persistent provider trigger Vehicle Keys action feedback, currently lock and unlock sound.

Example:

lua
---@param playerId integer
---@param netId integer
---@param action string
---@param desiredState boolean
exports["zyke_vehiclekeys"]:NotifyVehicleAction(playerId, netId, action, desiredState)

#Events

#On Key Change

Emitted on the server and the affected client when key access changes.

data always includes action and plate, with an optional source. Depending on the action it can also include accessMode, temporary, frequency, removed, permanentRemoved, temporaryRemoved, or oldPlate.

Actions currently include give, remove, rotate, rename, and delete.

Example:

lua
AddEventHandler("zyke_vehiclekeys:OnKeyChange", function(data)
    print(data.action, data.plate, data.source)
end)

#On Key Give

Emitted on the server and the affected client for non-temporary physical and persistent identifier grants.

Example:

lua
AddEventHandler("zyke_vehiclekeys:OnKeyGive", function(plate, data)
    print(plate, data)
end)

#On Key Remove

Emitted on the server and the affected client when key access is removed.

Example:

lua
AddEventHandler("zyke_vehiclekeys:OnKeyRemove", function(plate, data)
    print(plate, data)
end)

#On Frequency Changed

Emitted on the server when a plate's physical-key frequency changes. All clients receive the frequency update.

Example:

lua
AddEventHandler("zyke_vehiclekeys:OnFrequencyChanged", function(plate, frequency, data)
    print(plate, frequency, data)
end)

#On Key Robbery

Emitted after the server OnKeyRobbery hook. A local client event is also emitted for client-detected theft stages.

Robbery data can include type, stage, method, source, plate, model, vehicle and network IDs, coordinates, witness state, and witness details. The type can be keyTheft, npcRobbery, lockpick, or hotwire.

Example:

lua
AddEventHandler("zyke_vehiclekeys:OnKeyRobbery", function(data)
    print(data.type, data.stage, data.plate)
end)

#On Personal Setting Changed

Client-only event emitted after holdExitToKeepState or autoStartEngine changes.

Example:

lua
AddEventHandler("zyke_vehiclekeys:OnPersonalSettingChanged", function(name, value)
    print(name, value)
end)