Skip to main content
Grid Inventory

Server inventory

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

Setup overview

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.

API reference

Inventory exports

Read inventory data, manage items and control inventory storage.

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

Adds an item to an inventory.

invnumber | stringitemNamestringquantity?numbermeta?table
success, response_message, InventoryItem
CanCarryItem(inv, itemName, quantity)

Checks the weight, available slots and stacking capacity.

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
GetInventory(inv)

Returns the inventory data.

invnumber | string
Inventory
GetInventoryClass(inv)

Returns the class associated with the supplied inventory.

invInventoryClass
InventoryClass
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
GetItemOnSlotID(inv, slotId)

Returns the item assigned to an action slot from 1 to 5. Player inventories only.

invnumberslotIdnumber
InventoryItem | nil
GetItemQuantityBy(inv, findBy)

Returns the combined quantity of items matching the search options.

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 the specified player.

invstringsourcenumber
RegisterStash(data)

Creates a stash inventory.

dataStashInventoryClassCreate
RemoveItemBy(inv, quantity, findBy)

Removes an item matching the supplied search options.

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
void
SetMaxWeight(inv, maxWeight)

Sets the maximum weight of an inventory.

invnumber | stringmaxWeightnumber
boolean
SetMetaData(inv, findBy, metaData)

Replaces the metadata of a matching item.

invnumber | stringfindBytablemetaData{ [string]: any }
InventoryItem
SetNewVehiclePlate(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

Configuration

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": []
}
]]
Configuration

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
Configuration

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}))
Configuration

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.

Configuration

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)
Configuration

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)