Skip to main content
Inventory 4.0

Server inventory

Access and manage player and stash inventories from server-side resources.

Setup overview

Integration notes

Inventory identifiers

The inv argument accepts either a player ID or an inventory unique ID.

Search options

findBy can match an item by name, itemHash, slot, quantity or meta.

API reference

Inventory exports

Read inventory data, manage items and control stash storage.

18 exports
AddItem(inv, itemName, quantity?, meta?)

Adds an item to an inventory.

invnumber | stringitemNamestringquantity?numbermeta?table
success, response, item
CanCarryItem(inv, itemName, quantity)

Checks the available weight and whether an item can use an empty slot or stack.

invnumber | stringitemNamestringquantitynumber
boolean
Clear(inv)

Removes every item from an inventory, including untradable items.

invnumber | string
DestroyStash(inv)

Removes a stash from the server without deleting its items.

invstring
FriskTarget(source, targetID)

Opens a target player inventory for frisking.

sourcenumbertargetIDnumber
GetInventoryItems(inv)

Returns every item in an inventory.

invnumber | string
InventoryItem[]
GetItemBy(inv, findBy)

Returns one item matching the supplied search options.

invnumber | stringfindBytable
InventoryItem
GetItemQuantityBy(inv, findBy)

Returns the combined quantity of matching items.

invnumber | stringfindBytable
number
GetItemsBy(inv, findBy)

Returns every item matching the supplied search options.

invnumber | stringfindBytable
InventoryItem[]
GetWeight(inv)

Returns the current inventory weight.

invnumber | string
number
OpenStash(inv, source)

Opens a stash for a specified player.

invstringsourcenumber
RegisterStash(data)

Creates a stash inventory.

dataStashInventoryClassCreate
RemoveItemBy(inv, quantity, findBy)

Removes a specified quantity of a matching item.

invnumber | stringquantitynumberfindBytable
boolean, response_message
Save(inv)

Saves the items in an inventory.

invnumber | string
number
SaveAll()

Saves every inventory.

None
SetDurability(inv, findBy, durability)

Updates the durability of a matching item.

invnumber | stringfindBytabledurabilitynumber
InventoryItem
SetItemQuantity(inv, name, quantity)

Sets the quantity of an item.

invnumber | stringnamestringquantitynumber
SetMetaData(inv, findBy, metaData)

Replaces the metadata of a matching item.

invnumber | stringfindBytablemetaData{ [string]: any }
InventoryItem
Clearing inventories

Clear also deletes untradable items from the selected inventory.

Destroying stashes

DestroyStash only removes the stash from the server. Its items are retained, but the stash cannot be opened until it is created again.

Find an item

Configuration

Search an inventory

Find a backpack in a stash by its name and metadata.

local res = exports["avp_inv_4"]:GetItemBy("stash-1", {
name = "backpack",
meta = {
drawable = 40
}
})

Register a stash

The stash data accepts uniqueID, maxWeight, inventoryName and optional isPublic, ownerLicense, groups and isPermanent values. Public stashes ignore owner and group restrictions. Permanent stashes do not save their items to SQL and can be used as loot systems.

Configuration

Create a loot stash

Register a public, permanent stash with group data.

exports["avp_inv_4"]:RegisterStash({
isPublic = true,
isPermanent = true,
inventoryName = "Loot Box",
maxWeight = 100,
slotsAmount = 15,
uniqueID = "random-loot-1",
groups = {
["police"] = 2,
["ambulance"] = 1,
["ballas"] = 3
}
})

Update item data

Configuration

Set item durability

Find an axe in the player inventory and set its durability.

local source = source
exports["avp_inv_4"]:SetDurability(source, { name = "axe" }, 100)
Configuration

Set item metadata

Update the durability and drawable metadata of body armour.

local source = source
local bodyArmourItem = exports["avp_inv_4"]:GetItemBy(source, { name = "body_armour" })
if not bodyArmourItem then return end

bodyArmourItem.meta.durability = 100
bodyArmourItem.meta.drawable = 20

exports["avp_inv_4"]:SetMetaData(source, { itemHash = bodyArmourItem.itemHash }, bodyArmourItem.meta)