# 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 %}
