> For the complete documentation index, see [llms.txt](https://docs.watari-dev.com/watari-dev-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.watari-dev.com/watari-dev-docs/watari_cooldown/how-to-use.md).

# how to use

Basic Example (Client.lua)

```lua
local QBCore = exports['qb-core']:GetCoreObject()

Config = Config or {}
Config.Crime          = 'robbery:fleeca' -- any unique string key (ex: 'store:24', 'vangelico:main')
Config.CooldownTimer  = 120 -- minutes

local function Notify(msg, ntype)
    if GetResourceState('ox_lib') == 'started' and lib and lib.notify then
        lib.notify({ description = msg, type = ntype or 'inform' })
    else
        QBCore.Functions.Notify(msg, ntype or 'primary')
    end
end

-- Your heist start function (adjust to match your script)
local function StartHeist()
    -- Start your heist logic here
end

-- Option A: ox_lib callback (recommended)
CreateThread(function()
    local ready, remainingMin = lib.callback.await('watari_cooldown:check', false, Config.Crime)

    if ready then
        StartHeist()
        exports['watari_cooldown']:setCrimeCooldown(Config.Crime, Config.CooldownTimer)
        Notify('Cooldown has been initiated', 'success')
    else
        Notify(('Cooldown is active, ends in %s minutes'):format(tostring(remainingMin)), 'error')
    end
end)

-- Option B: client export (same result)
-- CreateThread(function()
--     local ready, remainingMin = exports['watari_cooldown']:isCooldownReady(Config.Crime)
--     if ready then
--         StartHeist()
--         exports['watari_cooldown']:setCrimeCooldown(Config.Crime, Config.CooldownTimer)
--         Notify('Cooldown has been initiated', 'success')
--     else
--         Notify(('Cooldown is active, ends in %s minutes'):format(tostring(remainingMin)), 'error')
--     end
-- end)
```

Server-side Example (Server.lua)

```
local function StartHeistServerLogic(src)
    -- your server-side start logic here
end

RegisterNetEvent('your_heist:server:tryStart', function()
    local src = source
    local crime = 'robbery:fleeca'
    local cooldownMin = 120

    local ready, remainingMin = exports['watari_cooldown']:IsReady(crime)
    if not ready then
        TriggerClientEvent('QBCore:Notify', src, ('Cooldown active (%s min left)'):format(tostring(remainingMin)), 'error')
        return
    end

    StartHeistServerLogic(src)
    exports['watari_cooldown']:Set(crime, cooldownMin)
    TriggerClientEvent('QBCore:Notify', src, 'Cooldown has been initiated', 'success')
end)
```

## API Reference (Quick)

### Client Exports

* `exports['watari_cooldown']:isCooldownReady(crime)` -> `(ready:boolean, remainingMin:number)`
* `exports['watari_cooldown']:setCrimeCooldown(crime, minutes)` -> sets cooldown (minutes <= 0 = clear)

### Server Exports

* `exports['watari_cooldown']:IsReady(crime)` -> `(ready:boolean, remainingMin:number)`
* `exports['watari_cooldown']:Set(crime, minutes)` -> sets cooldown (minutes <= 0 = clear)

### ox\_lib Callbacks

* `watari_cooldown:check` (crime) -> `(ready:boolean, remainingMin:number)`
* `watari_cooldown:list` (includeExpired:boolean)
* `watari_cooldown:getPrivileges`
* `watari_cooldown:reset` (crime) -- UI reset purpose

### UI

* Command: `/cooldownlist` (if enabled in config)
* Open UI:
  * `TriggerEvent('watari_cooldown:openUI')`
  * `TriggerEvent('watari_cooldown:openUI', true)` -- showActiveOnly
