# Cooldowns

The **Cooldowns module** provides a **standalone** system to handle **player, global, and resource-based cooldowns**. This ensures actions have enforced delays between executions.

## Server

### add\_cooldown(source, cooldown\_type, duration, is\_global)

Adds a cooldown for a player, globally, or for a specific resource.

#### Parameters:

* **source** *(number)* - The player's server ID (or identifier for non-global cooldowns).
* **cooldown\_type** *(string)* - The cooldown category (e.g., "begging").
* **duration** *(number)* - Duration of the cooldown in **seconds**.
* **is\_global** *(boolean)* - `true` for global cooldown, `false` for player-specific cooldown.

#### Example

```lua
local COOLDOWNS = exports.boii_utils:get("modules.cooldowns")
COOLDOWNS.add(1, "begging", 60, false) -- Adds a 60s cooldown for player 1
```

***

### check\_cooldown(source, cooldown\_type, is\_global)

Checks if a cooldown is active for a player or globally.

#### Parameters:

* **source** *(number)* - The player's server ID.
* **cooldown\_type** *(string)* - The cooldown category.
* **is\_global** *(boolean)* - `true` for global cooldown, `false` for player-specific cooldown.

#### Returns:

* *(boolean)* - `true` if cooldown is active, `false` otherwise.

#### Example

```lua
if COOLDOWNS.check(1, "begging", false) then
    print("Player is on cooldown.")
end
```

***

### clear\_cooldown(source, cooldown\_type, is\_global)

Clears an active cooldown for a player or globally.

#### Parameters:

* **source** *(number)* - The player's server ID.
* **cooldown\_type** *(string)* - The cooldown category.
* **is\_global** *(boolean)* - `true` for global cooldown, `false` for player-specific cooldown.

#### Example

```lua
COOLDOWNS.clear(1, "begging", false) -- Removes cooldown for player 1
```

***

### clear\_expired\_cooldowns()

Removes all expired cooldowns automatically.

#### Example

```lua
COOLDOWNS.clear_expired_cooldowns()
```

***

### clear\_resource\_cooldowns(resource\_name)

Clears all cooldowns set by a specific resource.

#### Parameters:

* **resource\_name** *(string)* - The name of the resource.

#### Example

```lua
COOLDOWNS.clear_resource_cooldowns("some_resource")
```
