> For the complete documentation index, see [llms.txt](https://5scripts-1.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://5scripts-1.gitbook.io/docs/assets/5s_building/custom-inventory.md).

# Custom Inventory

{% hint style="info" %}
**Supported inventories**

5s\_lib already supports these out of the box. Set yours in the [5s\_lib config](/docs/assets/5s_lib/config.md) and skip this page:

`ox_inventory`, `qs-inventory`, `qb-inventory`, `tgiann-inventory`, `core_inventory`, `basic-framework`

Only follow this page if your inventory is **not** on that list.
{% endhint %}

If your server runs an inventory that 5s\_lib does not support out of the box, you can wire it up yourself through the standalone bridge.

## 1. Select the standalone bridge

In `5s_lib/config.lua` set the inventory to `standalone`:

```lua
Config.inventory = "standalone"
```

This tells 5s\_lib to load the standalone bridge instead of a built-in one. By default every standalone function is a stub that returns a safe value and prints a `not implemented` warning, so nothing works until you fill them in.

## 2. Implement the server functions

File: `5s_lib/resource/bridge/inventory/standalone/server.lua`

5s\_building calls these functions, so all of them must be implemented for items, chests, and loot bags to work:

```lua
standalone.addItem = function(source, item, amount)
    -- Give `amount` of `item` to the player `source`
end

standalone.removeItem = function(source, item, amount)
    -- Take `amount` of `item` from the player `source`
end

standalone.getItemCount = function(source, item)
    -- Must RETURN how many of `item` the player `source` has (number)
    return 0
end

standalone.registerStash = function(stashId, label, slots, weight)
    -- Create/register a stash identified by `stashId`
end

standalone.openStash = function(source, stashId)
    -- Open the stash `stashId` for the player `source` (server-driven open)
end

standalone.getStashItems = function(stashId)
    -- Must RETURN the stash contents as a list of items.
    -- Each item should expose: name, count, weight, metadata, slot
    return {}
end

standalone.addStashItem = function(stashId, itemName, count, metadata)
    -- Add an item to the stash `stashId`
end

standalone.removeStashItem = function(stashId, itemName, count, metadata, slot)
    -- Remove an item from the stash `stashId`
end

standalone.clearStash = function(stashId)
    -- Empty the stash `stashId`
end
```

## 3. Implement the client function

File: `5s_lib/resource/bridge/inventory/standalone/client.lua`

```lua
standalone.openStashClient = function(stashId)
    -- Open the stash `stashId` on the client (client-driven open)
end
```

`Config.stash.open` in `5s_building/config.lua` decides which open path is used:

* `"server"` calls `openStash` (server side).
* `"client"` calls `openStashClient` (client side).

Implement the side you use, or both to be safe.

## Reference: ox\_inventory

For comparison, here is how the same functions are implemented for ox\_inventory in `5s_lib/resource/bridge/inventory/ox/server.lua`:

```lua
ox.addItem = function(source, item, amount)
    exports.ox_inventory:AddItem(source, item, amount)
end

ox.removeItem = function(source, item, amount)
    exports.ox_inventory:RemoveItem(source, item, amount)
end

ox.getItemCount = function(source, item)
    return exports.ox_inventory:GetItemCount(source, item)
end

ox.registerStash = function(stashId, label, slots, weight)
    exports.ox_inventory:RegisterStash(stashId, label, slots, weight, nil)
end

ox.openStash = function(source, stashId)
    exports.ox_inventory:forceOpenInventory(source, "stash", stashId)
end

ox.getStashItems = function(stashId)
    return exports.ox_inventory:GetInventoryItems(stashId)
end

ox.addStashItem = function(stashId, itemName, count, metadata)
    exports.ox_inventory:AddItem(stashId, itemName, count, metadata)
end

ox.removeStashItem = function(stashId, itemName, count, metadata, slot)
    exports.ox_inventory:RemoveItem(stashId, itemName, count, metadata, slot)
end

ox.clearStash = function(stashId)
    exports.ox_inventory:ClearInventory(stashId)
end
```

And the client side in `5s_lib/resource/bridge/inventory/ox/client.lua`:

```lua
ox.openStashClient = function(stashId)
    exports.ox_inventory:openInventory("stash", stashId)
end
```

> **Note:** The standalone bridge also ships stubs for `hasItem`, `canCarryItem`, and `createDrop`. 5s\_building does not call those, so you only need them if another 5scripts resource on your server uses them.
