# Events

{% content-ref url="chat-commands" %}
[chat-commands](https://docs.codesign.pro/paid-scripts/garage/developer-api/chat-commands)
{% endcontent-ref %}

{% content-ref url="events" %}
[events](https://docs.codesign.pro/paid-scripts/garage/developer-api/events)
{% endcontent-ref %}

{% content-ref url="exports" %}
[exports](https://docs.codesign.pro/paid-scripts/garage/developer-api/exports)
{% endcontent-ref %}

{% content-ref url="keys" %}
[keys](https://docs.codesign.pro/paid-scripts/garage/developer-api/keys)
{% endcontent-ref %}

{% content-ref url="items" %}
[items](https://docs.codesign.pro/paid-scripts/garage/developer-api/items)
{% endcontent-ref %}

***

{% hint style="info" %}

#### **Note**

These events are entirely optional and can be triggered as needed to integrate cd\_garage with your own scripts or custom systems.
{% endhint %}

***

## Client

{% hint style="success" %}

#### **Client-Side Events**

* Defined with **`RegisterNetEvent`** **in client files**.
* Triggered using **`TriggerEvent`** (if from client) or **`TriggerClientEvent`** (if from server).
* Run only on **one player’s game client** (the player’s PC).
  {% endhint %}

### **Mileage**

Sends a notification displaying the mileage of the vehicle you are in.

{% code title="client-side to client-side" %}

```lua
TriggerEvent('cd_garage:checkmileage')
```

{% endcode %}

{% code title="server-side to client-side" %}

```lua
TriggerClientEvent('cd_garage:checkmileage', source)
```

{% endcode %}

***

### **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.

{% code title="@parameters" %}

```lua
---@param vehicle number | entity The vehicle entity to be impounded.
---@example
--- local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
```

{% endcode %}

{% code title="client-side to client-side" %}

```lua
TriggerEvent('cd_garage:ImpoundVehicle', vehicle)
```

{% endcode %}

{% code title="server-side to client-side" %}

```lua
TriggerClientEvent('cd_garage:ImpoundVehicle', source, vehicle)
```

{% endcode %}

***

### **Transfer Vehicle**

Transfers the vehicle you are currently sitting in to another player.

{% code title="@parameters" %}

```lua
--- @param serverid number The server ID of the player to transfer the vehicle to.
--- @example
--- local serverid = 23
```

{% endcode %}

{% code title="client-side to client-side" %}

```lua
TriggerEvent('cd_garage:TransferVehicle', serverid)
```

{% endcode %}

***

### **Toggle Vehicle Lock**

Toggles the lock state of the closest vehicle to the player.

{% code title="client-side to client-side" %}

```lua
TriggerEvent('cd_garage:ToggleVehicleLock')
```

{% endcode %}

{% code title="server-side to client-side" %}

```lua
TriggerClientEvent('cd_garage:ToggleVehicleLock', source)
```

{% endcode %}

***

### **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.

{% code title="@parameters" %}

```lua
--- @param vehicle number | entity The vehicle entity to lock.
--- @example
--- local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
```

{% endcode %}

{% code title="client-side to client-side" %}

```lua
TriggerEvent('cd_garage:SetVehicleLocked', vehicle)
```

{% endcode %}

{% code title="server-side to client-side" %}

```lua
TriggerClientEvent('cd_garage:SetVehicleLocked', source, vehicle)
```

{% endcode %}

***

### **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.

{% code title="@parameters" %}

```lua
--- @param vehicle number | entity The vehicle entity to unlock.
--- @example
--- local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
```

{% endcode %}

{% code title="client-side to client-side" %}

```lua
TriggerEvent('cd_garage:SetVehicleUnlocked', vehicle)
```

{% endcode %}

{% code title="server-side to client-side" %}

```lua
TriggerClientEvent('cd_garage:SetVehicleUnlocked', source, vehicle)
```

{% endcode %}

***

### **Update Garage Type**

Updates the vehicle’s garage type in the database based on your current vehicle.

{% code title="client-side to client-side" %}

```lua
TriggerEvent('cd_garage:UpdateGarageType')
```

{% endcode %}

{% code title="server-side to client-side" %}

```lua
TriggerClientEvent('cd_garage:UpdateGarageType', source)
```

{% endcode %}

***

### **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.

{% code title="@parameters" %}

```lua
--- @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.
```

{% endcode %}

{% code title="client-side to client-side" %}

```lua
TriggerEvent('cd_garage:ImpoundVehicle:Direct', {
    plate = plate,
    impound = impound,
    props = props,
    time = time,
    description = description,
    canretrive = canretrive,
    vehicle = vehicle,
})
```

{% endcode %}

{% code title="server-side to client-side" %}

```lua
TriggerClientEvent('cd_garage:ImpoundVehicle:Direct', source, {
    plate = plate,
    impound = impound,
    props = props,
    time = time,
    description = description,
    canretrive = canretrive,
    vehicle = vehicle,
})
```

{% endcode %}

***

### **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**.

{% code title="@parameters" %}

```lua
--- @param type string The ownership type: 'personal' or 'society'.
--- @@example
--- local type = 'personal'
```

{% endcode %}

{% code title="client-side to client-side" %}

```lua
TriggerEvent('cd_garage:SetJobOwnedVehicle', type)
```

{% endcode %}

{% code title="server-side to client-side" %}

```lua
TriggerClientEvent('cd_garage:SetJobOwnedVehicle', source, type)
```

{% endcode %}

### **Open Property Garage**

Opens the garage UI from a property script.

{% code title="@parameters" %}

```lua
--- @param type string The garage type: 'quick' or 'inside'.
--- @param shell string | nil The shell type: can be nil, '10cargarage_shell', or '40cargarage_shell'.
--- @example
--- local type = 'quick'
--- local shell = nil
```

{% endcode %}

{% code title="client-side to client-side" %}

```lua
TriggerEvent('cd_garage:PropertyGarage', 'quick', nil)
```

{% endcode %}

{% code title="server-side to client-side" %}

```lua
TriggerClientEvent('cd_garage:PropertyGarage', source, 'quick', nil)
```

{% endcode %}

### **Store Vehicle Property Garage**

Stores the player's vehicle from a property script.

{% code title="@parameters" %}

```lua
--- The arguments below must remain exactly as shown (1, false, false) and cannot be changed.
```

{% endcode %}

{% code title="client-side to client-side" %}

```lua
TriggerEvent('cd_garage:StoreVehicle_Main', 1, false, false)
```

{% endcode %}

{% code title="server-side to client-side" %}

```lua
TriggerClientEvent('cd_garage:StoreVehicle_Main', source, 1, false, false)
```

{% endcode %}

***

### **Add Keys**

Gives the player keys for a specific vehicle based on its plate.

{% code title="@parameters" %}

```lua
-- @param plate string The vehicle’s plate. Example: "ABCD1234"
--- @example
--- local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
--- local plate = exports['cd_garage']:GetPlate(vehicle)
```

{% endcode %}

{% code title="client-side to client-side" %}

```lua
TriggerEvent('cd_garage:AddKeys', plate)
```

{% endcode %}

{% code title="server-side to client-side" %}

```lua
TriggerClientEvent('cd_garage:AddKeys', source, plate)
```

{% endcode %}

***

### **Remove Keys**

Removes the player's keys for a specific vehicle based on its plate.

{% code title="@parameters" %}

```lua
-- @param plate string The vehicle’s plate. Example: "ABCD1234"
--- @example
--- local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
--- local plate = exports['cd_garage']:GetPlate(vehicle)
```

{% endcode %}

{% code title="client-side to client-side" %}

```lua
TriggerEvent('cd_garage:RemoveKeys', plate)
```

{% endcode %}

{% code title="server-side to client-side" %}

```lua
TriggerClientEvent('cd_garage:RemoveKeys', source, plate)
```

{% endcode %}

***

### **Show Keys UI**

Opens the vehicle keys UI for the player, displaying all vehicles they currently have keys for.

{% code title="client-side to client-side" %}

```lua
TriggerEvent('cd_garage:ShowKeys')
```

{% endcode %}

{% code title="server-side to client-side" %}

```lua
TriggerClientEvent('cd_garage:ShowKeys', source)
```

{% endcode %}

##

***

## Server

{% hint style="success" %}

#### **Server-Side Events**

* Defined with **`RegisterServerEvent`** and **`AddEventHandler`** **in server files**.
* Triggered using **`TriggerEvent`** (if from server) or **`TriggerServerEvent`** (if from client).
* Run on the **server**, not on any individual player’s game client.
  {% endhint %}

### **Save Mileage Timer**

Saves the mileage data for all vehicles currently tracked by cd\_garage. Typically used before a server restart.

{% code title="server-side to client-side" %}

```lua
TriggerClientEvent('cd_garage:SaveAllMiles', -1)
```

{% endcode %}

***

### **Save Vehicle Damage Timer**

Saves the damage data for all vehicles currently tracked by cd\_garage. Typically used before a server restart.

{% code title="server-side to client-side" %}

```lua
TriggerClientEvent('cd_garage:SaveAllVehicleDamage', -1)
```

{% endcode %}

***

### **Save Impound Timer**

Saves all active impound timers to the database, ensuring impounded vehicle durations are correctly updated and persistent.

{% code title="server-side to server-side" %}

```lua
TriggerEvent('cd_garage:SaveImpoundTimers')
```

{% endcode %}

***

### **Set Garage State**

Updates the vehicle’s “in garage” status in the database.

{% code title="@parameters" %}

```lua
--- @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.
--- @example
--- local plate = "ABCD1234"
--- local state = 1
```

{% endcode %}

{% code title="server-side to server-side" %}

```lua
TriggerEvent('cd_garage:SetGarageState', plate, state)
```

{% endcode %}

***

### 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.

{% code title="@parameters" %}

```lua
--- @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()))
```

{% endcode %}

{% code title="client-side to server-side" %}

```lua
TriggerServerEvent('cd_garage:AddKeysOwnedVehicle', plate, model)
```

{% endcode %}

{% code title="server-side to server-side" %}

```lua
TriggerEvent('cd_garage:AddKeysOwnedVehicle', plate, model, src)
```

{% endcode %}

***

### 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.

{% code title="@parameters" %}

```lua
--- @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)
```

{% endcode %}

{% code title="client-side to server-side" %}

```lua
TriggerServerEvent('cd_garage:AddPersistentVehicles', plate, netId)
```

{% endcode %}

{% code title="server-side to server-side" %}

```lua
TriggerEvent('cd_garage:AddPersistentVehicles', plate, netId)
```

{% endcode %}

***

### Remove Persistent Vehicle

Used to remove a vehicle from the persistent system, preventing it from saving or respawning automatically.

{% code title="@parameters" %}

```lua
--- @param plate string The vehicle’s plate. Example: "ABCD1234"
--- @example
--- local vehicle = GetVehiclePedIsIn(PlayerPedId(), false)
--- local plate = exports['cd_garage']:GetPlate(vehicle)
```

{% endcode %}

{% code title="client-side to server-side" %}

```lua
TriggerServerEvent('cd_garage:RemovePersistentVehicles', plate)
```

{% endcode %}

{% code title="server-side to server-side" %}

```lua
TriggerEvent('cd_garage:RemovePersistentVehicles', plate)
```

{% endcode %}

***

### Plate Changed Persistent Vehicle

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.

{% code title="@parameters" %}

```lua
--- @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")
```

{% endcode %}

{% code title="client-side to server-side" %}

```lua
TriggerServerEvent('cd_garage:PlateChangedPersistentVehicles', old_plate, new_plate)
```

{% endcode %}

{% code title="server-side to server-side" %}

```lua
TriggerEvent('cd_garage:PlateChangedPersistentVehicles', old_plate, new_plate)
```

{% endcode %}
