> 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/exports.md).

# Exports

Open the tablet, read balances, check permissions and upgrades from other resources.

## Client

### openSocietyMenu

Opens the tablet. Returns `true` when it opened, `false` when it is already open or the player has no job of that type.

```lua
exports['kossek_society']:openSocietyMenu(societyName, societyType, options)
```

| Parameter               | Type    | Description                                                                                                               |
| ----------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------- |
| `societyName`           | string  | Name of the society / job.                                                                                                |
| `societyType`           | string  | `'job'` or `'secondjob'`.                                                                                                 |
| `options.withAnimation` | boolean | Play the tablet animation. Default `true`.                                                                                |
| `options.defaultRoute`  | string  | Tab to open on. Default `'/dashboard'`. Others: `/employees`, `/banking`, `/upgrades`, `/missions`, `/notes`, `/history`. |

```lua
exports['kossek_society']:openSocietyMenu('police', 'job', {
    withAnimation = true,
    defaultRoute = '/banking'
})
```

### closeSocietyMenu

```lua
exports['kossek_society']:closeSocietyMenu()
```

### isMenuOpen

```lua
local isOpen = exports['kossek_society']:isMenuOpen()
```

### getCurrentSociety

Returns the society the tablet is open on: `{ name = 'police', type = 'job' }`. An empty table when the tablet is closed.

```lua
local society = exports['kossek_society']:getCurrentSociety()

if society.name then
    print('Current society: ' .. society.name)
end
```

## Server

### Societies

#### registerSociety

Registers a society and creates its account. Returns `false` when a society with that name already exists.

```lua
exports['kossek_society']:registerSociety(name, label, account, type)
```

| Parameter | Type   | Description                                 |
| --------- | ------ | ------------------------------------------- |
| `name`    | string | Society identifier, usually the job name.   |
| `label`   | string | Display name.                               |
| `account` | string | Account name, for example `society_police`. |
| `type`    | string | `'job'` or `'gang'`.                        |

```lua
exports['kossek_society']:registerSociety('police', 'Los Santos Police Department', 'society_police', 'job')
```

{% hint style="info" %}
Scripts written for esx\_society pass `society_<job>` as the fourth argument. That is accepted and treated as `'job'`.
{% endhint %}

#### getSociety

Returns the society object, or `nil`.

```lua
local society = exports['kossek_society']:getSociety('police')
```

The object has the banking methods:

```lua
society:getMoney(function(money) end)
society:addMoney(amount, function(success) end)
society:removeMoney(amount, function(success) end)
```

```lua
local police = exports['kossek_society']:getSociety('police')

police:getMoney(function(money)
    print('Police balance: $' .. money)

    police:addMoney(5000, function(success)
        if success then
            print('Added $5000 to the police account')
        end
    end)
end)
```

### Permissions

| Export                                                              | Returns                                               |
| ------------------------------------------------------------------- | ----------------------------------------------------- |
| `hasPermission(playerId, societyName, societyType, permissionType)` | `true` when the player has that permission.           |
| `isBoss(playerId, societyName, societyType)`                        | `true` when the player is a boss of the society.      |
| `getPlayerPermissions(playerId, societyName, societyType)`          | List of the player's permissions.                     |
| `clearPlayerCache(identifier)`                                      | Nothing. Drops the cached permissions of that player. |

The permission names are listed on the [Configuration](/docs/scripts/society/config.md) page.

```lua
if exports['kossek_society']:hasPermission(source, 'police', 'job', 'withdraw_money') then
    -- allow the withdrawal
end
```

### Upgrades

| Export                                                                       | Returns                                                                              |
| ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
| `getSocietyUpgrades(societyName, societyType)`                               | All upgrades of the society with their current levels.                               |
| `getUpgradeDetails(societyName, societyType, upgradeType)`                   | Details of one upgrade.                                                              |
| `getUpgradeSlots(societyName, societyType, upgradeType)`                     | `slots, hasUpgrade`: the current capacity, and whether the upgrade was bought.       |
| `hasUpgradeAccess(societyName, societyType, upgradeType)`                    | Whether the society has that upgrade.                                                |
| `hasUpgradePermission(societyName, societyType, upgradeType, requiredLevel)` | `hasUpgrade, level`: whether the upgrade is at least `requiredLevel`, and its level. |
| `getOrganizationLevel(societyName, societyType)`                             | The society's organization level.                                                    |

```lua
-- size a stash by the storage upgrade
local slots = exports['kossek_society']:getUpgradeSlots('police', 'job', 'storage')
```

```lua
-- gate a feature behind an upgrade
local hasArmory, level = exports['kossek_society']:hasUpgradePermission('police', 'job', 'armory', 1)

if hasArmory then
    print('Police armory is level ' .. level)
end
```

### Bonuses

| Export                                                 | Description                            |
| ------------------------------------------------------ | -------------------------------------- |
| `getBonusSettings(societyName, societyType)`           | Returns the bonus and salary settings. |
| `setBonusSettings(societyName, societyType, settings)` | Saves them.                            |
| `processPayouts()`                                     | Runs the weekly payouts now.           |

```lua
local settings = exports['kossek_society']:getBonusSettings('police', 'job')

settings.member_bonus = 10000
exports['kossek_society']:setBonusSettings('police', 'job', settings)
```

### History

#### logAction

Adds an entry to the society's history, so actions from your own scripts show up on the tablet.

```lua
exports['kossek_society']:logAction(societyName, societyType, actionType, performedBy, performedByIdentifier, metadata)
```

```lua
exports['kossek_society']:logAction('police', 'job', 'custom_action', 'John Doe', 'license:abc123', {
    description = 'Custom action performed',
    amount = 5000,
    target = 'Jane Doe'
})
```

### Detection

| Export                  | Description                                                                                         |
| ----------------------- | --------------------------------------------------------------------------------------------------- |
| `getDetectionResults()` | Returns what was detected on start: `framework`, `frameworkResource`, `banking`, `bankingVerified`. |
| `redetectSystems()`     | Runs the detection again and returns the result.                                                    |

### esx\_society compatibility

For scripts written against esx\_society, these exports are provided as well: `getSocietyMoney(societyName)`, `getPlayers(societyName, societyType)` and `washMoney(societyName, amount)`.
