Commands & Exports

This section lists all available commands, exports, and events included in the script. You’ll find client-side, server-side, and shared functions designed to help developers integrate, extend, or interact with the system easily within their own scripts or frameworks.


Commands

This section lists all available commands included in the script. Each command is designed to simplify administration, player interaction, or debugging tasks. You’ll find detailed descriptions, usage examples, and permission requirements to help you manage and customize your server efficiently.

Command
Description

/givekey [id]

Command for administrative use, gives keys to the player but must be inside a vehicle.


Client Exports

This section provides all available client exports for the script. These functions allow you to interact directly with the system from the client side, enabling custom features, UI interactions, and integrations with other resources. Each export includes a short description and usage example for easy implementation.

GiveKeys

The GiveKeys export allows you to assign vehicle keys to a player for a specified vehicle. This is particularly useful for third-party assets, such as vehicle shops, to grant ownership access.


Obtain the Plate Natively

To use the GiveKeys export effectively, you need the vehicle's plate and model. Here is a simple code snippet to obtain these values natively:

local model = GetDisplayNameFromVehicleModel(GetEntityModel(veh))
local plate = GetVehicleNumberPlateText(veh)

With these values, you can seamlessly integrate the export into your script.


How to Use

To give keys to a player, use the following code:

exports['qs-vehiclekeys']:GiveKeys(plate, model, true)
  • plate: The license plate of the vehicle.

  • model: The model of the vehicle.

  • bypassKeyCheck: (optional) A boolean value that, if set to true, bypasses the key validation check. By default, it is set to false.


Example

Here is an example of how to use the GiveKeys export in a vehicle shop script:

ESX.TriggerServerCallback('esx_vehicleshop:buyVehicle', function(success)
    if success then
        -- Retrieve the model and plate of the purchased vehicle
        local model = GetDisplayNameFromVehicleModel(GetEntityModel(vehicleData))
        local plate = GetVehicleNumberPlateText(vehicleData)

        -- Give keys to the player
        exports['qs-vehiclekeys']:GiveKeys(plate, model, true)
    else
        ESX.ShowNotification("You don't have enough money to purchase this vehicle.")
    end
end, vehicleData.model, generatedPlate)

This export simplifies the process of assigning keys to players, making it ideal for use in scenarios like vehicle purchases, rentals, or administrative commands. Integrate it with the plate and model retrieval logic to ensure a smooth experience.

RemoveKeys

The RemoveKeys export allows you to revoke a player's access to a specified vehicle by removing its keys. This is useful for scenarios such as repossessions, administrative actions, or vehicle ownership changes.


Obtain the Plate Natively

To use the RemoveKeys export, you need the vehicle's plate and model. Use the following code snippet to retrieve these values:

local model = GetDisplayNameFromVehicleModel(GetEntityModel(veh))
local plate = GetVehicleNumberPlateText(veh)

With these values, you can accurately identify the vehicle for which the keys should be removed.


How to Use

To remove keys from a player, use the following code:

exports['qs-vehiclekeys']:RemoveKeys(plate, model)
  • plate: The license plate of the vehicle.

  • model: The model of the vehicle.


Example

Here’s an example of how to use the RemoveKeys export in a script:

RegisterCommand('removekeys', function(source)
    local vehicle = GetVehiclePedIsIn(GetPlayerPed(source), false)
    if not DoesEntityExist(vehicle) then
        print("No vehicle found.")
        return
    end

    -- Retrieve the model and plate of the vehicle
    local model = GetDisplayNameFromVehicleModel(GetEntityModel(vehicle))
    local plate = GetVehicleNumberPlateText(vehicle)

    -- Remove the keys
    exports['qs-vehiclekeys']:RemoveKeys(plate, model)
    print("Keys removed for vehicle with plate: " .. plate)
end, false)

This export provides an efficient way to manage vehicle access dynamically. Use it in scenarios such as player penalties, vehicle ownership adjustments, or administrative commands to maintain control over vehicle keys.

GetKey

The GetKey export allows you to check if a player has access to the keys of a specified vehicle. This is useful for verifying ownership or permissions before allowing certain vehicle-related actions.


How to Use

To check if the player has keys for a specific vehicle, use the following code:

