# qb-inventory

{% tabs %}
{% tab title="Old Version" %}

* Add the following code at the end of the file

{% code title="qb-inventory/server/main.lua" %}

```lua
exports("GetStash", function(stashId)
    return Stashes[stashId] or {
        items = GetStashItems(stashId)
    }
end)

exports('GetStashItems', GetStashItems)

RegisterServerEvent('qb-inventory:server:SaveStashItems', function(stashId, items)
    MySQL.insert('INSERT INTO stashitems (stash, items) VALUES (@stash, @items) ON DUPLICATE KEY UPDATE items = @items', {
        ['@stash'] = stashId,
        ['@items'] = json.encode(items)
    })

    if Stashes[stashId] then
        Stashes[stashId].items = items
    end
end)
```

{% endcode %}
{% endtab %}

{% tab title="New Version (2.0)" %}

* Modify the function called `InitializeInventory` so that it looks like this

{% code title="qb-inventory\server\functions.lua" %}

```lua
local function InitializeInventory(inventoryId, data)
    if Inventories[inventoryId] and Inventories[inventoryId].maxweight then return Inventories[inventoryId] end
    Inventories[inventoryId] = {
        items = {},
        isOpen = false,
        label = data and data.label or inventoryId,
        maxweight = data and data.maxweight or Config.StashSize.maxweight,
        slots = data and data.slots or Config.StashSize.slots
    }
    return Inventories[inventoryId]
end
```

{% endcode %}

* Below the previous function, add the export of it

{% code title="qb-inventory\server\functions.lua" %}

```lua
exports('InitializeInventory', InitializeInventory)
```

{% endcode %}

* Add the following code at the end of the file

{% code title="qb-inventory\server\functions.lua" %}

```lua
exports('GetStashItems', function(identifier)
    local inventory = Inventories[identifier]
    if not inventory then return end
    return inventory.items
end)
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions: 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:

```
GET https://docs.origennetwork.store/origen-masterjob/installation/qb-inventory.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
