Events
Note
These events are entirely optional and can be triggered as needed to integrate cd_garage with your own scripts or custom systems.
Client
Client-Side Events
- Defined with
RegisterNetEventin client files. - Triggered using
TriggerEvent(if from client) orTriggerClientEvent(if from server). - Run only on one player's game client (the player's PC).
Impound Vehicle
Opens the impound UI. You can send a vehicle's ID as the first argument; otherwise, it will automatically select the closest vehicle.
---@param vehicle number | entity The vehicle entity to be impounded.
---@example
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
TriggerEvent('cd_garage:ImpoundVehicle', vehicle)TriggerEvent('cd_garage:ImpoundVehicle', vehicle)TriggerClientEvent('cd_garage:ImpoundVehicle', source, vehicle)Impound Vehicle Directly
Impounds a vehicle directly using code without opening the impound UI. Sends detailed data such as the plate, impound location, vehicle properties, and retrieval status.
--- @field plate string The vehicle's plate.
--- @field impound number The Impound ID from Config.ImpoundLocations.
--- @field props table The vehicle's properties.
--- @field time number The time the vehicle was impounded.
--- @field description string The reason or description for the impound.
--- @field canretrive boolean Whether the vehicle can be retrieved by the owner.
--- @field vehicle number | entity The vehicle entity.TriggerEvent('cd_garage:ImpoundVehicle:Direct', {
plate = plate,
impound = impound,
props = props,
time = time,
description = description,
canretrive = canretrive,
vehicle = vehicle,
})TriggerClientEvent('cd_garage:ImpoundVehicle:Direct', source, {
plate = plate,
impound = impound,
props = props,
time = time,
description = description,
canretrive = canretrive,
vehicle = vehicle,
})Toggle Vehicle Lock
Toggles the lock state of the closest vehicle to the player.
TriggerEvent('cd_garage:ToggleVehicleLock')TriggerClientEvent('cd_garage:ToggleVehicleLock', source)Set Vehicle Locked
Locks a vehicle using the garage's built-in key system. You must send the vehicle's ID in the first argument.
--- @param vehicle number The vehicle entity to lock.
--- @example
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
TriggerEvent('cd_garage:SetVehicleLocked', vehicle)TriggerEvent('cd_garage:SetVehicleLocked', vehicle)TriggerClientEvent('cd_garage:SetVehicleLocked', source, vehicle)Set Vehicle Unlocked
Unlocks a vehicle using the garage's built-in key system. You must send the vehicle's ID in the first argument.
--- @param vehicle number The vehicle entity to unlock.
--- @example
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
TriggerEvent('cd_garage:SetVehicleUnlocked', vehicle)TriggerEvent('cd_garage:SetVehicleUnlocked', vehicle)TriggerClientEvent('cd_garage:SetVehicleUnlocked', source, vehicle)Update Garage Type
Updates the vehicle's garage type in the database based on your current vehicle.
TriggerEvent('cd_garage:UpdateGarageType')TriggerClientEvent('cd_garage:UpdateGarageType', source)Add Keys
Gives the player keys for a specific vehicle based on its plate.
-- @param plate string The vehicle's plate. Example: "ABCD1234"
--- @example
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
local plate = exports['cd_garage']:GetPlate(vehicle)
TriggerEvent('cd_garage:AddKeys', plate)TriggerEvent('cd_garage:AddKeys', plate)TriggerClientEvent('cd_garage:AddKeys', source, plate)Remove Keys
Removes the player's keys for a specific vehicle based on its plate.
-- @param plate string The vehicle's plate. Example: "ABCD1234"
--- @example
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
local plate = exports['cd_garage']:GetPlate(vehicle)
TriggerEvent('cd_garage:RemoveKeys', plate)TriggerEvent('cd_garage:RemoveKeys', plate)TriggerClientEvent('cd_garage:RemoveKeys', source, plate)Show Keys UI
Opens the vehicle keys UI for the player, displaying all vehicles they currently have keys for.
TriggerEvent('cd_garage:ShowKeys')TriggerClientEvent('cd_garage:ShowKeys', source)Server
Server-Side Events
- Defined with
RegisterServerEventandAddEventHandlerin server files. - Triggered using
TriggerEvent(if from server) orTriggerServerEvent(if from client). - Run on the server, not on any individual player's game client.
Set Job Owned Vehicle
Marks the vehicle the player is currently sitting in as either a personal or society owned job vehicle.
This event must be triggered while the player is inside the vehicle.
--- @param method string The ownership type: 'personal' or 'society'.
--- @param plate string The vehicle plate.
--- @param jobs table Optional. Only used for society owned vehicles to allow extra jobs access.
--- @example For personal owned vehicles:
local method = 'personal'
local plate = 'ABCD1234'
TriggerServerEvent('cd_garage:SetJobOwnedVehicle', method, plate)
--- @example For society owned vehicles:
local method = 'society'
local plate = 'ABCD1234'
local jobs = {
'police',
'sheriff'
}
TriggerServerEvent('cd_garage:SetJobOwnedVehicle', method, plate, jobs)TriggerServerEvent('cd_garage:SetJobOwnedVehicle', method, plate)TriggerEvent('cd_garage:SetJobOwnedVehicle', method, plate)Create Private Garage
Creates a private garage using code. This is mainly useful for property scripts that need to create a garage automatically.
--- @param data table The private garage data.
--- @param data.garage_label string The display name of the private garage.
--- @param data.allowed_vehicle_types table The vehicle types allowed in this garage. Example: 'car' 'boat' 'heli' 'plane'.
--- @param data.coords table The garage location data.
--- @param data.coords.open table The location where players open the garage.
--- @param data.coords.spawn table The location where vehicles spawn.
--- @param data.private_garage table Optional private garage owner and access data.
--- @param data.private_garage.owner_identifier string Optional main owner identifier.
--- @param data.private_garage.access_identifiers table Optional list of player identifiers allowed to access the garage.
--- @param data.blip table Optional blip settings.
--- @example
local ped = PlayerPedId()
local coords = GetEntityCoords(ped)
local heading = GetEntityHeading(ped)
local data = {
garage_label = 'New Private Garage',
allowed_vehicle_types = {'car'},
coords = {
open = {
x = coords.x,
y = coords.y,
z = coords.z,
interact_distance = 5,
view_distance = 15
},
spawn = {
x = coords.x,
y = coords.y,
z = coords.z,
heading = heading
}
},
private_garage = { -- optional
owner_identifier = 'steam:110000112345678',
access_identifiers = {
'steam:110000112345678',
'steam:110000112345679'
}
},
blip = { -- optional
enabled = true,
sprite = 357,
scale = 0.6,
color = 9
}
}
TriggerServerEvent('cd_garage:PrivateGarage:Create', data)TriggerServerEvent('cd_garage:PrivateGarage:Create', data)TriggerEvent('cd_garage:PrivateGarage:Create', data)Set Garage State
Updates the vehicle's in garage status in the database.
--- @param plate string The vehicle's license plate. Example: "ABCD1234"
--- @param state number The vehicle's garage state. 0 = not in garage, 1 = in garage, 2 = in impound.
--- @example
local plate = "ABCD1234"
local state = 1
TriggerEvent('cd_garage:SetGarageState', plate, state)TriggerEvent('cd_garage:SetGarageState', plate, state)Add Owned Keys
Used when adding an owned vehicle to a player's garage. This ensures the new vehicle appears in the player's keys UI.
--- @param plate string The vehicle's plate. Example: "ABCD1234"
--- @param model number The vehicle's model hash. Example: 127317925
--- @example
local plate = "ABCD1234"
local model = GetEntityModel(GetVehiclePedIsIn(PlayerPedId()))
TriggerServerEvent('cd_garage:VehicleKeys:AddOwnedKeys', plate, model)TriggerServerEvent('cd_garage:VehicleKeys:AddOwnedKeys', plate, model)TriggerEvent('cd_garage:VehicleKeys:AddOwnedKeys', plate, model, src)Add Persistent Vehicle
Used to mark a vehicle as persistent, allowing it to automatically save and respawn if it despawns while the server is running.
--- @param plate string The vehicle's plate. Example: "ABCD1234"
--- @param netId number The vehicle's network ID. Example: NetworkGetNetworkIdFromEntity(vehicle)
--- @example
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
local plate = exports['cd_garage']:GetPlate(vehicle)
local netId = NetworkGetNetworkIdFromEntity(vehicle)
TriggerServerEvent('cd_garage:PersistentVehicles:Add', plate, netId)TriggerServerEvent('cd_garage:PersistentVehicles:Add', plate, netId)TriggerEvent('cd_garage:PersistentVehicles:Add', plate, netId)Remove Persistent Vehicle
Used to remove a vehicle from the persistent system, preventing it from saving or respawning automatically.
--- @param plate string The vehicle's plate. Example: "ABCD1234"
--- @example
local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
local plate = exports['cd_garage']:GetPlate(vehicle)
TriggerServerEvent('cd_garage:PersistentVehicles:Remove', plate)TriggerServerEvent('cd_garage:PersistentVehicles:Remove', plate)TriggerEvent('cd_garage:PersistentVehicles:Remove', plate)Persistent Vehicle Plate Changed
When a vehicle's plate is changed while persistent vehicles are enabled, the old plate must be removed from the persistent system. This prevents the vehicle from being saved or respawning using its previous plate.
--- @param old_plate string The vehicle's old plate. Example: "ABCD1234"
--- @param new_plate string The vehicle's new plate. Example: "1234ABCD"
--- @example
local old_plate = exports['cd_garage']:GetCorrectPlateFormat("ABCD1234")
local new_plate = exports['cd_garage']:GetCorrectPlateFormat("1234ABCD")
TriggerServerEvent('cd_garage:PersistentVehicles:PlateChanged', old_plate, new_plate)TriggerServerEvent('cd_garage:PersistentVehicles:PlateChanged', old_plate, new_plate)TriggerEvent('cd_garage:PersistentVehicles:PlateChanged', old_plate, new_plate)Transfer Vehicle
Transfers a vehicle to another players garage.
--- @param plate string The plate of the vehicle to transfer.
--- @param serverid number The server ID of the player to transfer the vehicle to.
--- @example
local plate = 'ABCD1234'
local serverId = 23
TriggerServerEvent('cd_garage:TransferVehicle', plate, serverId)TriggerEvent('cd_garage:TransferVehicle', plate, serverid)TriggerEvent('cd_garage:TransferVehicle', plate, serverid)Save Vehicle Damage Timer
Saves the damage data for all vehicles currently tracked by cd_garage. Typically used before a server restart.
TriggerClientEvent('cd_garage:SaveAllVehicleDamage', -1)Save Impound Timer
Saves all active impound timers to the database, ensuring impounded vehicle durations are correctly updated and persistent.
TriggerEvent('cd_garage:SaveImpoundTimers')