Skip to main content
Inventory 2.0

Adding and removing items

Access player inventories and create events or exports for common item operations.

Inventory 2.0 does not include ready-made exports for these operations. Use the existing inventory class functions to create the events or exports your server needs.

Inventory class functions

All functions attached to the inventory class are defined in sv_main.lua. The following example exposes the existing getItemCount class function as an export.

The getItemCount inventory class function

Configuration

Read an item count

Resolve the player's inventory and return the quantity of an item.

Export example
exports('getItemCount', function(source, item)
local identifier = Config.getIdentifier(source)
local Inventory = AquiverInventories[identifier]

if Inventory then
return Inventory.getItemCount(item)
end
end)

Add and remove items with events

These server events resolve the player's inventory before adding or removing an item. The cb argument is passed through the event and is not a framework callback.

Configuration

Item events

Register server events for adding and removing player items.

Events
RegisterNetEvent('AquiverInventory:Player:addItem')
RegisterNetEvent('AquiverInventory:Player:removeItem')

AddEventHandler('AquiverInventory:Player:addItem', function(item, count, vars, cb)
local source = source
local identifier = Config.getIdentifier(source)
if AquiverInventories[identifier] then
AquiverInventories[identifier].addItem(item, count, vars, function(response)
if cb then cb(response) end
end)
end
end)

AddEventHandler('AquiverInventory:Player:removeItem', function(item, count, cb)
local source = source
local identifier = Config.getIdentifier(source)
if AquiverInventories[identifier] then
AquiverInventories[identifier].removeItem(item, count, function(response)
if cb then cb(response) end
end)
end
end)

Add items with an export

The same inventory class function can be exposed as an export instead of an event.

Configuration

Add an item

Create an export that adds an item to a player's inventory.

Export example
exports('addItemPlayer', function(source, item, count, vars, cb)
local identifier = Config.getIdentifier(source)
local Inventory = AquiverInventories[identifier]

if Inventory then
Inventory.addItem(item, count, vars, function(response)
if cb then cb(response) end
end)
end
end)