local hasKey = exports['qs-vehiclekeys']:GetKey(plate)
if hasKey then
    print("The player has keys for the vehicle with plate: " .. plate)
else
    print("The player does not have keys for the vehicle with plate: " .. plate)
end

This example retrieves the key status for the given plate and determines if the player has the required access. Use this export to enhance vehicle security and player permissions in your scripts seamlessly.

GiveKeysAuto

The GiveKeysAuto export provides an automatic way to give the player keys for the vehicle they are currently inside. This is ideal for scenarios where the player is interacting with a vehicle directly, such as after purchasing or entering it.


How to Use

To grant keys for the vehicle the player is currently inside, use the following code:

exports['qs-vehiclekeys']:GiveKeysAuto()
print("Keys have been granted for the vehicle you are in.")

This export does not require specifying the vehicle's plate or model, as it automatically detects the vehicle the player is seated in. Use this export to streamline key assignment in your scripts for intuitive and efficient vehicle interactions.

RemoveKeysAuto

The RemoveKeysAuto export allows you to automatically remove the keys for the vehicle the player is currently inside. This is particularly useful in scenarios where key access needs to be revoked after certain events or interactions.


How to Use

To remove keys for the vehicle the player is currently in, use the following code:

exports['qs-vehiclekeys']:RemoveKeysAuto()
print("Keys have been removed for the vehicle you are in.")

This export automatically detects the vehicle the player is seated in and removes the keys without requiring additional parameters. Use this export to efficiently manage key removal in real-time gameplay situations.

GetKeyAuto

The GetKeyAuto export allows you to check if the player has keys for the vehicle they are currently inside. This is useful for determining access permissions in real-time gameplay scenarios.


How to Use

To check if the player has keys for the vehicle they are in, use the following code:

local hasKey = exports['qs-vehiclekeys']:GetKeyAuto()
if hasKey then
    print("Player has keys for the current vehicle.")
else
    print("Player does not have keys for the current vehicle.")
end

This export automatically identifies the vehicle the player is seated in and returns a boolean value (true or false) indicating whether the player has keys for it. Use this export to implement custom logic based on key ownership.

DoorLogic

The DoorLogic export provides advanced control over vehicle door locking and unlocking mechanics. This system includes various optional parameters to customize animations, notifications, sounds, and other effects.


How to Use

To apply door logic to a vehicle, use the following code:

local closestVehicle = GetClosestVehicle() -- Retrieve the nearest vehicle
if closestVehicle ~= 0 then
    exports["qs-vehiclekeys"]:DoorLogic(closestVehicle, false, 1, false, false, false)
    print("Door logic applied successfully.")
else
    print("No vehicle found.")
end

Example Parameters:

  • vehicle: The targeted vehicle entity.

  • skipAnimation: (Optional, default false) Skips the lock/unlock animation if true.

  • forcedDoorStatus: (Optional) Forces the door status (0 for None, 1 for Unlocked, 2 for Locked).

  • skipNotification: (Optional, default false) Prevents notifications from being displayed.

  • skipSound: (Optional, default false) Prevents the default vehicle door sounds.

  • skipFlickerLights: (Optional, default false) Prevents lights from flickering when toggling the lock state.


Example Usage

This example demonstrates applying DoorLogic to the closest vehicle:

function GetClosestVehicle()
    local playerPed = GetPlayerPed(-1)
    local pos = GetEntityCoords(playerPed)
    local vehicles = GetGamePool('CVehicle')
    local closestVehicle = 0
    local minDistance = -1

    for _, vehicle in ipairs(vehicles) do
        local distance = #(pos - GetEntityCoords(vehicle))

        if minDistance == -1 or distance < minDistance then
            minDistance = distance
            closestVehicle = vehicle
        end
    end

    return closestVehicle
end

local closestVehicle = GetClosestVehicle()
if closestVehicle ~= 0 then
    exports["qs-vehiclekeys"]:DoorLogic(closestVehicle, false, 2, true, false, true)
    print("DoorLogic applied: Doors locked, notifications displayed.")
else
    print("No vehicle found.")
end

This export allows flexible control over vehicle door states, enabling customized interaction within your scripts.

AddRentalPapers

