# Inventory

## Introduction

T1GER Resources supports compatibility with popular custom inventories. We plan on adding "out-the-box" compatibility with more inventories as they are being proposed to us.&#x20;

{% hint style="success" %}
You can also use the 'custom' option and integrate your own exports/function for whatever custom inventory you may have.
{% endhint %}

### Config.Inventory

```lua
Config.Inventory = 'ox-inventory' -- Set the inventory system
```

Specifies the custom inventory system in use. Update this based on your selected inventory system.

* **Type**: `string`
* **Options**:
  * `'ox-inventory'` - [Ox Inventory](https://github.com/overextended/ox_inventory)
  * `'qb-inventory'` - [QB Inventory](https://docs.qbcore.org/qbcore-documentation/qbcore-resources/qb-inventory)
  * `'mf-inventory'` - ModFreakz Inventory (paid)
  * `'qs-inventory'` - Quasar Inventory (paid)
  * `'core-inventory'` - Core Inventory (paid)
  * `'codem-inventory'` - CodeM Inventory (paid)
  * `'custom'` - If none of these are being used or if you want to integrate your own!

## Setup

All you need to do is basically set your inventory system in `Config.Inventory` and you are all set.

{% hint style="danger" %}
If you are not using any of the preconfigured inventories, set the option to **`'custom'`**.

* Please note that you have to integrate exports/functions yourself! It's not our job to support for 3rd party paid inventory.
* We strongly recommend to reach out to your inventory creator to ask them to help you integrate their resource.&#x20;
* You can suggest compatibility on our discord and we might reach out to the creator of said inventory to possibly add preconfigured support.
  {% endhint %}

## Functions

These are the functions used in our T1GER resources.

{% hint style="info" %}
These are also the functions you want to modify in case you want to integrate your custom inventory resource. Simply use `'custom'` in `Config.Inventory` and integrate your export/functions in the if/else statements for `'custom'`.
{% endhint %}

### OpenStash

```
t1ger_lib/client/framework.lua
```

Used when player in-game opens a shared/stash inventory. Usually in my resources, owner is nil.

```lua
OpenStash(id, label, slots, weight, owner)
-- parameters: id(string), label(string), slots(int), weight(int), owner(string)
-- void: client-function to open the stash/inventory. Commonly used parameters are parsed as u can see.
```

### CreateStash

```
t1ger_lib/server/framework.lua
```

Used when creating a stash first time (example when creating a storage marker). Not all inventories require this function to be ran.

```lua
CreateStash(id, label, slots, weight, owner)
-- parameters: id(string), label(string), slots(int), weight(int), owner(string)
-- void: server-function to create/register stash first time when creating for example a marker.
```

### RegisterStash

```
t1ger_lib/server/framework.lua
```

Used when restarting resource or starting up server. Some inventories requires stashes/storages to be registered/created manually.&#x20;

```lua
RegisterStash(id, label, slots, weight, owner)
-- parameters: id(string), label(string), slots(int), weight(int), owner(string)
-- void: server-function to register stash on resource startup
```

### StashAddItem

```
t1ger_lib/server/framework.lua
```

Used when need to add an item directly into a stash/storage. The stash/storage identifier string is also parsed as an argument in this function.

```lua
StashAddItem(storageId, item, amount)
-- parameters: storageId(string), item(string), amount(int)
-- void: adds x amount of item into stash/storage with given id/identifier for the stash
```

## QB Inventory Not Opening

By default, t1ger\_lib will support latest qb-inventory. If you may for whatever reason, still be using the old qb-inventory, then follow these instructions:

#### `t1ger_lib/client/framework.lua`

Find the function called `OpenStash` and you should see the following code:

<figure><img src="https://2167335559-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MiDWIMbFBeXle-trOlk%2Fuploads%2FRkVQ1xhmaqSorJ1d1Z3W%2Fimage.png?alt=media&#x26;token=25ed3601-fcc7-49d2-8e94-f458696d48a7" alt=""><figcaption></figcaption></figure>

Now, all u need to do is simply commenting out the TriggerServerEvent and enabling the other code that has already been commented out.&#x20;

You can also replace your whole OpenStash function with this snippet, where I have made the changes for you:&#x20;

```lua
    OpenStash = function(id, label, slots, weight, owner)
        if Config.Inventory == 'ox-inventory' then
            exports.ox_inventory:openInventory('stash', {id = id})
        elseif Config.Inventory == 'qb-inventory' then
            --TriggerServerEvent('t1ger_lib:server:openInventory', id, label, slots, weight, owner)
            TriggerServerEvent('inventory:server:OpenInventory', 'stash', id, {
                maxweight = weight,
                slots = slots
            })
            TriggerEvent('inventory:client:SetCurrentStash', id)
        elseif Config.Inventory == 'mf-inventory' then
            exports['mf-inventory']:openOtherInventory(id)
        elseif Config.Inventory == 'qs-inventory' then
            local other = {}
            other.maxweight = weight 
            other.slots = slots 
            TriggerServerEvent('inventory:server:OpenInventory', 'stash', 'Stash_'..id, other)
            TriggerEvent('inventory:client:SetCurrentStash', 'Stash_'..id)
        elseif Config.Inventory == 'core-inventory' then
            TriggerServerEvent('core_inventory:server:openInventory', 'stash-'..id:gsub('/',''):gsub(':',''):gsub('#',''), 'stash', nil, nil)
        elseif Config.Inventory == 'custom' then
            -- export/event to open stash/storage inventory
        end
    end,
```
