# 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")
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.boii.dev/old-docs/boii_utils/api/cooldowns.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