The AddRentalPapers export enables adding rental papers to the player's inventory for a specific vehicle. This is useful for implementing rental systems or verifying vehicle ownership during rentals.


How to Use

To add rental papers to the player's inventory, use the following code:

local plate = "ABC123" -- The plate of the rented vehicle
local model = "Sultan" -- The model of the rented vehicle

exports["qs-vehiclekeys"]:AddRentalPapers(plate, model)
print("Rental papers added for vehicle: " .. plate .. " (" .. model .. ")")

This export requires two parameters:

  • plate: The license plate of the vehicle.

  • model: The model of the vehicle.


Example Usage

This example demonstrates how to add rental papers dynamically when renting a vehicle:

function RentVehicle(veh)
    local plate = GetVehicleNumberPlateText(veh) -- Get the plate of the vehicle
    local model = GetDisplayNameFromVehicleModel(GetEntityModel(veh)) -- Get the model of the vehicle
    
    -- Add rental papers for the vehicle
    exports["qs-vehiclekeys"]:AddRentalPapers(plate, model)
    
    print("Rental papers issued for: " .. plate .. " (" .. model .. ")")
end

-- Example of using the function
local rentedVehicle = GetVehiclePedIsIn(PlayerPedId(), false) -- Example vehicle
if rentedVehicle then
    RentVehicle(rentedVehicle)
else
    print("No vehicle to rent.")
end

This export integrates seamlessly into rental systems, enabling efficient tracking and management of rented vehicles.

RemoveRentalPapers

The RemoveRentalPapers export enables removing rental papers from the player's inventory for a specified vehicle. This is ideal for scenarios where a rental period ends or the vehicle is returned.


How to Use

To remove rental papers from the player's inventory, use the following code:

local plate = "ABC123" -- The plate of the rented vehicle
local model = "Sultan" -- The model of the rented vehicle

exports["qs-vehiclekeys"]:RemoveRentalPapers(plate, model)
print("Rental papers removed for vehicle: " .. plate .. " (" .. model .. ")")

This export requires two parameters:

  • plate: The license plate of the vehicle.

  • model: The model of the vehicle.


Example Usage

This example demonstrates how to remove rental papers when the rental period ends:

function ReturnVehicle(veh)
    local plate = GetVehicleNumberPlateText(veh) -- Get the plate of the vehicle
    local model = GetDisplayNameFromVehicleModel(GetEntityModel(veh)) -- Get the model of the vehicle
    
    -- Remove rental papers for the vehicle
    exports["qs-vehiclekeys"]:RemoveRentalPapers(plate, model)
    
    print("Rental papers removed for: " .. plate .. " (" .. model .. ")")
end

-- Example of using the function
local rentedVehicle = GetVehiclePedIsIn(PlayerPedId(), false) -- Example vehicle
if rentedVehicle then
    ReturnVehicle(rentedVehicle)
else
    print("No rented vehicle to return.")
end

This export integrates seamlessly into vehicle return workflows, ensuring rental papers are properly managed and removed when a rental concludes.

GetDoorState

The GetDoorState export retrieves the current door state of a specified vehicle, providing essential information for vehicle-related interactions or logic. The export returns an integer that corresponds to various door states.


Door State Values

The door state values and their meanings are as follows:

  • 0: None

  • 1: Unlocked

  • 2: Locked

  • 3: LockedForPlayer

  • 4: StickPlayerInside

  • 7: CanBeBrokenInto

  • 8: CanBeBrokenIntoPersist

  • 10: CannotBeTriedToEnter

  • Other values: Unknown Status


How to Use

To retrieve the door state of a vehicle, use the following code:

local vehicle = GetVehiclePedIsIn(PlayerPedId(), false) -- Get the current vehicle the player is in
if vehicle and vehicle ~= 0 then
    local doorState = exports["qs-vehiclekeys"]:GetDoorState(vehicle)
    print("Door State: " .. doorState)
else
    print("No vehicle found.")
end

This export takes the vehicle entity as a parameter and returns its door state.


Example Usage

This example checks the door state of the nearest vehicle and performs logic based on the state:

