# Server

### Items

{% tabs %}
{% tab title="All Items" %}

```lua
exports['ak47_inventory']:Items()
```

{% endtab %}

{% tab title="Single Item" %}

```lua
exports['ak47_inventory']:Items('water')
```

{% endtab %}
{% endtabs %}

### AddItem

```lua
exports['ak47_inventory']:AddItem(inv, item, amount, slot, info, weight, expiretime)
```

* inv: `string` or `number`
  * player id or unique inventory identifier
* item: `string`
  * item name
* amount: `number`
  * amount of the item
* slot: `number` (optional)
  * slot value
* info: `table` (optional)
  * item metadata table
* weight: `number` (optional)
  * change the weight of this item
* expiretime: `number` (optional)
  * change expire time of this item

### RemoveItem

```lua
exports['ak47_inventory']:RemoveItem(inv, item, amount, slot, forceRemove)
```

* inv: `string` or `number`
  * player id or unique inventory identifier
* item: `string`
  * item name
* amount: `number`
  * amount of the item
* slot: `number` (optional)
  * slot value
* forceRemove: `boolean` (optional)
  * will remove permanent item also

### GetItem <a href="#getitem" id="getitem"></a>

```lua
exports['ak47_inventory']:GetItem(inv, item, info, strict)
```

* inv: `string` or `number`
* item: `string`
  * item name
* info?: `table` (optional)
* strict?: `boolean` (optional)
  * full match or partial match

### GetFirstItem

```lua
exports['ak47_inventory']:GetFirstItem(inv, item)
```

* inv: `string` or `number`
* item: `string`
  * item name

Return: `table`

* first item table with total item amount & properties

Return: `table`

* item table with total item amount & properties

### CanAddItem

```lua
exports['ak47_inventory']:CanAddItem(identifier, item, amount, skipWeight)
```

* identifier: `string` or `number`
  * player id or inventory identifier
* item `string`
  * item name
* amount: `number`
* skipWeight?: `boolean` (optional)
  * if true then it will not check weight. Only check if there is any slot available

Return: `boolean`

### CanCarryAmount <a href="#cancarryamount" id="cancarryamount"></a>

```lua
exports['ak47_inventory']:CanCarryAmount(identifier, item)
```

* identifier: `string` or `number`
  * player id or inventory identifier
* item `string`
  * item name

Return: `number`

### CanCarryWeight

```lua
exports['ak47_inventory']:CanCarryWeight(identifier, weight)
```

* identifier: `string` or `number`
  * player id or inventory identifier
* weight:`number`

Return: `boolean`, `number`

* canHold
* availableWeight

### SetMaxWeight

```lua
exports['ak47_inventory']:SetMaxWeight(identifier, newWeight)
```

* identifier: `string` or `number`
  * player id or inventory identifier
* newWeight:`number`

### CanSwapItem <a href="#canswapitem" id="canswapitem"></a>

Returns true if the item swap is possible based on inventory weight.

```lua
exports['ak47_inventory']:CanSwapItem(inv, firstItem, firstItemCount, testItem, testItemCount)
```

* inv: `string` or `number`
* firstItem: `string`
* firstItemAmount: `number`
* testItem: `string`
* testItemAmount: `number`

Return: `boolean`

### GetAmount

```lua
exports['ak47_inventory']:GetAmount(identifier, item, info, strict)
```

* identifier: `string` or `number`
* item: `string`
  * item name
* info?: `table` (optional)
* strict?: `boolean` (optional)
  * full match or partial match

Return: `number`

### GetSlot

```lua
exports['ak47_inventory']:GetSlot(identifier, slot)
```

* identifier: `string` or `number`
* slot: `number`

Return: `table`

* item table of that slot

### GetSlotForItem <a href="#getslotforitem" id="getslotforitem"></a>

```lua
exports['ak47_inventory']:GetSlotForItem(identifier, itemName, info)
```

* identifier: `string` or `number`
* itemName: `string`
* info: `table?`

Return: `number`

* slotId

### GetSlotIdWithItem <a href="#getslotidwithitem" id="getslotidwithitem"></a>

```lua
exports['ak47_inventory']:GetSlotIdWithItem(identifier, itemName, info, strict)
```

* identifier: `string` or `number`
* itemName: `string`
* info?: `table`
* strict?: `boolean`
  * strictly match info properties, otherwise use partial matching.

Return: `number`

* slotId

### GetSlotIdsWithItem <a href="#getslotidswithitem" id="getslotidswithitem"></a>

```lua
exports['ak47_inventory']:GetSlotIdsWithItem(inv, itemName, info, strict)
```

* identifier: `string` or `number`
* itemName: `string`
* info?: `table`
* strict?: `boolean`
  * Strictly match info properties, otherwise use partial matching.

Return: `table`

* slotIds:

### GetSlotsWithItem <a href="#getslotswithitem" id="getslotswithitem"></a>

```lua
exports['ak47_inventory']:GetSlotsWithItem(identifier, itemName, info, strict)
```

* identifier: `string` or `number`
* itemName: `string`
* info?: `table`
* strict?: `boolean`
  * Strictly match info properties, otherwise use partial matching.

Return: `table`

* slotsData

### GetEmptySlot <a href="#getemptyslot" id="getemptyslot"></a>

```lua
exports.ox_inventory:GetEmptySlot(identifier)
```

* identifier: `string` or `number`

Return: `number`

* slotId

### GetContainerFromSlot <a href="#getcontainerfromslot" id="getcontainerfromslot"></a>

```lua
exports['ak47_inventory']:GetContainerFromSlot(identifier, slotId)
```

