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

# Server Exports

Server functions of the Striga Core API.

```lua
local Core = exports['striga-core']:GetCore()
```

On the server, most functions take the player `src` as the first argument: `Core.getMoney(src, 'cash')`.

## Player

| Function                          | Returns                                                                       |
| --------------------------------- | ----------------------------------------------------------------------------- |
| `isReady()`                       | Core is ready                                                                 |
| `isLoggedIn(src)`                 | Player is in game with a character                                            |
| `getProfile(src)`                 | `{ charId, firstname, lastname, birthdate, gender, phone, money, job, gang }` |
| `getCharId(src)` / `getName(src)` | Character id / first and last name                                            |
| `getMoney(src, account)`          | Money in that account                                                         |
| `getJob(src)` / `getGang(src)`    | `{ name, label, onDuty, isBoss, grade = { level, name, label } }`             |
| `getMetadata(src, key)`           | Framework metadata value (e.g. `stress`)                                      |
| `framework()` / `inventory()`     | Name of the active system                                                     |

## Money and metadata

| Function                                     | Notes                 |
| -------------------------------------------- | --------------------- |
| `addMoney(src, account, amount, reason?)`    |                       |
| `removeMoney(src, account, amount, reason?)` | `false` if not enough |
| `setMoney(src, account, amount, reason?)`    |                       |
| `setMetadata(src, key, value)`               |                       |

## Inventory

| Function                                                                        | Returns / does                                                 |
| ------------------------------------------------------------------------------- | -------------------------------------------------------------- |
| `getItems(src)`                                                                 | List of `{ name, label, count, slot, weight, metadata }`       |
| `getItemCount(src, item)` / `hasItem(src, item, count?, metadata?)`             | Count / boolean                                                |
| `hasItems(src, list)`                                                           | All items in the list                                          |
| `getItemLabel(item)` / `getItemData(item)`                                      | Label / `{ label, weight, description, unique, useable, ... }` |
| `inventoryWeight(src)` / `inventoryMaxWeight(src)` / `inventoryFreeWeight(src)` | Weight                                                         |
| `canCarry(src, item, count)`                                                    | Boolean                                                        |
| `addItem(src, item, count, metadata?, slot?, reason?)`                          |                                                                |
| `removeItem(src, item, count, metadata?, slot?, reason?)`                       |                                                                |
| `getItemBySlot(src, slot)` / `setItemMetadata(src, slot, metadata)`             | Slot item / set its metadata                                   |
| `registerUsableItem(item, fn(src, item))`                                       | Run `fn` when a player uses the item                           |
| `registerStash(id, opts)` / `registerShop(id, opts)`                            |                                                                |
| `openInventory(src, target)` / `closeInventory(src)`                            |                                                                |
| `clearInventory(src, keep?)`                                                    |                                                                |
| `createDrop(coords, items, opts?)`                                              |                                                                |

{% hint style="warning" %}
Core checks the shape of the data. **Distance, job and intent checks are your job**, for example before `openInventory`.
{% endhint %}

## Identity and staff

| Function                  | Returns                                                                            |
| ------------------------- | ---------------------------------------------------------------------------------- |
| `getIdentity(src)`        | `{ id, name, loggedIn, charId?, firstname, lastname, charName, job, gang, staff }` |
| `getStaff(src)`           | `{ group, level, isStaff, groups }`                                                |
| `isStaff(src, minGroup?)` | Boolean. Groups from `staff.groups` in `config.json`, or the `staff.ace` ACE       |
| `hasAce(src, object)`     | Boolean                                                                            |

## Players and position

| Function                                                         | Returns                            |
| ---------------------------------------------------------------- | ---------------------------------- |
| `getPlayers()` / `getPlayerList()`                               | Online players                     |
| `getPlayersNear(src, radius, opts?)`                             | Players near `src`                 |
| `getSourceByCharId(charId)` / `getSourceByLicense(license)`      | Player id or `nil`                 |
| `getBucket(src)` / `getCoords(src)` / `getDistance(src, target)` | Routing bucket / coords / distance |

## Notify, callbacks, chat

| Function                                                                                                  | Notes                                          |
| --------------------------------------------------------------------------------------------------------- | ---------------------------------------------- |
| `notify(src, text, type?, duration?)` or `notify(src, { title, description, type, duration, icon, ... })` | Max 20 per second per player, more are dropped |
| `registerCallback(name, fn(src, ...), { limit?, window? })`                                               | Name must start with your resource name        |
| `getCommandSuggestions(src)` / `refreshCommands(src)`                                                     | Chat command suggestions                       |

## Language

The server language is set in `config.json` (`"locale"`) and with `/strigalocale`. Core reads **your** resource's `editable/locales/<code>.json` (the calling resource). `code` is optional: without it the active language is used.

| Export                            | Returns                                                                                                                      |
| --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `GetLocale()`                     | Active code, e.g. `'tr'`                                                                                                     |
| `LocaleText(key, params?, code?)` | `game[key]`, then English `game[key]`, then the key. `{name}` is filled from `params`; without params you get the raw string |
| `LocaleUi(path, code?)`           | Dotted lookup in `ui` (`'settings.title'`), string or table, English fallback                                                |
| `LocaleFiles(code?)`              | `localeRaw, fallbackRaw`: raw JSON of `<code>.json` and `en.json`, for your NUI                                              |
| `GetLocales()`                    | Array of codes that exist for your resource                                                                                  |
| `SetLocale(code)`                 | `true` when set. Live, not saved (same as `/strigalocale`)                                                                   |

```lua
local text = exports['striga-core']:LocaleText('welcome', { name = 'Alex' })  -- "Welcome {name}" -> "Welcome Alex"
local title = exports['striga-core']:LocaleUi('settings.title')
```

A missing `<code>.json` prints one console warning and English is used. Listen to the [locale events](/striga-docs/striga-core/events.md) to refresh your texts when the language changes.

## Example

```lua
Core.registerCallback('my-shop:getPrice', function(src, item)
    if type(item) ~= 'string' then return nil end
    return prices[item]
end)

RegisterNetEvent('my-shop:buy', function(item)
    local src = source
    local price = prices[item]
    if not price then return end
    if not Core.canCarry(src, item, 1) then return Core.notify(src, 'Bag is full', 'error') end
    if not Core.removeMoney(src, 'cash', price, 'my-shop') then return Core.notify(src, 'Not enough money', 'error') end
    Core.addItem(src, item, 1)
end)
```

## GetSuiteVersions

```lua
local versions = exports['striga-core']:GetSuiteVersions()
-- { ['striga-chat'] = { version = '1.0.0', min = '0.1.0', latest = '1.0.0', outdated = false }, ... }
```

`latest` is `nil` until an update check worked.

{% content-ref url="/pages/h3GHrnMxz5MNy4sOwDR6" %}
[Client Exports](/striga-docs/striga-core/exports/client-exports.md)
{% endcontent-ref %}
