> For the complete documentation index, see [llms.txt](https://k0ssek-scripts.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://k0ssek-scripts.gitbook.io/docs/scripts/society/events.md).

# Events

Client and server events, including the esx\_society ones.

## Client

### Open and close the tablet

```lua
TriggerEvent('kossek_society:openMenu', societyName, societyType, options)
TriggerEvent('kossek_society:closeMenu')
```

Same arguments as the `openSocietyMenu` export. From the server:

```lua
TriggerClientEvent('kossek_society:openMenu', source, 'police', 'job')
```

### Updates you can listen to

| Event                                     | Arguments               | Fired when                        |
| ----------------------------------------- | ----------------------- | --------------------------------- |
| `kossek_society:updateBalance`            | `newBalance`            | The society balance changed.      |
| `kossek_society:updateEmployees`          | none                    | The employee list changed.        |
| `kossek_society:permissionsUpdated`       | none                    | The player's permissions changed. |
| `kossek_society:historyUpdated`           | `data`                  | A new action was logged.          |
| `kossek_society:upgradesPurchased`        | `upgradeType, newLevel` | An upgrade was bought.            |
| `kossek_society:organizationLevelChanged` | `newLevel`              | The organization level changed.   |

```lua
RegisterNetEvent('kossek_society:upgradesPurchased', function(upgradeType, newLevel)
    print(('Upgrade purchased: %s level %s'):format(upgradeType, newLevel))
end)
```

## Server

### Register and read societies

```lua
TriggerEvent('kossek_society:registerSociety', name, label, account, type)

TriggerEvent('kossek_society:getSocieties', function(societies)
    for _, society in ipairs(societies) do
        print('Society: ' .. society.name)
    end
end)

TriggerEvent('kossek_society:getSociety', 'police', function(society)
    if society then
        print('Found society: ' .. society.name)
    end
end)
```

`type` is `'job'` or `'gang'`. The same is available as exports, see [Exports](/docs/scripts/society/exports.md).

## esx\_society compatibility

kossek\_society answers the esx\_society events and callbacks, so existing job scripts work without changes.

| Kind             | Names                                                                                                                               |
| ---------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| Server events    | `esx_society:registerSociety`, `esx_society:getSocieties`, `esx_society:getSociety`                                                 |
| Net events       | `esx_society:depositMoney`, `esx_society:withdrawMoney`, `esx_society:washMoney`, `esx_society:addMoney`, `esx_society:removeMoney` |
| Server callbacks | `esx_society:getSocietyMoney`, `esx_society:getOnlinePlayers`, `esx_society:getJob`, `esx_society:setJob`, `esx_society:getPlayers` |
| Client event     | `esx_society:openBossMenu` opens the tablet                                                                                         |

The compatibility layer is open (`compatibility/esx_society/`), so you can adjust it.