* identifier: `string` or `number`
* slotId: `number`

Return: `table`

* containerData

### SetSlotCount <a href="#setslotcount" id="setslotcount"></a>

```lua
exports['ak47_inventory']:SetSlotCount(identifier, slots)
```

* identifier: `string` or `number`
* slots: `number`

### GetInventory

```lua
exports['ak47_inventory']:GetInventory(identifier)
```

* identifier: `string` or `number`

Return: `table`

* inventoryTable

### GetInventoryItems

```lua
exports['ak47_inventory']:GetInventoryItems(identifier)
```

* identifier: `string` or `number`

Return: `table`

* inventoryItemsTable

### SetInvItems

```lua
exports['ak47_inventory']:SetInvItems(identifier, items)
```

* identifier: `string` or `number`
* items: `table`

### ConfiscateInventory <a href="#confiscateinventory" id="confiscateinventory"></a>

```lua
exports['ak47_inventory']:ConfiscateInventory(identifier)
```

* identifier: `string` or `number`

### ReturnInventory

```lua
exports['ak47_inventory']:ReturnInventory(identifier)
```

* identifier: `string` or `number`

### ClearInventory

```lua
exports['ak47_inventory']:ClearInventory(identifier)
```

* identifier: `string` or `number`

### ClearClothing

```lua
exports['ak47_inventory']:ClearClothing(identifier)
```

* identifier: `string` or `number`

### Search <a href="#search" id="search"></a>

```lua
exports['ak47_inventory']:Search(identifier, search, item, info)
```

* identifier: `string` or `number`
* search: `string`
* item: `table` or `string`
* info?: `table` or `string`

`search` can be either `'slots'` or `'count'`, where slots will return a table of data and count will return the found amount of the specified item.

### CreateInventory

```lua
exports['ak47_inventory']:CreateInventory(identifier, data)
```

* identifier: `string`
* data: `table`
  * label: `string`
  * maxWeight: `number`
  * slots: `number`
  * type: `string`
    * backpack, stash, player, shop, trunk, glovebox
  * type2: `string` or `nil`
    * smallBackpack, largeBackpack (only use for backpack)
  * temp: `boolean` or `nil`
    * is this a temporary inventory?
  * whitelist: `table` or `nil`
    * list of whitelisted items or nil
  * blacklist: `table` or `nil`
    * list of blacklisted items or nil

Example:

```lua
-- server side
exports['ak47_inventory']:CreateInventory('housing:123', {
    label = 'Housing',
    maxWeight = 500000,
    slots = 50,
    type = 'stash',
})

--open from server side
exports['ak47_inventory']:OpenInventory(source, 'housing:123')

--open from client side
exports['ak47_inventory']:OpenInventory('housing:123')
```

### LoadInventory

load an existing inventory from databse

{% tabs %}
{% tab title="Load Existing Inventory" %}

```lua
exports['ak47_inventory']:LoadInventory(identifier)
```

{% endtab %}

{% tab title="Create & Load" %}

```lua
--if missing in database then create & load an inventory
exports['ak47_inventory']:LoadInventory(identifier, data)
```

{% endtab %}
{% endtabs %}

Return: `boolean`

Example:

```lua
-- server side
exports['ak47_inventory']:LoadInventory('housing:123', {
    label = 'Housing',
    maxWeight = 500000,
    slots = 50,
    type = 'stash',
})
```

### UnloadInventory

```lua
exports['ak47_inventory']:UnloadInventory(identifier)
```

* identifier: `string` or `number`

### SetWhitelistedItemsForContainer

```lua
exports['ak47_inventory']:SetWhitelistedItemsForContainer(identifier, items)
```

* identifier: `string` or `number`
* items: `table`

Example:

```lua
exports['ak47_inventory']:SetWhitelistedItemsForContainer('stash:123', {'water', 'bread'})
```

### SetBlacklistedItemsForContainer

```lua
exports['ak47_inventory']:SetBlacklistedItemsForContainer(identifier, items)
```

* identifier: `string` or `number`
* items: `table`

Example:

```lua
exports['ak47_inventory']:SetBlacklistedItemsForContainer('stash:123', {'water', 'bread'})
```

### GetCurrentWeapon

```lua
exports['ak47_inventory']:GetCurrentWeapon(identifier)
```

* identifier: `string` or `number`

Return: `table`

* currentWeapon

### SetQuality

```lua
exports['ak47_inventory']:SetQuality(identifier, slot, quality)
```

* identifier: `string` or `number`
* slot: `number`
* quality: `number`

### SetItemInfo

```lua
exports['ak47_inventory']:SetItemInfo(identifier, slot, info)
```

* identifier: `string` or `number`
* slot: `number`
* info: `table`

### RemoveQuality

```lua
exports['ak47_inventory']:RemoveQuality(identifier, slot, value)
```

* identifier: `string` or `number`
* slot: `number`
* value: `number`

### SaveInventory

```lua
exports['ak47_inventory']:SaveInventory(identifier)
```

* identifier: `string` or `number`

### DeleteInventory

```lua
exports['ak47_inventory']:DeleteInventory(identifier)
```

* identifier: `string` or `number`

### SaveAllInventory

```lua
exports['ak47_inventory']:SaveAllInventory()
```

### OnChangeVehiclePlate

```lua
exports['ak47_inventory']:OnChangeVehiclePlate(oldPlate, newPlate)
```

* oldPlate: `string`
* newPlate: `string`


---

# 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.menanak47.com/qbcore/ak47_qb_inventory/exports/server.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.
