> For the complete documentation index, see [llms.txt](https://docs.kojascripts.eu/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kojascripts.eu/koja-lib/inventory/custom-inventory.md).

# Custom Inventory

If you use an inventory that is not supported out of the box, set `Config.Inventory = "custom"` and fill in the stub files.

***

## Setup

```lua
-- editable/shared/config.lua
Config.Inventory = "custom"
```

Two stub files are then loaded automatically:

| File                                   | Side   |
| -------------------------------------- | ------ |
| `editable/custom/inventory_server.lua` | Server |
| `editable/custom/inventory_client.lua` | Client |

***

## Server Stubs

Open `editable/custom/inventory_server.lua` and implement each function:

```lua
CustomInventory.Server = {}

-- Add `count` of `name` to the player's inventory.
-- metadata and slot are optional.
-- Return true on success.
CustomInventory.Server.AddItem = function(src, name, count, metadata, slot)
    return false
end

-- Remove `count` of `name` from the player's inventory.
-- Return true on success.
CustomInventory.Server.RemoveItem = function(src, name, count, metadata, slot)
    return false
end

-- Return the total count of `name` in the player's inventory.
CustomInventory.Server.GetItemCount = function(src, name, metadata)
    return 0
end

-- Return the full inventory as { [itemName] = count }.
CustomInventory.Server.GetItems = function(src)
    return {}
end
```

***

## Client Stubs

Open `editable/custom/inventory_client.lua` and implement each function:

```lua
CustomInventory.Client = {}

-- Return the count of `item` in the local player's inventory.
CustomInventory.Client.GetItemCount = function(item)
    return 0
end

-- Return the local player's full inventory as { [itemName] = count }.
CustomInventory.Client.GetItems = function()
    return {}
end
```

***

## Example

```lua
-- inventory_server.lua
CustomInventory.Server.AddItem = function(src, name, count, metadata, slot)
    local ok = exports['my-inventory']:addItemToPlayer(src, name, count)
    return ok == true
end

CustomInventory.Server.GetItemCount = function(src, name)
    return exports['my-inventory']:getItemCount(src, name) or 0
end

CustomInventory.Server.GetItems = function(src)
    local raw = exports['my-inventory']:getAllItems(src) or {}
    local result = {}
    for _, item in pairs(raw) do
        if item.name then
            result[item.name] = (result[item.name] or 0) + (item.count or 0)
        end
    end
    return result
end
```

Once implemented, all standard koja-lib inventory calls route through your functions:

```lua
KOJA.Server.addInventoryItem(source, 'bread', 3)
KOJA.Server.HasItem(source, 'bread')
KOJA.Server.GetPlayerInventory(source)
```


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.kojascripts.eu/koja-lib/inventory/custom-inventory.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