function CheckVehicleDoorState(veh)
    local doorState = exports["qs-vehiclekeys"]:GetDoorState(veh)

    if doorState == 1 then
        print("The vehicle is unlocked.")
    elseif doorState == 2 then
        print("The vehicle is locked.")
    elseif doorState == 7 then
        print("The vehicle can be broken into.")
    else
        print("Vehicle door state: " .. doorState)
    end
end

-- Example of using the function
local playerVehicle = GetVehiclePedIsIn(PlayerPedId(), false)
if playerVehicle and playerVehicle ~= 0 then
    CheckVehicleDoorState(playerVehicle)
else
    print("Player is not in a vehicle.")
end

This export is highly useful for managing vehicle interactions, security, and gameplay logic tied to door states.


Server Exports

This section provides all available server exports for the script. These functions allow developers to interact with the system from the server side, manage data, trigger actions, and integrate with other resources. Each export includes a clear description and a practical example to simplify its implementation.

The getHouseRoutingId export allows you to retrieve the Routing Bucket ID of a house instance. This is useful for checking if a specific house is currently active (someone is inside) or to manage instance-based logic inside houses.


How to Use

To get the routing ID of a house, use the following code:

local routingId = exports['qs-housing']:getHouseRoutingId('house')
if not routingId then
    print('Nobody is home!')
end

print('Routing ID:', routingId)

Here’s an example of a command that checks if a specific house is occupied:

RegisterCommand('checkhouserouting', function()
    local routingId = exports['qs-housing']:getHouseRoutingId('house')

    if not routingId then
        print('Result: Nobody is currently inside the house.')
    else
        print('Result: House is occupied. Routing ID:', routingId)
    end
end)

This example checks if the house identified by 'house' has an active routing bucket. If no one is inside (routingId is nil), it prints that nobody is home. If there is an active routing bucket, it prints the routingId, indicating the house is currently being used.

The housing:handleRentPayment event is triggered each time a rent payment is processed for a property. This allows external scripts to track rent-related activity or perform custom actions such as logging, rewards, or penalties.

Event Parameters

  • house: The name or ID of the house being rented.

  • identifier: The identifier (usually Steam or Rockstar ID) of the player making the payment.

  • payed: A boolean indicating if the rent was successfully paid (true) or not (false).


How to Use

To listen for rent payment events in your script, use the following pattern:

AddEventHandler('housing:handleRentPayment', function(house, identifier, payed)
    if payed then
        print(('[Rent Paid] Player %s has paid rent for house %s.'):format(identifier, house))
    else
        print(('[Rent Failed] Player %s failed to pay rent for house %s.'):format(identifier, house))
    end
end)

Here’s an example of how you could log all successful rent payments to a file:

AddEventHandler('housing:handleRentPayment', function(house, identifier, payed)
    if payed then
        local logMessage = os.date('[%Y-%m-%d %H:%M:%S]') ..
            (' Rent paid for %s by %s\n'):format(house, identifier)

        SaveResourceFile('my-logger', 'rent_logs.txt', logMessage, -1)
    end
end)

This code listens for rent payments and writes successful transactions to a text file for later review.

The housing:handleRentPayment event is triggered each time a rent payment is processed for a property. This allows external scripts to track rent-related activity or perform custom actions such as logging, rewards, or penalties.

Event Parameters

  • house: The name or ID of the house being rented.

  • identifier: The identifier (usually Steam or Rockstar ID) of the player making the payment.

  • payed: A boolean indicating if the rent was successfully paid (true) or not (false).


How to Use

To listen for rent payment events in your script, use the following pattern:

AddEventHandler('housing:handleRentPayment', function(house, identifier, payed)
    if payed then
        print(('[Rent Paid] Player %s has paid rent for house %s.'):format(identifier, house))
    else
        print(('[Rent Failed] Player %s failed to pay rent for house %s.'):format(identifier, house))
    end
end)

Here’s an example of how you could log all successful rent payments to a file:

AddEventHandler('housing:handleRentPayment', function(house, identifier, payed)
    if payed then
        local logMessage = os.date('[%Y-%m-%d %H:%M:%S]') ..
            (' Rent paid for %s by %s\n'):format(house, identifier)

        SaveResourceFile('my-logger', 'rent_logs.txt', logMessage, -1)
    end
end)

This code listens for rent payments and writes successful transactions to a text file for later review.