Skip to content

Inventory

Overview

The Inventory table provides access to Inv objects.

Functions

Find(InvType)

function Inventory.Find(config : InvType) -> [ Inv ]

Returns the Inv associated with the supplied InvType.

Parameter Type Description
config InvType A valid InvType.
Returns Description
Inv The inventory container for a list of objects.

Example

local inv = Inventory.Find(config.Inv.INV)
-- Do something with the inv

Find(Integer)

function Inventory.Find(id : Integer) -> [ Inv ]

Returns the Inv associated with the matching ID.

Parameter Type Description
id Integer A valid ID value.
Returns Description
Inv The inventory container for a list of objects.

Example

local targetInvID = ...
local inv = Inventory.Find(targetInvID)
-- Do something with the inv

Inv

Overview

An inventory provides access to a list of InvSlot entries, each of which contains information about the ObjType contained within it.
Inventories are of a fixed size, and their slots may or may not be populated by an InvSlot.

Info

An Inv object is a Proxy usertype, which means it is safe to copy and store in your scripts.
It cannot, however, be used with any persistent storage.

Warning

Use Inv.isValid to confirm that an inventory still exists before trying to access its properties.
Inventories can be added or removed from the client by the server for a variety of reasons e.g. the player closes a shop interface. When an inventory's data is removed it will become invalid, and any copies of this usertype should be disposed of.
If the same inventory data is re-added to the client by the server, such as walking back into visibility range, then a different new Inv object will be created.

Methods

GetSlot

function Inv:GetSlot(index : Integer) -> InvSlot

Returns the InvSlot at the specified index.

Warning

This function returns a copy of the data in the specified slot at the time of execution.

Parameter Type Description
index Integer A valid slot index.
Index values are 1-indexed.
Returns Description
InvSlot An object representing the inventory slot specified.
Returns nil on failure.

Example

local inv = Inventory.Find(config.Inv.INV)
local firstSlot = inv:GetSlot(1)
-- Do something with the slot data

GetSlots

function Inv:GetSlots() -> [InvSlot]

Returns the current data associated for all slots in the inventory.

Warning

This function returns a copy of the data in the specified slot at the time of execution.

Returns Description
[InvSlot] An table of objects representing the inventory slot specified.
Returns nil on failure.

Example

local inv = Inventory.Find(config.Inv.INV)
local slots = inv:GetSlots()
for i,slot in ipairs(slots) do
    -- Do something with the slots here
end

GetTotal(ObjType)

function Inv:GetTotal(objType : ObjType) -> Integer

Returns the number of objects matching a valid ObjType specified in the associated inventory.

Parameter Type Description
objType ObjType A valid ObjType.
Returns Description
Integer The number of objects matching the specified ObjType.

Example

local inv = Inventory.Find(config.Inv.INV)
local steelBarTotal = inv:GetTotal(config.Obj.STEEL_BAR)

GetTotal(Integer)

function Inv:GetTotal(id : Integer) -> Integer

Returns the number of objects matching a valid ObjType ID specified in the associated inventory.

Parameter Type Description
id Integer A valid ObjType ID.
Returns Description
Integer The number of objects matching the id.

Example

local inv = Inventory.Find(config.Inv.INV)
local id = config.Obj["STEEL_BAR"].id
local steelBarTotal = inv:GetTotal(id)

GetCategoryTotal

function Inv:GetCategoryTotal(category : Integer) -> Integer

Returns the number of objects in the inventory that are in the category specified.

Parameter Type Description
category Integer A valid category of object.
Returns Description
Integer The number of objects matching the specified category.

Example

local inv = Inventory.Find(config.Inv.INV)
local categoryTotal = inv:GetCategoryTotal(config.Obj.STEEL_BAR.category)

Properties

Name Type Description
id Integer Unique ID associated with the inventory.
config InvType InvType config used to construct the inventory.
valid Boolean Is the inventory object valid.
slotCount Integer Total number of slots.
usedSlotCount Integer Number of non-empty slots.
freeSlotCount Integer Number of empty slots.

InvSlot

Overview

A representation of an individual inventory slot.

Properties

Name Type Description
obj ObjType Unique ID associated with the inventory.
count Integer Number of objects in the slot.