Skip to content

Exports & events

Public API of Cuxial Garages: exports for keys, house garages, impound and vehicle cleanup.

Give and check vehicle keys, open a house garage, impound a vehicle or start a cleanup from your own resources. Resources written for qbx_vehiclekeys need no changes.

The key exports exist only with enabled = true in data/keys.lua, and the cleanup exports only with enabled = true in data/carwipe.lua.

Server exports ​

GiveKeys ​

Gives a player the key of a plate. Does nothing if the player already has it.

lua
exports.cuxial_garages:GiveKeys(source, plate)
ParameterTypeDescription
sourcenumberServer id of the player.
platestringPlate of the vehicle. Spaces around it are ignored and it is upper-cased.

Returns: boolean. true when the player ends up with the key.

lua
exports.cuxial_garages:GiveKeys(source, 'ABC12345')

HasKeys ​

Tells whether a player carries the key of a plate.

lua
local has = exports.cuxial_garages:HasKeys(source, plate)
ParameterTypeDescription
sourcenumberServer id of the player.
platestringPlate of the vehicle.

Returns: boolean.

lua
if not exports.cuxial_garages:HasKeys(source, plate) then return end

RemoveKeys ​

Removes every key of that plate from the player's inventory.

lua
exports.cuxial_garages:RemoveKeys(source, plate)
ParameterTypeDescription
sourcenumberServer id of the player.
platestringPlate of the vehicle.

Returns: boolean. true when at least one key was removed.

lua
exports.cuxial_garages:RemoveKeys(source, plate)

ImpoundStoredVehicle ​

Sends a vehicle to the impound from its database id, without an officer. Made for vehicles that are stored: it does not remove a vehicle that is out in the world.

lua
local result = exports.cuxial_garages:ImpoundStoredVehicle(data)
ParameterTypeDescription
data.idnumberId of the vehicle in the vehicle table. Required.
data.costnumberFee to retrieve it. Defaults to defaultPrice from data/impound.lua.
data.reasonstringReason shown to the owner. Up to 255 characters.
data.sentBystringName shown as the person who impounded it. Up to 100 characters.
data.jobstringJob recorded as the origin of the impound.
data.depotstringId of the depot that holds it. Without it, the vehicle can be retrieved at any depot.
data.fromStatenumberState the vehicle must be in. Defaults to stored (1).

Returns: table. On success { ok = true, cost, depot, depotLabel }. On failure { ok = false, reason }, where reason is 'bad_request', 'no_vehicle' or 'not_stored'.

lua
local result = exports.cuxial_garages:ImpoundStoredVehicle({
    id = vehicleId,
    cost = 2500,
    reason = 'Seized by court order',
    sentBy = 'Department of Justice',
    job = 'police',
})
if result.ok then print('Impounded for $' .. result.cost) end

GetVehicleMdtInfo ​

Returns the nickname and the impound record of a plate. Made for police tablets.

lua
local info = exports.cuxial_garages:GetVehicleMdtInfo(plate)
ParameterTypeDescription
platestringPlate of an owned vehicle.

Returns: table or nil when the plate has no owner.

FieldTypeDescription
nicknamestring | nilNickname set by the owner.
impoundtable | nilnil when the vehicle is not impounded. Otherwise depot, cost, reason, selfRetrievable, sentBy, authorizedBy and date (Unix time).
lua
local info = exports.cuxial_garages:GetVehicleMdtInfo('ABC12345')
if info and info.impound then
    print(('Impounded by %s: %s'):format(info.impound.sentBy, info.impound.reason or '-'))
end

StartCarWipe ​

Starts a vehicle cleanup after a countdown shown to every player.

lua
local ok, message = exports.cuxial_garages:StartCarWipe(seconds)
ParameterTypeDescription
secondsnumberCountdown in seconds. Optional; countdown from data/carwipe.lua by default.

Returns: boolean, string. false when a cleanup is already in progress. The string is the message to show.

lua
local ok, message = exports.cuxial_garages:StartCarWipe(90)
print(message)

CancelCarWipe ​

Cancels the cleanup in progress.

lua
local ok, message = exports.cuxial_garages:CancelCarWipe()

Returns: boolean, string. false when no cleanup is in progress.

IsWipeInProgress ​

Tells whether a cleanup countdown is running.

lua
local running = exports.cuxial_garages:IsWipeInProgress()

Returns: boolean.

Client exports ​

GiveKeys ​

Asks the server for the key of a plate for the local player. The server only grants it when the player owns the vehicle or the plate has no owner.

lua
exports.cuxial_garages:GiveKeys(plate, vehicleEntity)
ParameterTypeDescription
platestringPlate of the vehicle.
vehicleEntitynumberVehicle handle. Optional. When given, the player can use that vehicle at once, without waiting for the item. Use it for vehicles you spawn yourself, such as test drives.
lua
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
exports.cuxial_garages:GiveKeys(GetVehicleNumberPlateText(vehicle), vehicle)

HasKeys ​

Tells whether the local player carries the key of a plate. It asks the server, so call it from a thread.

lua
local has = exports.cuxial_garages:HasKeys(plate)

Returns: boolean.

RemoveKeys ​

