Documentation › Lua

Container and Inventory

Container works with the bags open in the client. Inventory works with the equipment slots.

Container#

Container.new(index) (or Container(index)) creates the object for the container open at that index (the first one opened is 0). The slots inside it start at 0. Methods use :. Methods that send an action return true, or nil when the slot is empty.

lua
-- Lists what is in each open bag
for _, i in ipairs(Player.getContainers() or {}) do
  local bag = Container.new(i)
  print(bag:getName() .. ": " .. (bag:getItemCount() or 0) .. " items")
end

Reading#

MethodReturns
bag:getIndex()The index used to create the object
bag:getName()Name as shown in the window (first letter capitalized), or nil
bag:getItems()List of {id, count, tier, slot} (tier always 0), or nil when the container is closed
bag:getItemCount()How many slots are taken, or nil
bag:getItemCountById(itemId)Sum of the counts of that item, or nil
bag:getCapacity()Slots per page, or nil
bag:getCurrentPage()Current page (starts at 1), or nil
bag:getTotalPages()Total pages (0 without paging), or nil
lua
local bag = Container.new(0)
print(bag:getItemCountById(268) or 0, "mana potions in the first bag")

bag:goToPage(page)#

→ true or nil

Goes to the page (starts at 1). nil if the container has no pages.

lua
Container.new(0):goToPage(2)

bag:moveUp() and bag:close()#

Goes back to the parent container / closes the container.

lua
Container.new(1):close()

bag:useItem(slot, newWindow)#

→ true or nil

Uses the item in the slot. On a bag, newWindow = true opens it in another window; without it, it opens in the same one.

lua
Container.new(0):useItem(0, true)

bag:lookAt(slot)#

→ true or nil

Looks at the item in the slot.

lua
Container.new(0):lookAt(0)

bag:moveItemToInventory(slot, inventorySlot, count)#

→ true or nil

Moves the item to an equipment slot. Without count, it moves the whole stack (at most 100).

lua
Container.new(0):moveItemToInventory(3, Enums.InventorySlot.CONST_SLOT_AMMO)

bag:moveItemToGround(slot, count, x, y, z)#

→ true or nil

Drops the item on a tile.

lua
local p = Player.getPosition()
Container.new(0):moveItemToGround(0, nil, p.x, p.y, p.z)

bag:moveItemToContainer(slot, count, toIndex, toSlot)#

→ true or nil

Moves the item to another open container.

lua
Container.new(0):moveItemToContainer(0, nil, 1, 0)

bag:useItemWithContainerItem(slot, toIndex, toSlot)#

→ true or nil

Uses the item in the slot on another container item.

lua
Container.new(0):useItemWithContainerItem(2, 1, 0)

Container.useItemOnAnotherItem(itemId, otherItemId)#

→ true or nil

Module function (with ., not :). Uses the item itemId as a hotkey on the first otherItemId it finds in the open containers or the equipment. nil if it finds none.

lua
-- uses item 5908 on the first item 4010 it finds (replace with your ids)
Container.useItemOnAnotherItem(5908, 4010)

bag:stowItem(slot, count) and bag:stowAllItems(slot)#

→ true or nil

Sends the item (or the whole stack, with stowAllItems) to the supply stash.

lua
Container.new(0):stowAllItems(0)

bag:pickItemImbuement(slot)#

→ true or nil

Opens the imbuement window with the item in the slot.

lua
Container.new(0):pickItemImbuement(0)

Inventory#

Module functions (with .). The slot is Enums.InventorySlot (1 to 10). All of them return true, or nil when the slot is empty.

Inventory.useItem(slot)#

Uses the equipped item.

lua
Inventory.useItem(Enums.InventorySlot.CONST_SLOT_BACKPACK) -- opens the backpack

Inventory.lookAt(slot)#

Looks at the equipped item.

lua
Inventory.lookAt(Enums.InventorySlot.CONST_SLOT_RING)

Inventory.moveItemToGround(slot, count, x, y, z)#

Drops the equipped item on a tile.

lua
local p = Player.getPosition()
Inventory.moveItemToGround(Enums.InventorySlot.CONST_SLOT_AMMO, 10, p.x, p.y, p.z)

Inventory.moveItemToContainer(slot, count, container, containerSlot)#

Moves the equipped item to an open container.

lua
Inventory.moveItemToContainer(Enums.InventorySlot.CONST_SLOT_RING, nil, 0, 0)

Inventory.stowContainer(slot)#

Sends the contents of the container equipped in the slot to the supply stash.

lua
Inventory.stowContainer(Enums.InventorySlot.CONST_SLOT_BACKPACK)

Inventory.pickItemImbuement(slot)#

Opens the imbuement window with the equipped item.

lua
Inventory.pickItemImbuement(Enums.InventorySlot.CONST_SLOT_ARMOR)