Server inventory
Access and manage player, stash and vehicle inventories from server-side resources.
Integration notes
Inventory identifiers
The inv argument accepts either a player ID or an inventory unique ID unless the export states otherwise.
Search options
The findBy table can filter by name, itemHash, x, y, isWeared and meta.
Inventory exports
Read inventory data, manage items and control inventory storage.
AddItem(inv, itemName, quantity?, meta?)Adds an item to an inventory.
invnumber | stringitemNamestringquantity?numbermeta?tablesuccess, response_message, InventoryItemCanCarryItem(inv, itemName, quantity)Checks the weight, available slots and stacking capacity.
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—GetInventory(inv)Returns the inventory data.
invnumber | stringInventoryGetInventoryClass(inv)Returns the class associated with the supplied inventory.
invInventoryClassInventoryClassGetInventoryItems(inv)Returns every item in an inventory.
invnumber | stringInventoryItem[]GetItemBy(inv, findBy)Returns one item matching the supplied search options.
invnumber | stringfindBytableInventoryItemGetItemOnSlotID(inv, slotId)Returns the item assigned to an action slot from 1 to 5. Player inventories only.
invnumberslotIdnumberInventoryItem | nilGetItemQuantityBy(inv, findBy)Returns the combined quantity of items matching the search options.
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 the specified player.
invstringsourcenumber—RegisterStash(data)Creates a stash inventory.
dataStashInventoryClassCreate—RemoveItemBy(inv, quantity, findBy)Removes an item matching the supplied search options.
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 | stringnamestringquantitynumbervoidSetMaxWeight(inv, maxWeight)Sets the maximum weight of an inventory.
invnumber | stringmaxWeightnumberbooleanSetMetaData(inv, findBy, metaData)Replaces the metadata of a matching item.
invnumber | stringfindBytablemetaData{ [string]: any }InventoryItemSetNewVehiclePlate(oldPlate, newPlate)Updates an inventory after a vehicle plate is changed.
oldPlatestringnewPlatestring—Clearing inventories
Clear also deletes untradable items from the selected inventory.
Inventory classes
Only use GetInventoryClass if you understand the internal inventory classes. Each inventory type inherits from the main BaseInventory class.
Examples
Read an inventory
Return the data stored for a stash inventory.
local inventory = exports["avp_grid_inventory"]:GetInventory("stash-1")
--[[
{
"stashY": 5308.7,
"isPublic": true,
"maxWeight": 10000,
"inventoryName": "House Safe",
"inventoryUniqueId": "stash-1",
"inventoryY": 7,
"inventoryX": 7,
"stashZ": 101.5,
"observers": [],
"stashX": 2942.91,
"type": "stash",
"items": []
}
]]
Access an inventory class
Resolve an inventory class and call its open function when available.
local inventory = exports["avp_grid_inventory"]:GetInventory(1)
local class = exports["avp_grid_inventory"]:GetInventoryClass(inventory)
if type(class?.open) == "function" then
class.open(inventory)
end
Find an item
Search a stash by item name and metadata.
local res = exports["grid_inventory"]:GetItemBy("stash-1", {
name = "backpack",
meta = {
drawable = 40
}
})
print(json.encode(res, {indent=true}))
Register a stash
Create a stash with size, weight, location and group access settings.
exports["grid_inventory"]:RegisterStash({
uniqueID = "stash-1",
maxWeight = 10000,
inventoryName = "House Safe",
xSize = 7,
ySize = 7,
groups = {
["police"] = 2,
["ambulance"] = 1,
["ballas"] = 3
},
coordX = 2942.91,
coordY = 5308.7,
coordZ = 101.5,
})
The stash data accepts uniqueID, xSize, ySize, maxWeight, inventoryName, coordinates and optional isPublic, ownerLicense, groups and isPermanent values. Public stashes ignore owner and group restrictions. When isPermanent is set to true, its items are not saved to SQL and the stash can be used as a loot system.
Update item durability
Find the equipped weapon and set its durability.
local source = source
local usedWeaponItem = exports["avp_grid_inventory"]:GetUsedWeapon(source)
if not usedWeaponItem then return end
exports["avp_grid_inventory"]:SetDurability(source, { itemHash = usedWeaponItem.itemHash }, 100)
Update item metadata
Modify the metadata of a worn armour item.
local source = source
local bodyArmourItem = exports["avp_grid_inventory"]:GetItemBy(source, { isWeared = true, name = "armour" })
if not bodyArmourItem then return end
bodyArmourItem.meta.durability = 100
bodyArmourItem.meta.drawable = 20
exports["avp_grid_inventory"]:SetMetaData(source, { itemHash = bodyArmourItem.itemHash }, bodyArmourItem.meta)