# Events

{% 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 %}

### Set Door State (Closest)

Sets the lock state of the closest door. The first argument **state** determines whether the door is locked (`true`) or unlocked (`false`).

{% code title="@parameters" %}

```lua
---@param state boolean Determines the door state (true = locked, false = unlocked).

---@example
local state = true
```

{% endcode %}

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

```lua
TriggerEvent('cd_doorlock:SetDoorState_closest', state)
```

{% endcode %}

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

```lua
TriggerClientEvent('cd_doorlock:SetDoorState_closest', source, state)
```

{% endcode %}

***

### Set Door State (By Name)

Sets the lock state of a specific door by name. The first argument **state** determines whether the door becomes locked (`true`) or unlocked (`false`). The second and third arguments specify the door’s **name** and **location group**.

{% code title="@parameters" %}

```lua
---@param state boolean Determines the door state (true = locked, false = unlocked).
---@param doorName string The unique name of the door.
---@param locationGroup string The building’s location group.

---@example
local state = true
local doorName = 'Main Enterance'
local locationGroup = 'MRPD'
```

{% endcode %}

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

```lua
TriggerEvent('cd_doorlock:SetDoorState_name', state, doorName, locationGroup)
```

{% endcode %}

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

```lua
TriggerClientEvent('cd_doorlock:SetDoorState_name', source, state, doorName, locationGroup)
```

{% endcode %}

***

### Set Door State (By Unique ID)

Sets the lock state of a specific door using its unique ID. The first argument **state** determines whether the door becomes locked (`true`) or unlocked (`false`). The second argument is the door’s **unique ID**.

{% code title="@parameters" %}

```lua
---@param state boolean Determines the door state (true = locked, false = unlocked).
---@param uniqueID string The unique ID assigned to the door.

---@example
local state = true
local uniqueID = "1234-5678"
```

{% endcode %}

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

```lua
TriggerEvent('cd_doorlock:SetDoorState_uniqueid', state, uniqueID)
```

{% endcode %}

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

```lua
TriggerClientEvent('cd_doorlock:SetDoorState_uniqueid', source, state, uniqueID)
```

{% 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 %}

### Lockdown Building

The first argument **state** sets the lockdown status (`true` = lock all doors, `false` = unlock all doors).\
The second argument defines the **location group** of the building.\
All players inside the defined building will receive a lockdown notification.

{% code title="@parameters" %}

```lua
---@param state boolean Lockdown state (true = lock, false = unlock).
---@param locationGroup string The building’s location group.

---@example
local locationGroup = 'MRPD'
local state = true
```

{% endcode %}

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

```lua
TriggerServerEvent('cd_doorlock:LockdownBuilding', locationGroup , state)
```

{% endcode %}

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

```lua
TriggerEvent('cd_doorlock:SetDoorState_uniqueid', locationGroup , state)
```

{% endcode %}

***

### Set Door Permissions (By Unique ID)

Sets the permission data for a specific door using its unique ID.\
You can set **all permission types** or **only specific ones**.\
When setting only certain permissions, leave the others **nil**, and they will simply not have any permissions assigned.\
The second argument **perms** is a table defining who can access the door.

<pre class="language-lua" data-title="@parameters"><code class="lang-lua">---@param uniqueId string The door’s unique ID.
---@param perms table Permission settings for the door.

---@example
<strong>local uniqueId = 12
</strong>local perms = {
     job = { 
          {name = 'police', grade = 0},
          {name = 'ems', grade = 0}
     },
     identifier = { 'steam:11000010abcd123' },
     ace = { 'admin' },
     discord = { '123456789012345678' },
     items = {
          name = 'keycard',
          amount = 1,
          destroy = false
     }
 }
--- OR
local perms = {
     job = { 
          {name = 'police', grade = 0},
          {name = 'ems', grade = 0}
     }
}
</code></pre>

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

```lua
TriggerServerEvent('cd_doorlock:SetDoorPerms', uniqueId, perms)
```

{% endcode %}

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

```lua
TriggerEvent('cd_doorlock:SetDoorPerms', uniqueId, perms)
```

{% endcode %}

***

### Add Door Permissions (By Unique ID)

Adds new permission data to a specific door using its unique ID.\
The **perms** table is merged into the door's existing permissions instead of replacing them.\
You can add **one or many** permission types.\
Any permission type you leave **nil** will simply not be added.

{% code title="@parameters" %}

```lua
---@param uniqueId string The door’s unique ID.
---@param perms table Permission data to add to the door.

---@example
local uniqueId = 12
local perms = {
     identifier = { 'steam:11000010abcd123' },
     items = {
          name = 'keycard',
          amount = 1,
          destroy = false
     }
 }
--- OR
 local perms = {
     job = { 
          {name = 'police', grade = 0},
          {name = 'ems', grade = 0}
     }
}
```

{% endcode %}

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

```lua
TriggerServerEvent('cd_doorlock:AddDoorPerms', uniqueId, perms)
```

{% endcode %}

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

```lua
TriggerEvent('cd_doorlock:AddDoorPerms', uniqueId, perms)
```

{% endcode %}
