> For the complete documentation index, see [llms.txt](https://striga.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://striga.gitbook.io/docs/striga-inventory/exports-and-events/server.md).

# Server

Server exports, hooks and server events of Striga Inventory.

All exports here are **server side**. For the `inv` and `target` arguments, see [Exports & Events](/docs/striga-inventory/exports-and-events.md).

## Items

| Export                                                  | Returns                                 | What it does                                            |
| ------------------------------------------------------- | --------------------------------------- | ------------------------------------------------------- |
| `AddItem(inv, name, amount?, info?, slot?, reason?)`    | `ok`, result                            | Adds an item. `info` = metadata table                   |
| `RemoveItem(inv, name, amount?, info?, slot?, reason?)` | `ok`                                    | Removes an item                                         |
| `GetItems(inv)`                                         | table                                   | All items                                               |
| `GetItemBySlot(inv, slot)`                              | `{ name, amount, info, slot }` or `nil` | Item in one slot                                        |
| `GetItemCount(inv, name, info?)`                        | number                                  | How many of an item (optionally with matching metadata) |
| `CanCarry(inv, name, amount?, info?)`                   | bool                                    | Is there room (slots and weight)                        |
| `GetWeight(inv)`                                        | number                                  | Current weight in grams                                 |
| `GetMaxWeight(inv)`                                     | number                                  | Max weight in grams                                     |
| `SetMetadata(inv, slot, info)`                          | bool                                    | Replaces the metadata of the item in a slot             |
| `ClearInventory(inv, keep?)`                            | bool                                    | Clears it. `keep` = item name or list of names to keep  |
| `GetItemData(name)`                                     | table or `nil`                          | The item's definition                                   |

`amount` defaults to `1`. A weapon added without `serie` / `quality` gets a serial number and `quality = 100`.

{% hint style="info" %}
Metadata `label` and `image` change how one item shows: `SetMetadata(source, slot, { label = 'Old watch' })`.
{% endhint %}

```lua
-- Give a weapon with metadata
exports['striga-inventory']:AddItem(source, 'weapon_pistol', 1, { serie = 'ABC123' }, nil, 'my-script:reward')

-- Check before adding
if exports['striga-inventory']:CanCarry(source, 'water_bottle', 5) then
    exports['striga-inventory']:AddItem(source, 'water_bottle', 5)
end

-- How many in a stash
local count = exports['striga-inventory']:GetItemCount('stash:police', 'bandage')
```

***

## Open and close

| Export                          | Returns | What it does                    |
| ------------------------------- | ------- | ------------------------------- |
| `OpenInventory(source, target)` | bool    | Opens an inventory for a player |
| `CloseInventory(source)`        | bool    | Closes the player's inventory   |
| `IsOpen(source)`                | bool    | Is the player's inventory open  |

```lua
exports['striga-inventory']:OpenInventory(source, { type = 'stash', id = 'police_evidence' })
exports['striga-inventory']:OpenInventory(source, 'trunk:ABC123')
```

***

## Stashes, shops, drops and crafting

| Export                             | Returns          | What it does                                                              |
| ---------------------------------- | ---------------- | ------------------------------------------------------------------------- |
| `RegisterStash(id, opts)`          | bool             | Registers a stash                                                         |
| `RegisterPersonalStash(id, opts)`  | bool             | A stash at a place, one copy per character (`coords` required)            |
| `RegisterShop(id, opts)`           | bool             | Registers a shop                                                          |
| `RegisterGunShop(id, opts)`        | bool             | Same as `RegisterShop`, as a gun shop                                     |
| `OpenShop(source, id)`             | bool             | Opens a shop for a player (your script checks the place)                  |
| `RegisterCraft(id, opts)`          | bool             | Adds a crafting bench. See [Crafting](/docs/striga-inventory/crafting.md) |
| `CreateDrop(coords, items, opts?)` | drop id or `nil` | Puts items on the ground (max 50 entries)                                 |

Stashes, shops, benches and hooks of your resource are removed by themselves when it stops.

{% tabs %}
{% tab title="Stash" %}

```lua
-- opts: label?, slots?, maxWeight?, owner? (true = one per character), groups? { job = minGrade }, coords? vector3
exports['striga-inventory']:RegisterStash('police_evidence', {
    label = 'Evidence',
    slots = 100,
    maxWeight = 500000,
    groups = { police = 2 },
})

exports['striga-inventory']:RegisterPersonalStash('mechanic_locker', {
    label = 'Mechanic locker',
    coords = vector3(-347.4, -133.6, 39.0),
    groups = { mechanic = 0 },
})
```

{% endtab %}

{% tab title="Shop" %}

```lua
-- opts: label?, type? ('weapon'), products, locations? { vector4 } | coords?, interactionDistance?,
--       groups? | requiredJob?, account? 'cash' | 'bank', ped?, scenario?, blip? { sprite, scale, color }, interact?
exports['striga-inventory']:RegisterShop('my_shop', {
    label = 'Corner Shop',
    products = {
        { name = 'water_bottle', price = 2, amount = 50 },
        { name = 'sandwich', price = 3, amount = 50 },
    },
    locations = { vector4(24.47, -1346.62, 29.5, 271.66) },
    interact = true,   -- players open it with E at its locations
    ped = 'mp_m_shopkeep_01',
    blip = { sprite = 52, scale = 0.6, color = 0 },
})
```

Product fields: `name`, `price`, `amount` (stock), `requiredJob?`, `requiredLicense?`.

{% hint style="warning" %}
Without `interact = true` the shop only opens through `OpenShop` from your script, so your own checks (job, mission, reputation) stay in charge.
{% endhint %}
{% endtab %}

{% tab title="Crafting" %}

```lua
-- opts: label?, coords | locations, interactionDistance?, groups?, blip?, recipes
exports['striga-inventory']:RegisterCraft('weed_table', {
    label = 'Weed table',
    coords = vector3(1039.5, -3205.2, -38.2),
    groups = { ballas = 0 },
    recipes = {
        { name = 'weed_baggy', amount = 5, time = 6000, ingredients = { weed_brick = 1, empty_baggy = 5 } },
    },
})
```

{% endtab %}

{% tab title="Drop" %}

```lua
-- items: { { name, amount?, info? } }   opts: label?, slots?, maxWeight?, bucket?
local dropId = exports['striga-inventory']:CreateDrop(GetEntityCoords(GetPlayerPed(source)), {
    { name = 'bandage', amount = 3 },
})
```

{% endtab %}
{% endtabs %}

***

## Hooks

Hooks let your script check an action and **cancel** it. Return `false` to cancel.

| Export                             | Returns | What it does                                            |
| ---------------------------------- | ------- | ------------------------------------------------------- |
| `RegisterHook(event, fn, filter?)` | hook id | Adds a hook                                             |
| `RemoveHooks(id?)`                 | -       | Removes one hook, or all hooks of your resource (`nil`) |

**Events:** `move`, `add`, `remove`, `use`, `open`, `buy`, `craft`

**Filter:** `itemFilter = { name = true }`, `typeFilter = { stash = true }`, `inventoryFilter = { 'pattern' }`

| Event    | Payload fields                                                                                                      |
| -------- | ------------------------------------------------------------------------------------------------------------------- |
| `add`    | `item`, `amount`, `to`, `toType`, `reason`                                                                          |
| `remove` | `item`, `amount`, `from`, `fromType`, `reason`                                                                      |
| `use`    | `source`, `item`, `slot`, `from`, `fromType`                                                                        |
| `open`   | `source`, `to`, `toType` (`'shop:<id>'` / `'craft:<id>'` for shops and benches)                                     |
| `buy`    | `source`, `item`, `amount`, `price`, `from` (`'shop:<id>'` or `'gunsmith:<id>'`), `fromType`, `to`, `toType`        |
| `craft`  | `source`, `item`, `amount`, `recipe`, `bench`, `to`, `toType`                                                       |
| `move`   | `source`, `item`, `amount`, `from`, `fromType`, `to`, `toType` (moves inside the UI also send `fromSlot`, `toSlot`) |

```lua
-- No guns in the police evidence stash
exports['striga-inventory']:RegisterHook('move', function(payload)
    if payload.to == 'stash:police_evidence' and payload.item:sub(1, 7) == 'weapon_' then
        return false
    end
end, { typeFilter = { stash = true } })
```

{% hint style="info" %}
A hook that errors is logged and skipped. A hook slower than 50 ms prints a warning.
{% endhint %}

***

## Server events

For listening with `AddEventHandler`:

| Event                      | Arguments                           | When                         |
| -------------------------- | ----------------------------------- | ---------------------------- |
| `striga-inventory:used`    | `source`, `name`, `item`            | A player used an item        |
| `striga-inventory:changed` | `source`                            | A player's inventory changed |
| `striga-inventory:crafted` | `source`, `name`, `amount`, `bench` | A player crafted something   |

```lua
AddEventHandler('striga-inventory:crafted', function(source, name, amount, bench)
    print(('player %s crafted %dx %s at %s'):format(source, amount, name, bench))
end)
```

{% content-ref url="/pages/62itaUo7IpuuiTQBlLIk" %}
[Client](/docs/striga-inventory/exports-and-events/client.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://striga.gitbook.io/docs/striga-inventory/exports-and-events/server.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