Removes the key of a plate from the local player.

lua
exports.cuxial_garages:RemoveKeys(plate)

IsVehicleAccessible ​

Tells whether the local player can use a vehicle: with its key, or through the shared keys of their job. It asks the server, so call it from a thread.

lua
local allowed = exports.cuxial_garages:IsVehicleAccessible(vehicle)
ParameterTypeDescription
vehiclenumberVehicle handle.

Returns: boolean.

lua
if not exports.cuxial_garages:IsVehicleAccessible(cache.vehicle) then return end

OpenGarage ​

Opens a house garage at a position given by your housing resource. The garage is not saved in the database and draws no marker: your resource handles the interaction point.

lua
exports.cuxial_garages:OpenGarage(id, opts)
ParameterTypeDescription
idstringUnique id of the garage, up to 64 characters. Vehicles stored there stay tied to this id.
opts.coordsvector4Access position, also used as the parking spot when no spawns are given. Required.
opts.categorystring'car', 'motorcycle', 'air' or 'sea'. Optional; all categories by default.
opts.labelstringName shown in the interface. Optional, up to 48 characters.
opts.capacitynumberVehicles per player, from 1 to 100. Optional. Applied only with capacity.enabled = true.
opts.spawnstable[]Parking spots as { x, y, z, h }. Optional, up to 16, each within 30 metres of coords.
lua
exports.cuxial_garages:OpenGarage('house:' .. property.id, {
    coords = vector4(x, y, z, heading),
    category = 'car',
    label = 'Home garage',
    capacity = 4,
})

StoreVehicle ​

Stores the vehicle the local player is driving in a house garage. Does nothing if the player is not the driver.

lua
exports.cuxial_garages:StoreVehicle(id, opts)
ParameterTypeDescription
idstringId of the garage, the same one used with OpenGarage.
optstableOptional. Same fields as OpenGarage. Without coords, the player's position is used.
lua
exports.cuxial_garages:StoreVehicle('house:' .. property.id, { category = 'car' })

OpenGarage and StoreVehicle only work with externalGarages = true in shared/config.lua. The server also checks that the player is within interactDistance (8 metres by default) of coords, and accepts up to 25 house garages per player and session.

OpenImpound ​

Opens the impound form for the vehicle nearest to the local player, as /impound does. The player still needs an impound job.

lua
exports.cuxial_garages:OpenImpound()

qbx_vehiclekeys compatibility ​

Cuxial Garages answers these calls under the qbx_vehiclekeys name, so resources that use them keep working:

CallBehaviour
exports.qbx_vehiclekeys:GiveKeys(source, vehicle)Server. vehicle is a vehicle handle or a plate.
exports.qbx_vehiclekeys:HasKeys(source, plate)Server. Same as HasKeys above.
exports.qbx_vehiclekeys:RemoveKeys(source, plate)Server. Same as RemoveKeys above.
lib.callback('qbx_vehiclekeys:server:giveKeys', false, cb, netId)Called from the client. Grants the key of that vehicle when the player owns it or it has no owner.
lua
exports.qbx_vehiclekeys:GiveKeys(source, vehicle)

State bags ​

State bagOnMeaning
vehicleidVehicleDatabase id of an owned vehicle delivered by a garage. Vehicles without it count as not owned.
doorslockstateVehicleDoor lock state set by the key system. Above 1 = locked.
ignoreLocksVehicleSet it to true from your resource to keep a vehicle out of the lock system.
rentalcodeVehicleTicket code of a rented vehicle.
lua
Entity(vehicle).state:set('ignoreLocks', true, true)

Events ​

Cuxial Garages triggers these server events locally, with TriggerEvent, so any server resource can listen to them with AddEventHandler.

EventParametersWhen
cuxial_garages:server:VehicleSpawnedveh, vehicleId, plateA vehicle leaves a garage, an impound, a job fleet or a rental.
cuxial_garages:server:VehicleDeletedid, plateStaff delete a vehicle from the admin panel.
cuxial_garages:server:VehicleTransferredid, plate, newCitizenIdA vehicle is transferred to another player.
cuxial_garages:server:PlateChangedveh, oldPlate, newPlateA vehicle plate changes while keys are handed over.
lua
AddEventHandler('cuxial_garages:server:VehicleSpawned', function(veh, vehicleId, plate)
    -- veh is the vehicle entity; vehicleId is its database id
end)

Custom integrations ​

Three options point to a resource by name. To use your own resource instead of the default, it must provide these server exports:

OptionExports your resource must provide
dispatch.resource in data/keys.luaSendDispatchAlert(data)
license.resource in data/rental.luaGetAvailableCards() returns a list of { type, label }. GetPlayerLicenses(citizenid) returns a list of { type }.
finance.resource in shared/config.luagetPlayerFinancedVehicles(citizenid), getFinanceByPlate(plate) and makeFinancePayment(source, plate)

The theft alert sent to SendDispatchAlert:

lua
{
    title = 'Vehicle theft',      -- translated text
    type = 'vehicle',
    code = '10-72',
    coords = { x = 0.0, y = 0.0, z = 0.0 },
    vehicle = { plate = 'ABC12345' },
    central = true,
}

© Cuxial