> For the complete documentation index, see [llms.txt](https://tgiann.gitbook.io/tgiann/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tgiann.gitbook.io/tgiann/scripts/tgiann-inventory/exports/server.md).

# Server

## Server

{% hint style="info" %}
You do not have to replace calls like `AddItem`, `RemoveItem` or `GetItemByName` in your other scripts. The QB and ESX inventory functions keep working, they are bridged to these exports.
{% endhint %}

{% hint style="info" %}
Every export is also registered with a lowercase first letter, so `AddItem` and `addItem` call the same function.
{% endhint %}

{% hint style="info" %}
Item list, label, durability and crafting registration exports are shared between client and server. See the Shared page.
{% endhint %}

{% hint style="info" %}
**Grid inventory.** Inventories are grids of `config.grid.columns` cells per row and an item can take several cells (see `GetItemSize` on the Shared page). Wherever an export takes or returns a `slot`, it is the top left cell of the item; a turned item has `rotated = true` in its data. A slot amount (`slots`, `SetSlotCount`, `SetInventoryCapacity`) is a cell count.
{% endhint %}

{% hint style="info" %}
**Inventory references.** Exports that take an `inv` argument accept a player source (`number`), a stash name (`string`) or an Ox Inventory style table `{ id = "stash_name", owner = "citizenid" }`. Player facing exports such as `AddItem` and `RemoveItem` also accept a stash name instead of the player source.
{% endhint %}

### AddItem

Adds an item to the player. When the inventory is full, the item is either dropped on the ground or refused, depending on `config.createDropWhenPlayerFull`. Adding a firearm requires `serie`, `ammo`, `usedTotalAmmo` (and `durabilityPercent` when weapon durability is enabled) inside the metadata. Negative amounts ban the player.

The Ox Inventory argument order `(inv, item, count, metadata, slot, cb)` is detected automatically: when the 4th argument is a table it is treated as the metadata and the 5th as the slot. A stash name as the first argument adds the item to that stash.

```lua
local success = exports["tgiann-inventory"]:AddItem(src, "bandage", 2, nil, { level = 2 })
exports["tgiann-inventory"]:AddItem("police_stash", "bandage", 2)
```

#### Parameters

* **source**: `number | string` player source, or a stash name
* **item**: `string` item name
* **amount**: `number` amount to add
* **slot?**: `number` target slot (top left cell), the first place the whole item fits is used when omitted
* **info?**: `table` item metadata
* **isClotheSlot?**: `boolean` add the item to the clothing inventory instead of the main inventory. A function here is treated as the Ox Inventory `cb` and called with the result

#### Returns

* `boolean` success

***

### RemoveItem

Removes an item from the player and writes a removal log. Negative amounts ban the player. The Ox Inventory order `(inv, item, count, metadata, slot)` is detected when the 4th argument is a table, and a stash name as the first argument removes from that stash.

```lua
local itemData = exports["tgiann-inventory"]:GetItemByName(src, "bandage")
if itemData.amount > 0 then
    exports["tgiann-inventory"]:RemoveItem(src, "bandage", 1, itemData.slot)
end
```

#### Parameters

* **src**: `number | string` player source, or a stash name
* **item**: `string` item name
* **amount**: `number` amount to remove
* **slot?**: `number` slot to remove from
* **metadata?**: `table` metadata to match
* **strict?**: `boolean` strict metadata matching

#### Returns

* `boolean` success

***

### SetItem

Sets the amount of an item to an exact value.

```lua
local success = exports["tgiann-inventory"]:SetItem(src, "bandage", 15)
```

#### Parameters

* **src**: `number` player source
* **item**: `string` item name
* **amount**: `number` new amount
* **metadata?**: `table` metadata to match

#### Returns

* `boolean` success

***

### ClearInventory

Clears an inventory. Passing item names keeps only those items untouched.

```lua
exports["tgiann-inventory"]:ClearInventory(src)
exports["tgiann-inventory"]:ClearInventory(src, { "phone", "id_card" })
exports["tgiann-inventory"]:ClearInventory("police_stash")
```

#### Parameters

* **source**: `number | string | table` player source, stash name or inventory reference
* **filterItems?**: `string | string[]` items that must not be removed

***

### GetPlayerItems

Returns the items of the player's main inventory.

```lua
local items = exports["tgiann-inventory"]:GetPlayerItems(src)
```

#### Parameters

* **src**: `number` player source

#### Returns

* `table` slot indexed item list, empty table when the inventory is not loaded

***

### GetPlayerClotheItems

Returns the items of the player's clothing inventory.

```lua
local clotheItems = exports["tgiann-inventory"]:GetPlayerClotheItems(src)
```

#### Parameters

* **src**: `number` player source

#### Returns

* `table` slot indexed clothing item list

***

### HasItem

Checks whether the player carries the given item(s).

```lua
local has = exports["tgiann-inventory"]:HasItem(src, "bandage", 2)
local hasAll = exports["tgiann-inventory"]:HasItem(src, { "bandage", "armor" }, 2)
local hasAmounts = exports["tgiann-inventory"]:HasItem(src, { bandage = 2, armor = 1 })
```

#### Parameters

* **src**: `number` player source
* **items**: `string | string[] | table<string, number>` a single item name, an array of item names, or an item name to amount map
* **amount?**: `number` required amount, defaults to `1`. Only used when **items** is a string or an array

#### Returns

* `boolean` whether the player has the item(s)

***

### GetItemByName

Returns the first matching item slot data of the player.

```lua
local itemData = exports["tgiann-inventory"]:GetItemByName(src, "bandage")
if itemData.amount > 0 then
    exports["tgiann-inventory"]:RemoveItem(src, "bandage", itemData.amount, itemData.slot)
end
```

#### Parameters

* **src**: `number` player source
* **item**: `string` item name
* **metadata?**: `table` metadata to match
* **strict?**: `boolean` strict metadata matching

#### Returns

* `table` item data, or `{ amount = 0 }` when the item is not found

***

### GetItemsByName

Returns every matching item slot data of the player.

```lua
local items = exports["tgiann-inventory"]:GetItemsByName(src, "bandage")
```

#### Parameters

* **src**: `number` player source
* **item**: `string` item name
* **metadata?**: `table` metadata to match
* **strict?**: `boolean` strict metadata matching

#### Returns

* `table` list of item data, empty table when nothing matches

***

### GetItemBySlot

Returns the item in the given slot.

```lua
local itemData = exports["tgiann-inventory"]:GetItemBySlot(src, 1)
```

#### Parameters

* **src**: `number` player source
* **slot**: `number` slot id
* **metadata?**: `table` metadata to match
* **strict?**: `boolean` strict metadata matching

#### Returns

* `table` item data, or `{ amount = 0 }` when the slot is empty

***

### GetItemCount

Returns the total amount of the given item(s) in an inventory. With metadata only the matching stacks are counted.

```lua
local count = exports["tgiann-inventory"]:GetItemCount(src, "bandage")
local total = exports["tgiann-inventory"]:GetItemCount(src, { "bandage", "medikit" })
local levelTwo = exports["tgiann-inventory"]:GetItemCount(src, "bandage", { level = 2 })
local stashCount = exports["tgiann-inventory"]:GetItemCount("police_stash", "bandage")
```

#### Parameters

* **src**: `number | string | table` player source, stash name or inventory reference
* **items**: `string | string[]` item name or list of item names
* **metadata?**: `table` metadata to match
* **strict?**: `boolean` strict metadata matching, defaults to `true`

#### Returns

* `number` total amount

***

### GetItem

Returns item data from one or more inventories with the summed amount. Player inventories are addressed with a `number` source, stashes with their `string` name.

```lua
local itemData = exports["tgiann-inventory"]:GetItem(src, "bandage")
local amount = exports["tgiann-inventory"]:GetItem({ src, "airdrop_01" }, "bandage", nil, true)
```

#### Parameters

* **inv**: `number | string | table` player source, stash name, or a list of them
* **item**: `string | table` item name or item data containing a `name` field
* **metadata?**: `table` metadata to match
* **returnsCount?**: `boolean` return only the total amount instead of the item data

#### Returns

* `table | number | nil` item data with the summed `amount`, the amount when **returnsCount** is `true`, or `nil` when nothing matched

***

### Search

Searches an inventory. The return type depends on the first argument: `count` returns amounts, `slots` returns the matching item data.

```lua
local count = exports["tgiann-inventory"]:Search(src, "count", "bandage")
local slots = exports["tgiann-inventory"]:Search(src, "slots", "water")
local stashSlots = exports["tgiann-inventory"]:Search("police_stash", "slots", "water")
```

#### Parameters

* **src**: `number | string | table` player source, stash name or inventory reference
* **search**: `string` `count` or `slots`
* **item**: `string | string[]` item name or list of item names
* **metadata?**: `table` metadata to match
* **strict?**: `boolean` strict metadata matching, defaults to `true`

#### Returns

* `number | table` a single value when one item name is given, otherwise a table keyed by item name

***

### GetSlotsByItem

Returns the slots of an item inside a given item list. It works on a plain item table, not on a live inventory.

```lua
local items = exports["tgiann-inventory"]:GetPlayerItems(src)
local slots = exports["tgiann-inventory"]:GetSlotsByItem(items, "bandage")
```

#### Parameters

* **items**: `table` item list
* **itemName**: `string` item name

#### Returns

* `table` list of slots

***

### GetFirstSlotByItem

Returns the first slot of an item inside a given item list.

```lua
local items = exports["tgiann-inventory"]:GetPlayerItems(src)
local slot = exports["tgiann-inventory"]:GetFirstSlotByItem(items, "bandage")
```

#### Parameters

* **items**: `table` item list
* **itemName**: `string` item name

#### Returns

* `string?` slot id, `nil` when the item is not in the list

***

### GetTotalWeight

Returns the total weight of an item list. Metadata weight overrides the item list weight.

```lua
local items = exports["tgiann-inventory"]:GetPlayerItems(src)
local weight = exports["tgiann-inventory"]:GetTotalWeight(items)
```

#### Parameters

* **items**: `table` item list

#### Returns

* `number` total weight

***

### GetFreeWeight

Returns the remaining free weight of the player's inventory.

```lua
local freeWeight = exports["tgiann-inventory"]:GetFreeWeight(src)
```

#### Parameters

* **src**: `number` player source

#### Returns

* `number` free weight, `0` when the inventory is not loaded

***

### CanCarryItem

Checks whether an inventory can carry the given amount of an item. Extra names: `CanAddItem` (QB) and `CanGiveItems` (old name). A metadata table in the 4th argument (Ox Inventory order) is ignored.

```lua
if exports["tgiann-inventory"]:CanCarryItem(src, "bandage", 100) then
    exports["tgiann-inventory"]:AddItem(src, "bandage", 100)
end
```

#### Parameters

* **src**: `number | string | table` player source, stash name or inventory reference
* **item**: `string` item name
* **amount**: `number` amount to check
* **removeWeight?**: `number` weight that will be removed from the inventory before the check

#### Returns

* `boolean` whether the item fits

***

### CanCarryItems

Checks whether the player can carry several items at once.

```lua
local items = {
    { name = "bandage", amount = 3 },
    { name = "gold", amount = 1 },
}
if exports["tgiann-inventory"]:CanCarryItems(src, items) then
    for i = 1, #items do
        exports["tgiann-inventory"]:AddItem(src, items[i].name, items[i].amount)
    end
end
```

#### Parameters

* **src**: `number` player source
* **items**: `table` list of `{ name: string, amount: number }`
* **removeWeight?**: `number` weight that will be removed from the inventory before the check

#### Returns

* `boolean` whether all items fit

***

### CanCarryWeight

Checks whether an inventory can carry the given weight.

```lua
local canCarry = exports["tgiann-inventory"]:CanCarryWeight(src, 5000)
```

#### Parameters

* **src**: `number | string | table` player source, stash name or inventory reference
* **weight**: `number` weight to check

#### Returns

* `boolean` whether the weight fits

***

### CanCarryAmount

Returns how many of an item still fit into an inventory by weight. Weightless items return `math.huge`.

```lua
local amount = exports["tgiann-inventory"]:CanCarryAmount(src, "bandage")
```

#### Parameters

* **inv**: `number | string | table` player source, stash name or inventory reference
* **item**: `string | table` item name or item data containing a `name` field

#### Returns

* `number?` amount that fits, `nil` when the inventory or item does not exist

***

### CanSwapItem

Checks whether removing some of one item and adding another keeps the inventory under its weight limit.

```lua
local canSwap = exports["tgiann-inventory"]:CanSwapItem(src, "bandage", 5, "medikit", 1)
```

#### Parameters

* **inv**: `number | string | table` player source, stash name or inventory reference
* **firstItem**: `string` item that leaves the inventory
* **firstItemCount**: `number` amount of the first item
* **testItem**: `string` item that enters the inventory
* **testItemCount**: `number` amount of the test item

#### Returns

* `boolean?` whether the swap fits, `nil` when the player does not have enough of the first item

***

### HasCraftItems

Checks whether the player has all ingredients of a recipe and returns the data needed to remove them.

```lua
local costItems = { bandage = 2, metalscrap = 5 }
local hasItems, removeData = exports["tgiann-inventory"]:HasCraftItems(src, costItems, 1)
```

#### Parameters

* **src**: `number` player source
* **CostItems**: `table<string, number>` item name to required amount map
* **amount**: `number` how many times the recipe is crafted, the costs are multiplied by it

#### Returns

* `boolean` whether every ingredient is available
* `table` list of `{ slot, removeAmount, name }` for each ingredient, empty when something is missing

***

### UpdateItemMetadata

Updates the metadata of an item in a slot. The slot is only updated when the item name in that slot matches. Old name: `SetItemData`.

```lua
local itemData = exports["tgiann-inventory"]:GetItemByName(src, "weapon_pistol")
exports["tgiann-inventory"]:UpdateItemMetadata(src, "weapon_pistol", itemData.slot, { ammo = 200 })
```

#### Parameters

* **src**: `number` player source
* **item**: `string` item name
* **slot**: `number` slot id
* **info**: `table` the new metadata

***

### SetMetadata

Replaces the metadata of the item in a slot without checking the item name. Works on any inventory reference.

```lua
exports["tgiann-inventory"]:SetMetadata(src, 3, { quality = 50 })
exports["tgiann-inventory"]:SetMetadata("police_stash", 1, { quality = 50 })
```

#### Parameters

* **inv**: `number | string | table` player source, stash name or inventory reference
* **slotId**: `number` slot id
* **metadata**: `table` the new metadata

***

### SetDurability

Sets the `durabilityPercent` metadata of the item in a slot, clamped between `0` and `100`.

```lua
exports["tgiann-inventory"]:SetDurability(src, 3, 75)
```

#### Parameters

* **inv**: `number | string | table` player source, stash name or inventory reference
* **slotId**: `number` slot id
* **durability**: `number` new durability percent

***

### RepairWeapon

Sets the durability of a weapon in a slot and increases its repair counter.

```lua
exports["tgiann-inventory"]:RepairWeapon(src, slot, 100)
```

#### Parameters

* **src**: `number` player source
* **key**: `number` slot id of the weapon
* **percent?**: `number` new durability, clamped between `0` and `100`, defaults to `100`

#### Returns

* `boolean?` `true` when the weapon was repaired

***

### GetSlot

Returns the item in a slot of any inventory. Unlike `GetItemBySlot` it returns `nil` for an empty slot.

```lua
local itemData = exports["tgiann-inventory"]:GetSlot("police_stash", 1)
```

#### Parameters

* **inv**: `number | string | table` player source, stash name or inventory reference
* **slotId**: `number` slot id

#### Returns

* `table?` item data, `nil` when the slot is empty

***

### GetSlotWithItem

Returns the first matching item slot data of any inventory. Ox Inventory name for `GetItemByName`, but it returns `nil` instead of `{ amount = 0 }` when nothing matches.

```lua
local itemData = exports["tgiann-inventory"]:GetSlotWithItem(src, "bandage")
```

#### Parameters

* **inv**: `number | string | table` player source, stash name or inventory reference
* **itemName**: `string` item name
* **metadata?**: `table` metadata to match
* **strict?**: `boolean` strict metadata matching, defaults to `true`

#### Returns

* `table?` item data, `nil` when not found

***

### GetSlotsWithItem

Returns every matching item slot data of any inventory.

```lua
local items = exports["tgiann-inventory"]:GetSlotsWithItem(src, "bandage")
```

#### Parameters

* **inv**: `number | string | table` player source, stash name or inventory reference
* **itemName**: `string` item name
* **metadata?**: `table` metadata to match
* **strict?**: `boolean` strict metadata matching, defaults to `true`

#### Returns

* `table?` list of item data, `nil` when nothing matches

***

### GetSlotIdWithItem

Returns the slot id of the first matching item in any inventory.

```lua
local slot = exports["tgiann-inventory"]:GetSlotIdWithItem(src, "bandage")
```

#### Parameters

* **inv**: `number | string | table` player source, stash name or inventory reference
* **itemName**: `string` item name
* **metadata?**: `table` metadata to match
* **strict?**: `boolean` strict metadata matching, defaults to `true`

#### Returns

* `number?` slot id, `nil` when not found

***

### GetSlotIdsWithItem

Returns every slot id holding the given item in any inventory.

```lua
local slots = exports["tgiann-inventory"]:GetSlotIdsWithItem(src, "bandage")
```

#### Parameters

* **inv**: `number | string | table` player source, stash name or inventory reference
* **itemName**: `string` item name
* **metadata?**: `table` metadata to match
* **strict?**: `boolean` strict metadata matching, defaults to `true`

#### Returns

* `table?` list of slot ids, `nil` when nothing matches

***

### GetItemSlots

Returns the slots holding an item together with the amount in each slot, the total amount and the number of empty slots.

```lua
local slots, totalCount, emptySlots = exports["tgiann-inventory"]:GetItemSlots(src, "bandage")
-- slots = { [3] = 5, [7] = 2 }
```

#### Parameters

* **inv**: `number | string | table` player source, stash name or inventory reference
* **item**: `string | table` item name or item data containing a `name` field
* **metadata?**: `table` metadata to match
* **strict?**: `boolean` strict metadata matching, defaults to `true`

#### Returns

* `table<number, number>?` slot id to amount map
* `number?` total amount
* `number?` empty slot count

***

### GetEmptySlot

Returns the first free cell of an inventory. A free cell does not mean a bigger item fits there, use `GetSlotForItem` for that.

```lua
local slot = exports["tgiann-inventory"]:GetEmptySlot(src)
```

#### Parameters

* **inv**: `number | string | table` player source, stash name or inventory reference

#### Returns

* `number?` slot id, `nil` when the inventory is full or does not exist

***

### GetSlotForItem

Returns the slot an item would be added to: a slot that already holds the same item and is not at its max stack, otherwise the first place on the grid where the whole item fits (turned if only that way fits).

```lua
local slot = exports["tgiann-inventory"]:GetSlotForItem(src, "bandage", { level = 2 })
```

#### Parameters

* **inv**: `number | string | table` player source, stash name or inventory reference
* **itemName**: `string` item name
* **metadata?**: `table` metadata the existing stack must match

#### Returns

* `number?` slot id (top left cell), `nil` when nothing fits

***

### SwapSlots

Swaps the items of two slots. The slots can belong to two different inventories, and one of them can be empty to move an item instead of swapping. Each item lands with its top left cell on the other slot, the swap fails when an item does not fit there.

```lua
local success = exports["tgiann-inventory"]:SwapSlots(src, "police_stash", 1, 5)
```

#### Parameters

* **fromInv**: `number | string | table` first inventory reference
* **toInv**: `number | string | table` second inventory reference
* **slot1**: `number` slot in the first inventory
* **slot2**: `number` slot in the second inventory

#### Returns

* `boolean` whether the swap was applied

***

### GiveClotheItem

Creates a clothing item with the given components and gives it to the player. With **isClotheSlot** it goes straight into the clothing inventory and is worn immediately.

```lua
exports["tgiann-inventory"]:GiveClotheItem(src, model, itemName, data, isClotheSlot)
```

#### Parameters

* **src**: `number` player source
* **model**: `number` ped model hash, `joaat("mp_m_freemode_01")` or `joaat("mp_f_freemode_01")`
* **itemName**: `string` clothing item name, see the list below
* **data**: `table` array of clothing components, see the structure below
* **isClotheSlot?**: `boolean` put the item in the clothing slot and wear it right away

**Valid `itemName` values**

* `c_mask` — Mask (component 1)
* `c_helmet` — Helmet / Hat (prop 0)
* `c_glasses` — Glasses (prop 1)
* `c_watch` — Watch (prop 6)
* `c_bracelet` — Bracelet (prop 7)
* `c_bproof` — Body Armor (component 9)
* `c_necklace` — Necklace (component 7)
* `c_ear` — Earring (prop 2)
* `c_torso` — Torso: top (component 11), arms (component 3), undershirt (component 8)
* `c_bag` — Bag (component 5)
* `c_pants` — Pants (component 4)
* `c_shoes` — Shoes (component 6)
* `c_decal` — Decal (component 10)

Each element of **data** follows this structure:

```lua
local exampleDataEntry = {
    category = "component", -- "component" or "prop"
    id = 6,                 -- GTA component/prop id
    data = {
        collection = "",    -- collection name (often an empty string, can be a DLC name)
        index = 1,          -- drawable index
        texture = 0,        -- texture / colour id
    }
}
```

**Examples**

```lua
-- Give shoes to the player inventory
exports["tgiann-inventory"]:GiveClotheItem(
    source,
    GetEntityModel(GetPlayerPed(source)),
    "c_shoes",
    {
        { category = "component", id = 6, data = { collection = "", index = 1, texture = 0 } }
    },
    false
)

-- Give pants and wear them immediately
exports["tgiann-inventory"]:GiveClotheItem(
    source,
    GetEntityModel(GetPlayerPed(source)),
    "c_pants",
    {
        { category = "component", id = 4, data = { collection = "", index = 7, texture = 0 } }
    },
    true
)

-- Give a torso (up to 3 components: torso, arms, undershirt)
exports["tgiann-inventory"]:GiveClotheItem(
    source,
    GetEntityModel(GetPlayerPed(source)),
    "c_torso",
    {
        { category = "component", id = 11, data = { collection = "Male_freemode_valentines", index = 2, texture = 1 } },
        { category = "component", id = 3,  data = { collection = "", index = 0, texture = 0 } },
        { category = "component", id = 8,  data = { collection = "", index = 15, texture = 0 } },
    },
    true
)

-- Give a helmet (prop item)
exports["tgiann-inventory"]:GiveClotheItem(
    source,
    GetEntityModel(GetPlayerPed(source)),
    "c_helmet",
    {
        { category = "prop", id = 0, data = { collection = "", index = 45, texture = 0 } }
    },
    false
)
```

***

### AddClotheDirt

Adds dirt to the clothes the player wears. It only works when `config.clotheDirt.active` is enabled.

```lua
exports["tgiann-inventory"]:AddClotheDirt(src, 10)
exports["tgiann-inventory"]:AddClotheDirt(src, 25, "c_shoes")
exports["tgiann-inventory"]:AddClotheDirt(src, 5, nil, { min = 1, max = 3 })
```

#### Parameters

* **src**: `number` player source
* **amount**: `number` dirt percent to add, the total is capped at `100`
* **clotheFilter?**: `string | string[]` only dirty these clothing items, every worn item when omitted
* **randomClotheAmount?**: `table` `{ min: number, max: number }` dirty only this many randomly picked worn items

***

### SetPlayerClotheDirt

Sets the dirt percent of the player's clothes to an exact value. It only works when `config.clotheDirt.active` is enabled.

```lua
local success, count = exports["tgiann-inventory"]:SetPlayerClotheDirt(src, 0, "all")
```

#### Parameters

* **src**: `number` player source
* **percent**: `number` new dirt percent, clamped between `0` and `100`
* **target?**: `string` `clothe` worn clothes (default), `player` main inventory, `all` both

#### Returns

* `boolean` success, `false` when the clothe dirt system is disabled
* `number?` amount of updated clothing items

***

### OpenInventory

Opens an inventory for a player. The player's own inventory is always sent along with the requested one.

Stash ownership follows the Ox Inventory logic through `invData.owner`: `true` gives every player their own copy of the stash (stored as `name:citizenid`), a `string` opens the stash of that citizenid, and `nil` opens a shared stash. When the stash was registered with `owner = true`, a citizenid string in `invData.owner` opens another player's stash (police searching a locker, for example). When `config.needRegisterStash` is enabled, opening a stash that was not registered with `RegisterStash` throws an error.

```lua
exports["tgiann-inventory"]:OpenInventory(src, "stash", "gang12", {
    maxWeight = 10000,
    slots = 10,
    whitelist = { "bandage", "item2" },
    label = "Gang Stash",
    maxAmount = { bandage = 5 },
    jobs = "police",
    coords = vector3(0.0, 100.0, 20.0)
})

exports["tgiann-inventory"]:OpenInventory(src, "stash", "motel_locker", { slots = 20, owner = true })
exports["tgiann-inventory"]:OpenInventory(src, "stash", { id = "motel_locker", owner = "ABC12345" })
exports["tgiann-inventory"]:OpenInventory(src, "otherplayer", targetSrc, { showClothe = false })
exports["tgiann-inventory"]:OpenInventory(src, "trunk", "PLATE123")
```

#### Parameters

* **source**: `number` player source
* **invType?**: `string` `glovebox` | `trunk` | `stash` | `shop` | `drop` | `crafting` | `otherplayer`. `player` with a target id is treated as `otherplayer`
* **invId**: `string | number | table` inventory name, plate or target player server id. Stashes also accept `{ id = "name", owner = true | "citizenid" }`
* **invData?**: `table` `{ maxWeight?: number, slots?: number, whitelist?: string[], blacklist?: string[], label?: string, maxAmount?: table, jobs?: string | string[], coords?: vector3 | vector3[], owner?: boolean | string, showClothe?: boolean }`. **showClothe** (default `true`) also sends the clothing inventory when opening another player
* **legacyOpenType?**: `table` old `{ showClothe, isPlayer }` table, still accepted and merged into **invData**. Use **invData** instead
* **force?**: `boolean` skip the open checks (job, distance, `config.searchPlayer`)

***

### ForceOpenInventory

Same as `OpenInventory` with **force** set to `true`: job, distance and search checks are skipped. It was added for Ox Inventory conversions.

```lua
exports["tgiann-inventory"]:ForceOpenInventory(src, "stash", "gang12", { slots = 10, maxWeight = 10000 })
exports["tgiann-inventory"]:ForceOpenInventory(src, "stash", { id = "motel_locker", owner = "ABC12345" })
```

#### Parameters

* **src**: `number` player source
* **invType**: `string` inventory type
* **invId**: `string | number | table` inventory name, plate, target player server id or `{ id, owner }`
* **invData?**: `table` inventory data, same fields as `OpenInventory`

***

### OpenInventoryById

Opens another player's inventory. The `config.searchPlayer` checks (weapon in hand, target animation, dead player) still apply.

```lua
exports["tgiann-inventory"]:OpenInventoryById(src, targetSrc, true)
```

#### Parameters

* **src**: `number` player source
* **targetSrc**: `number` target player source
* **showClothe?**: `boolean` also show the target's clothing inventory, defaults to `true`

***

### ForceOpenInventoryById

Opens another player's inventory while ignoring the `config.searchPlayer` checks.

```lua
exports["tgiann-inventory"]:ForceOpenInventoryById(src, targetSrc, true)
```

#### Parameters

* **src**: `number` player source
* **targetSrc**: `number` target player source
* **showClothe?**: `boolean` also show the target's clothing inventory, defaults to `true`

***

### OpenNearbyInventory

Opens the inventory of the closest player within `config.openMaxDistance.player`. The `config.searchPlayer` checks apply. An error notification is shown when nobody is nearby.

```lua
exports["tgiann-inventory"]:OpenNearbyInventory(src)
```

#### Parameters

* **src**: `number` player source

***

### InspectInventory

Opens an inventory for a player without any checks. A number opens that player's inventory with clothes, a string opens the stash with that name.

```lua
exports["tgiann-inventory"]:InspectInventory(src, targetSrc)
exports["tgiann-inventory"]:InspectInventory(src, "police_stash")
```

#### Parameters

* **playerId**: `number` player source
* **invId**: `number | string` target player source or stash name

***

### SetStashTarget

Makes the inventory key of a player open the given stash instead of their own inventory until it is cleared. Call it with `nil` to clear it. Same as the client export, but triggered from the server.

```lua
exports["tgiann-inventory"]:SetStashTarget(src, "motel_locker", true)
exports["tgiann-inventory"]:SetStashTarget(src, nil)
```

#### Parameters

* **src**: `number` player source
* **id?**: `string` stash name, `nil` clears the target
* **owner?**: `boolean | string` stash owner, see `OpenInventory`

***

### CloseInventory

Closes every inventory the player has open, on the server side.

```lua
exports["tgiann-inventory"]:CloseInventory(src)
```

#### Parameters

* **src**: `number` player source

***

### OpenShop

Opens a shop defined in `configShop.lua` or registered with `RegisterShop`.

```lua
exports["tgiann-inventory"]:OpenShop(src, "market_1")
```

#### Parameters

* **src**: `number` player source
* **name**: `string` shop name, the key inside `config.Products`

***

### OpenCraft

Opens a crafting menu.

```lua
exports["tgiann-inventory"]:OpenCraft(src, "defaultCraft")
```

#### Parameters

* **src**: `number` player source
* **name**: `string` crafting category name

***

### RegisterShop

Registers or overwrites a shop at runtime. Without **details** the shop is a plain product list: the title is the shop name, there are no category buttons and the player picks cash or bank at checkout. With **details** you get a title, subtitle, category buttons and an optional forced payment method. The Ox Inventory shop table `{ name, inventory = { { name, price, count } } }` is also accepted as the second argument.

```lua
local items = {
    { name = "beer",    price = 7,  amount = 50, type = "item" },
    { name = "whiskey", price = 10, amount = 50, type = "item" },
}
exports["tgiann-inventory"]:RegisterShop("policeshop2", items)

exports["tgiann-inventory"]:RegisterShop("policeshop3", {
    { name = "weapon_pistol", price = 2500, amount = 10, type = "weapon", category = "weapons" },
    { name = "pistol_ammo",   price = 250,  amount = 50, type = "item",   category = "ammo" },
}, {
    label = { en = "Police Armory", tr = "Polis Cephaneleği" },
    subtitle = "Store",
    paymentMethod = "bank", -- optional, forces bank at checkout
    categories = {
        { key = "weapons", label = "Weapons", icon = "gun" },
        { key = "ammo",    label = "Ammo",    icon = "box" },
    },
})
```

#### Parameters

* **shopName**: `string` unique shop name
* **items**: `table` product list, see `configShop.lua` for the product fields
* **details?**: `table` `{ label?: string | table, subtitle?: string | table, paymentMethod?: "cash" | "bank", categories?: { key: string, label: string | table, icon?: string }[] }`

***

### CreateShop

QB compatible shop registration. It accepts a single shop table or a table containing several shops.

```lua
exports["tgiann-inventory"]:CreateShop({
    name = "policeshop2",
    items = {
        { name = "beer", price = 7, amount = 50, type = "item" },
    }
})
```

#### Parameters

* **shopData**: `table` `{ name: string, items: table }`, or a table of such entries

***

### RegisterStash

Registers a stash. It does nothing when a stash with the same name is already registered. It accepts a data table or the Ox Inventory positional arguments.

The **owner** field decides how the stash is shared: `nil` creates one shared stash right away, `true` creates a separate stash for every player who opens it (stored as `name:citizenid`), and a `string` binds the stash to that citizenid. Owner stashes are created the first time they are opened. Existing rows saved with the old `name_citizenid` naming are migrated automatically.

```lua
exports["tgiann-inventory"]:RegisterStash({
    name = "police_stash",
    label = "Police Stash",
    slots = 50,
    maxWeight = 100000,
    jobs = "police",
    coords = vector3(441.7, -981.2, 30.6),
    blacklist = { "weapon_pistol" },
})

exports["tgiann-inventory"]:RegisterStash({ name = "motel_locker", label = "Locker", slots = 20, maxWeight = 50000, owner = true })

exports["tgiann-inventory"]:RegisterStash("police_stash", "Police Stash", 50, 100000, nil, { police = 0 })
```

#### Parameters

* **data**: `table | string` stash data table, or the stash name when positional arguments are used
* **label?**: `string` inventory label
* **slots?**: `number` slot amount
* **maxWeight?**: `number` maximum weight
* **owner?**: `boolean | string` `true` one stash per player, `string` fixed owner, `nil` shared
* **groups?**: `string | string[] | table<string, number>` jobs that can open the stash. An Ox Inventory group map such as `{ police = 0 }` is converted to a job list
* **coords?**: `vector3 | vector3[]` stash coords, used for the distance check

Fields of the data table: `name`, `label`, `slots`, `maxWeight`, `blacklist`, `whitelist`, `jobs` (or `groups`), `coords`, `maxAmount`, `owner`.

#### Returns

* `table?` the created inventory object for shared stashes, `nil` for owner stashes or when the stash already exists

***

### CreateTemporaryStash

Creates a stash that is never written to the database and disappears on restart. Useful for search results, loot containers and similar short lived inventories.

```lua
local stashId = exports["tgiann-inventory"]:CreateTemporaryStash({
    label = "Loot",
    slots = 10,
    maxWeight = 20000,
    items = {
        { name = "bandage", count = 2 },
        { name = "water", count = 1, metadata = { quality = 50 } },
    }
})
exports["tgiann-inventory"]:OpenInventory(src, "stash", stashId)
```

#### Parameters

* **properties**: `table` `{ label?: string, slots?: number, maxWeight?: number, items?: { name: string, count?: number, metadata?: table }[] }`

#### Returns

* `string?` the stash id to open it with

***

### CreateInventory

Creates an inventory object directly. `RegisterStash`, `OpenInventory` and `GetInventory` use it internally; use it only when you need low level access.

```lua
local inv = exports["tgiann-inventory"]:CreateInventory("airdrop_1", "stash", { slots = 10, maxweight = 20000, label = "Airdrop" })
```

#### Parameters

* **invId**: `string | number` inventory id, name, plate or player source
* **invType**: `string` `player` | `playerclothe` | `playerrealisticarmor` | `stash` | `trunk` | `glovebox` | `drop` | `shop` | `crafting`
* **invData?**: `table` `{ slots?: number, maxweight?: number, label?: string, whitelist?, blacklist?, jobs?, coords?, maxAmount?, bucket?, owner?, temporary? }`
* **src?**: `number` player source, used for player bound inventory types

#### Returns

* `table` the inventory object, containing `Items` and `Functions`

***

### GetInventory

Returns an inventory object. It creates the inventory when it does not exist yet, except for stashes when `config.needRegisterStash` is enabled. Player inventories return `nil` until the player's data is loaded. Ox Inventory name: `Inventory`.

```lua
local inv = exports["tgiann-inventory"]:GetInventory(src, "player")
local stash = exports["tgiann-inventory"]:GetInventory("airdrop_1", "stash")
local locker = exports["tgiann-inventory"]:GetInventory({ id = "motel_locker", owner = "ABC12345" })
local sameLocker = exports["tgiann-inventory"]:Inventory("motel_locker", "ABC12345")
```

#### Parameters

* **invId**: `string | number | table` inventory id, name, plate, player source or `{ id, type?, owner? }`
* **invType?**: `string` inventory type. Defaults to `player` for a number and `stash` for a string
* **invData?**: `table` inventory data used when the inventory has to be created, `owner` resolves owner stashes
* **src?**: `number` player source, required for `shop` and `crafting` inventories and to resolve `owner = true`

#### Returns

* `table?` the inventory object, `nil` when it does not exist and cannot be created

***

### GetInventoryItems

Returns the items of any inventory reference.

```lua
local items = exports["tgiann-inventory"]:GetInventoryItems("motel_locker", "ABC12345")
```

#### Parameters

* **inv**: `number | string | table` player source, stash name or inventory reference
* **owner?**: `boolean | string` stash owner

#### Returns

* `table?` slot indexed item list, `nil` when the inventory does not exist

***

### GetInventories

Returns every loaded inventory of a type.

```lua
local stashIds = exports["tgiann-inventory"]:GetInventories("stash")
local stashes = exports["tgiann-inventory"]:GetInventories("stash", true)
```

#### Parameters

* **invType**: `string` inventory type
* **detailed?**: `boolean` return the inventory objects instead of only their ids

#### Returns

* `table` list of ids or inventory objects

***

### GetSecondaryInventoryItems

Returns the items of a stash, trunk or glovebox.

```lua
local items = exports["tgiann-inventory"]:GetSecondaryInventoryItems("stash", "airdrop_01")
```

#### Parameters

* **invType**: `string` `stash`, `trunk` or `glovebox`
* **id**: `string` inventory name or plate

#### Returns

* `table | false` item list, `false` when the inventory does not exist

***

### GetItemByNameFromSecondInventory

Returns an item from a stash, trunk or glovebox. Extra name: `GetItemByNameFromSecondaryInventory`.

```lua
local itemData = exports["tgiann-inventory"]:GetItemByNameFromSecondInventory("stash", "airdrop_01", "bandage")
```

#### Parameters

* **invType**: `string` `stash`, `trunk` or `glovebox`
* **id**: `string` inventory name or plate
* **item**: `string` item name
* **metadata?**: `table` metadata to match

#### Returns

* `table` item data, or `{ amount = 0 }` when the item is not found

***

### AddItemFromSecondInventory

Adds an item to a stash, trunk or glovebox. Extra name: `AddItemToSecondaryInventory`.

```lua
local success = exports["tgiann-inventory"]:AddItemFromSecondInventory("stash", "airdrop_01", "bandage", 1)
```

#### Parameters

* **invType**: `string` `stash`, `trunk` or `glovebox`
* **id**: `string` inventory name or plate
* **item**: `string` item name
* **amount**: `number` amount to add
* **slot?**: `number` target slot
* **metadata?**: `table` item metadata

#### Returns

* `boolean` success

***

### RemoveItemFromSecondInventory

Removes an item from a stash, trunk or glovebox. Extra name: `RemoveItemFromSecondaryInventory`.

```lua
local success = exports["tgiann-inventory"]:RemoveItemFromSecondInventory("stash", "airdrop_01", "bandage", 1)
```

#### Parameters

* **invType**: `string` `stash`, `trunk` or `glovebox`
* **id**: `string` inventory name or plate
* **item**: `string` item name
* **amount**: `number` amount to remove
* **slot?**: `number` slot to remove from
* **metadata?**: `table` metadata to match

#### Returns

* `boolean` success
* `table?` metadata of the removed item

***

### CreateCustomStashWithItem

Creates a stash inventory pre-filled with items.

```lua
-- Server
local items = {
    { name = "bandage", amount = 2 },
    { name = "weapon_pistol", amount = 1, info = { ammo = 500, serie = "ABC123", usedTotalAmmo = 0, durabilityPercent = 100 } },
}
exports["tgiann-inventory"]:CreateCustomStashWithItem("airdrop_1", items)

-- Client
exports["tgiann-inventory"]:OpenInventory("stash", "airdrop_1")
```

#### Parameters

* **id**: `string` unique stash name
* **items**: `table` list of `{ name: string, amount: number, info?: table }`

***

### DeleteInventory

Deletes an inventory and its saved data.

```lua
exports["tgiann-inventory"]:DeleteInventory("stash", "airdrop_01")
exports["tgiann-inventory"]:DeleteInventory("glovebox", "TL001TL")
```

#### Parameters

* **invType**: `string` `stash`, `trunk` or `glovebox`
* **invId**: `string` inventory name or plate

#### Returns

* `boolean?` `true` when the inventory was deleted

***

### RemoveInventory

Saves an inventory and unloads it from memory. Unlike `DeleteInventory` the database row is kept, the inventory is loaded again the next time it is opened.

```lua
exports["tgiann-inventory"]:RemoveInventory("airdrop_01")
```

#### Parameters

* **inv**: `number | string | table` player source, stash name or inventory reference

#### Returns

* `boolean?` `true` when the inventory was unloaded

***

### ConfiscateInventory

Moves every item of the player into a confiscation stash (`confiscated_<citizenid>`) and clears their inventory. Give the items back with `ReturnInventory`.

```lua
exports["tgiann-inventory"]:ConfiscateInventory(src)
```

#### Parameters

* **src**: `number` player source

#### Returns

* `boolean?` `true` when the items were confiscated

***

### ReturnInventory

Gives the items confiscated with `ConfiscateInventory` back to the player and deletes the confiscation stash.

```lua
exports["tgiann-inventory"]:ReturnInventory(src)
```

#### Parameters

* **src**: `number` player source

#### Returns

* `boolean?` `true` when the items were returned

***

### UpdateVehicle

Moves the trunk and glovebox inventories of a vehicle to a new plate.

```lua
local result = exports["tgiann-inventory"]:UpdateVehicle("OLD123", "NEW456")
-- result = { trunkUpdated = true, gloveboxUpdated = false }
```

#### Parameters

* **oldPlate**: `string` current plate
* **newPlate**: `string` new plate

#### Returns

* `table` `{ trunkUpdated: boolean, gloveboxUpdated: boolean }`

***

### CustomDrop

Creates a ground drop filled with the given items.

```lua
local items = {
    { name = "bandage", amount = 2 },
    { name = "water", amount = 1, info = { quality = 50 } },
}
exports["tgiann-inventory"]:CustomDrop("airdrop", items, vector3(0.0, 0.0, 72.0), 10, 20000)
```

#### Parameters

* **prefix**: `string` drop id prefix
* **items**: `table` list of `{ name: string, amount|count: number, info|metadata?: table }`
* **coords**: `vector3` drop coords
* **slots**: `number` slot amount
* **maxWeight**: `number` maximum weight
* **bucket?**: `number` routing bucket the drop is visible in

#### Returns

* `boolean?` `true` when the drop was created

***

### CreateDropFromPlayer

Moves every item of an online player into a new ground drop and clears their inventory.

```lua
exports["tgiann-inventory"]:CreateDropFromPlayer(src)
```

#### Parameters

* **source**: `number` player source

#### Returns

* `boolean?` `true` when the drop was created

***

### CreateDropFromPlayerId

Same as `CreateDropFromPlayer`, but it takes a citizenid/identifier. When the player is offline, the items are read from the database and their saved inventory is emptied.

```lua
exports["tgiann-inventory"]:CreateDropFromPlayerId("ABC12345", vector3(0.0, 0.0, 72.0))
```

#### Parameters

* **citizenid**: `string` citizenid / identifier
* **coords?**: `vector3` drop coords
* **bucket?**: `number` routing bucket the drop is visible in

#### Returns

* `boolean?` `true` when the drop was created

***

### GetCurrentWeapon

Returns the inventory item of the weapon the player currently holds.

```lua
local weaponItem = exports["tgiann-inventory"]:GetCurrentWeapon(src)
```

#### Parameters

* **src**: `number` player source

#### Returns

* `table?` weapon item data, `nil` when the player is unarmed

***

### LoadInventory

Returns the player's saved items. It exists for framework bridges. Ox Inventory name: `SetPlayerInventory`, which also accepts the framework player object.

```lua
PlayerData.items = exports["tgiann-inventory"]:LoadInventory(src)
```

#### Parameters

* **src**: `number` player source

#### Returns

* `table` item list

***

### SaveInventory

Saves the player's inventory to the database.

```lua
exports["tgiann-inventory"]:SaveInventory(src)
```

#### Parameters

* **src**: `number` player source

***

### SetInventory

Overwrites the player's whole item list.

```lua
exports["tgiann-inventory"]:SetInventory(src, items)
```

#### Parameters

* **src**: `number` player source
* **items**: `table` new item list

***

### SaveAllInventory

Saves every inventory that has pending changes and deletes expired drops. The script already runs this on a timer defined by `config.inventorySaveTime`.

```lua
exports["tgiann-inventory"]:SaveAllInventory()
```

***

### SetMaxWeight

Sets the maximum weight of an inventory at runtime. It is not saved to the database.

```lua
exports["tgiann-inventory"]:SetMaxWeight(src, 200000)
exports["tgiann-inventory"]:SetMaxWeight("police_stash", 500000)
```

#### Parameters

* **src**: `number | string | table` player source, stash name or inventory reference
* **maxweight**: `number` new maximum weight

***

### SetSlotCount

Sets the slot amount of an inventory at runtime and refreshes the UI of everyone who has it open. It is not saved to the database.

```lua
exports["tgiann-inventory"]:SetSlotCount(src, 60)
```

#### Parameters

* **inv**: `number | string | table` player source, stash name or inventory reference
* **slots**: `number` new slot amount

***

### SetInventoryCapacity

Sets the slot (cell) amount and the max weight of any inventory at runtime, open UIs see the change right away. Pass `nil` to keep one of them.

```lua
exports["tgiann-inventory"]:SetInventoryCapacity("police_stash", 120, 500000)
exports["tgiann-inventory"]:SetInventoryCapacity(src, nil, 150000)
```

#### Parameters

* **inv**: `number | string | table` player source, stash name or inventory reference
* **slots?**: `number` new cell amount
* **maxWeight?**: `number` new max weight (grams)

#### Returns

* `boolean?` `true` when the inventory was found

***

### SetPlayerBackPackLvl

Sets the player's backpack level, which defines the slot and weight limits from `config.backpack`. The level is saved to the database.

```lua
local success = exports["tgiann-inventory"]:SetPlayerBackPackLvl(src, 2)
```

#### Parameters

* **src**: `number` player source
* **lvl**: `number` backpack level, the index inside `config.backpack`

#### Returns

* `boolean?` `true` when the level was applied

***

### GetPlayerInventoryData

Returns the player's slot and weight limits with the backpack level, including the extra slots/weight granted by a clothing backpack.

```lua
local data = exports["tgiann-inventory"]:GetPlayerInventoryData(src)
-- data = { slots = 50, maxweight = 120000, backpackLvl = 1 }
```

#### Parameters

* **src**: `number | table` player source or the framework player object
* **pInventoryData?**: `table` inventory object, read again from the cache when omitted

#### Returns

* `table` `{ slots: number, maxweight: number, backpackLvl: number }`

***

### UseItem

Runs the usable item callback registered by the framework (`ESX.RegisterUsableItem` / `QBCore.Functions.CreateUseableItem`).

```lua
exports["tgiann-inventory"]:UseItem(src, "bandage")
```

#### Parameters

* **src**: `number` player source
* **itemName**: `string` item name
* **...**: `any` extra arguments passed to the item callback

***

### IsDecayableItem

Returns the decay time of an item, or `false` when it does not decay. The value comes from the decay time of the item (admin panel or `decayTime` in `items.lua`), or the melee weapon break amount.

```lua
local decayTime = exports["tgiann-inventory"]:IsDecayableItem("bandage")
```

#### Parameters

* **itemName**: `string` item name

#### Returns

* `number | false` decay time in seconds, `false` when the item does not decay

***

### IsMoneyItem

Returns whether a framework money type is handled as an item, together with the item name. It always returns `false` when `config.moneyAsItem.active` is disabled.

```lua
local isMoneyItem, itemName = exports["tgiann-inventory"]:IsMoneyItem("cash")
```

#### Parameters

* **moneyType**: `string` framework money type, for example `cash` or `black_money`

#### Returns

* `boolean` whether the money type is an item
* `string?` the item name

***

### IsRealisticTrunkActive

Returns whether the realistic trunk (`config.realisticTrunk.active`) is on. With a vehicle it answers for that vehicle alone: the admin panel can keep single vehicles on the plain trunk inventory or take their trunk away.

```lua
local active = exports["tgiann-inventory"]:IsRealisticTrunkActive()
local activeForCar = exports["tgiann-inventory"]:IsRealisticTrunkActive("sultan")
```

#### Parameters

* **vehicle?**: `number | string` vehicle entity, model hash or model name

#### Returns

* `boolean` whether the realistic trunk is used

***

### GetTrunkSize

Returns the trunk box of a vehicle as the admin panel holds it (`/invadmin > Vehicles`), vehicles without their own box use `config.realisticTrunk.defaultArea`.

```lua
local size = exports["tgiann-inventory"]:GetTrunkSize("sultan")
print(size.width, size.length, size.height, size.liters)
```

#### Parameters

* **vehicle**: `number | string` vehicle entity, model hash or model name

#### Returns

* `table` `{ width, length, height: number (cm), liters: number, cubicMeters: number, meters: { x, y, z }, openBed: boolean, classic: boolean, noTrunk: boolean, slots?: number, maxWeight?: number, model: number }`. **classic** = the vehicle uses the plain trunk inventory, **slots** / **maxWeight** are `nil` when the vehicle class lists decide

***

### GetTrunkVolume

Returns only the volume of a vehicle's trunk.

```lua
local liters = exports["tgiann-inventory"]:GetTrunkVolume("sultan")
```

#### Parameters

* **vehicle**: `number | string` vehicle entity, model hash or model name

#### Returns

* `number` liters

***

### VehicleHasNoTrunk

Returns whether the admin panel took the trunk of this vehicle away, so it can not be opened at all.

```lua
local noTrunk = exports["tgiann-inventory"]:VehicleHasNoTrunk("sultan")
```

#### Parameters

* **vehicle**: `number | string` vehicle entity, model hash or model name

#### Returns

* `boolean` whether the vehicle has no trunk

***

### RegisterHook

Registers a hook that runs before an inventory action and can cancel it by returning `false`. Hooks of a resource are removed automatically when that resource stops.

```lua
local hookId = exports["tgiann-inventory"]:RegisterHook("swapItems", function(payload)
    if payload.fromInventory == "police_stash" then return false end
    return true
end, {
    itemFilter = { water = true },
    inventoryFilter = { "^police_" }
})
```

#### Parameters

* **event**: `string` `swapItems` | `createItem` | `usingItem` | `buyItem` | `openInventory` | `dropWhenDieCash` | `pickupItem` | `pickupCash`, payloads are on the Hooks page
* **cb**: `function` hook function, return `false` to cancel the action. The `createItem` hook can return a table to replace the item metadata
* **options?**: `table` `{ itemFilter?: table<string, boolean>, inventoryFilter?: string[], fromInventoryFilter?: string[], toInventoryFilter?: string[], typeFilter?: table<string, boolean>, print?: boolean }`

#### Returns

* `number` hook id, usable with `RemoveHooks`

***

### RemoveHooks

Removes the hooks registered by the calling resource. Passing an id removes only that hook.

```lua
exports["tgiann-inventory"]:RemoveHooks()
exports["tgiann-inventory"]:RemoveHooks(hookId)
```

#### Parameters

* **id?**: `number` hook id, every hook of the resource is removed when omitted

## Ox Inventory export names

These names exist so scripts written for Ox Inventory work without changes. They map onto the exports above.

| Ox Inventory                                                                                                                                               | tgiann-inventory                                    |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------- |
| `Inventory(inv, owner)`                                                                                                                                    | `GetInventory`                                      |
| `GetInventoryItems(inv, owner)`                                                                                                                            | `GetInventoryItems`                                 |
| `ItemList(name)`                                                                                                                                           | `Items` (Shared page)                               |
| `SetPlayerInventory(player)`                                                                                                                               | `LoadInventory`                                     |
| `forceOpenInventory(playerId, invType, data)`                                                                                                              | `ForceOpenInventory`, `data` can be `{ id, owner }` |
| `RegisterStash(name, label, slots, maxWeight, owner, groups, coords)`                                                                                      | `RegisterStash`                                     |
| `RegisterShop(name, { name, inventory })`                                                                                                                  | `RegisterShop`                                      |
| `AddItem(inv, item, count, metadata, slot, cb)`                                                                                                            | `AddItem`                                           |
| `RemoveItem(inv, item, count, metadata, slot)`                                                                                                             | `RemoveItem`                                        |
| `GetItemCount(inv, item, metadata, strict)`                                                                                                                | `GetItemCount`                                      |
| `SetMetadata`, `SetDurability`, `SetSlotCount`, `SetMaxWeight`                                                                                             | same names                                          |
| `GetSlot`, `GetSlotWithItem`, `GetSlotsWithItem`, `GetSlotIdWithItem`, `GetSlotIdsWithItem`, `GetItemSlots`, `GetEmptySlot`, `GetSlotForItem`, `SwapSlots` | same names                                          |
| `CanCarryItem`, `CanCarryWeight`, `CanCarryAmount`, `CanSwapItem`                                                                                          | same names                                          |
| `ConfiscateInventory`, `ReturnInventory`, `ClearInventory`, `RemoveInventory`, `InspectInventory`, `CreateTemporaryStash`, `GetInventories`                | same names                                          |
| `CustomDrop`, `CreateDropFromPlayer`, `UpdateVehicle`, `Search`, `GetItem`, `GetCurrentWeapon`, `registerHook`, `removeHooks`                              | same names                                          |

Not available: the pefcl money exports (`addCash`, `removeCash`, `getCash`, `getCards`, `giveCard`, `getBank`), the container item exports (`GetContainerFromSlot`, `setContainerProperties`), `ConvertItems` and `setGetPlayerNameMethod`.
