Skip to content

Inventory Contract ​

Contract: IInventory
Default provider: shiva-inventory

Manages player inventories, stashes, and item definitions.

Methods ​

IInventory:getItem(serverId, item) ​

Get the count of an item in a player's inventory.

lua
local inv = container:make('IInventory')
local count = inv:getItem(source, 'fish_bass')

Returns: number


IInventory:addItem(serverId, item, count) ​

Add items to a player's inventory.

lua
inv:addItem(source, 'fish_bass', 1)

Returns: boolean


IInventory:removeItem(serverId, item, count) ​

Remove items. Returns false if the player doesn't have enough.

lua
local ok = inv:removeItem(source, 'fishing_rod', 1)

Returns: boolean


IInventory:hasItem(serverId, item, count?) ​

Check if a player has an item (and optionally a minimum count).

lua
if inv:hasItem(source, 'fishing_rod') then
    -- player has at least 1
end

Returns: boolean


IInventory:getAll(serverId) ​

Get all items in a player's inventory.

Returns: table — { [item] = count }


IInventory:openStash(serverId, stashId, options?) ​

Open a stash for a player.

Events Emitted ​

EventPayload
inventory:itemAdded{ playerId, item, count }
inventory:itemRemoved{ playerId, item, count }

Released under the MIT License.