Server inventory
Access and manage player and stash inventories from server-side resources.
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.
Inventory exports
Read inventory data, manage items and control stash storage.
AddItem(inv, itemName, quantity?, meta?)Adds an item to an inventory.
invnumber | stringitemNamestringquantity?numbermeta?tablesuccess, response, itemCanCarryItem(inv, itemName, quantity)Checks the available weight and whether an item can use an empty slot or stack.
invnumber | stringitemNamestringquantitynumberbooleanClear(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 | stringInventoryItem[]GetItemBy(inv, findBy)Returns one item matching the supplied search options.
invnumber | stringfindBytableInventoryItemGetItemQuantityBy(inv, findBy)Returns the combined quantity of matching items.
invnumber | stringfindBytablenumberGetItemsBy(inv, findBy)Returns every item matching the supplied search options.
invnumber | stringfindBytableInventoryItem[]GetWeight(inv)Returns the current inventory weight.
invnumber | stringnumberOpenStash(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 | stringquantitynumberfindBytableboolean, response_messageSave(inv)Saves the items in an inventory.
invnumber | stringnumberSaveAll()Saves every inventory.
—SetDurability(inv, findBy, durability)Updates the durability of a matching item.
invnumber | stringfindBytabledurabilitynumberInventoryItemSetItemQuantity(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 }InventoryItemClearing 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
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.
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
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)
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)