Inventory

Group
player
Methods
23
Fields
None

Getting one

player:inventory()

Methods

MethodReturnsDescription
emptySlots()numberFree inventory slots, out of 28.
isFull()booleanWhether all 28 slots are occupied.
contains(number)booleanWhether any inventory slot holds at least one item of itemId.
containsName(string)booleanWhether the inventory holds an item whose whole name matches, ignoring case: | separates alternatives and * is any run of characters. F…
itemAmount(number)numberTotal quantity of itemId held, counting stack sizes.
itemAmountName(string)numberTotal quantity held of every item whose name matches.
foodAmount(number?)numberTotal quantity of edible food carried that heals at least minHeal at the current Hitpoints level. Noted food is excluded: it still carrie…
prayerDoses()numberTotal prayer-restore doses carried, doses multiplied by quantity.
cureAmount()numberHow many carried potions cure poison or venom: items, not doses, so a 4-dose antidote counts 1.
totalHeal()numberHitpoints all the carried food would heal: heal at the current Hitpoints level times bites left, over every stack. Noted food and Hitpoints…
totalPrayerRestore()numberPrayer points all the carried potions would restore: points per dose times doses, over every stack. Noted potions do not count.
search()ContainerQueryOpen a query over the inventory's items.
lootingBag()RememberedItems?The looting bag's contents as this account last saw them.
interact(number, string | { string })booleanInteract with the first item of itemId.
interactName(string, string | { string })booleanInteract with the first item whose whole name matches.
interactAny({ number }, string | { string })booleanInteract with the first of itemIds that is carried and offers one of options.
select(number)booleanSelect an item as the source of a following target action.
target(number, number?)booleanApply an already-selected source to an inventory item.
useOnItem(number, number)booleanUse one inventory item on another: select, then target, together in one tick.
useOnNpc(number, NPC | number)booleanUse an inventory item on an NPC: select, then target the NPC.
useOnObject(number, TileObject | number)booleanUse an inventory item on a scene object: select, then target it.
useOnPlayer(number, Player)booleanUse an inventory item on a player: select, then use it on the player, together in one tick.
useOnGroundItem(number, TileItem)booleanUse an inventory item on a ground item: select, then use it on that stack (its id and its tile), together in one tick.

Returned by

MethodReturnsDescription
PlayerDomain.inventoryInventoryThe 28-slot inventory.

Method details

emptySlots

emptySlots: (Inventory) -> number

Free inventory slots, out of 28.

Returns
28 minus the number of occupied slots.

contains

contains: (Inventory, number) -> boolean

Whether any inventory slot holds at least one item of itemId.

itemId
Exact item id.

containsName

containsName: (Inventory, string) -> boolean

Whether the inventory holds an item whose whole name matches, ignoring case: | separates alternatives and * is any run of characters. For part of a name, use search():containing(text).

name
The name pattern, e.g. "Shark|Manta ray" or "Prayer potion(*)".

itemAmount

itemAmount: (Inventory, number) -> number

Total quantity of itemId held, counting stack sizes.

itemId
Exact item id.
Returns
0 when the item is absent.

itemAmountName

itemAmountName: (Inventory, string) -> number

Total quantity held of every item whose name matches.

name
The name pattern, matched as for containsName.

foodAmount

foodAmount: (Inventory, number?) -> number

Total quantity of edible food carried that heals at least minHeal at the current Hitpoints level. Noted food is excluded: it still carries heal data but cannot be eaten.

minHeal
The smallest heal that counts; default 1, anything that heals.

prayerDoses

prayerDoses: (Inventory) -> number

Total prayer-restore doses carried, doses multiplied by quantity.

Noted potions are excluded, for the same reason as foodAmount.

cureAmount

cureAmount: (Inventory) -> number

How many carried potions cure poison or venom: items, not doses, so a 4-dose antidote counts 1.

Exactly the list consumables:curePoison() drinks from, so this counts what that would actually find.

totalHeal

totalHeal: (Inventory) -> number

Hitpoints all the carried food would heal: heal at the current Hitpoints level times bites left, over every stack. Noted food and Hitpoints-boosting potions (Saradomin brew) do not count.

totalPrayerRestore

totalPrayerRestore: (Inventory) -> number

Prayer points all the carried potions would restore: points per dose times doses, over every stack. Noted potions do not count.

lootingBag

lootingBag: (Inventory) -> RememberedItems?

The looting bag's contents as this account last saw them.

nil until the bag has been checked or filled with Bento running. live while its check view or the bank's view of it is open.

interact

interact: (Inventory, number, string | { string }) -> boolean

Interact with the first item of itemId.

itemId
Exact item id.
options
An option ("Eat"), or options to try in order; the first the item exposes wins, counting sub-menu options as well as top-level ones.
Returns
false when the item is absent or no listed option resolves.

interactName

interactName: (Inventory, string, string | { string }) -> boolean

Interact with the first item whose whole name matches.

name
The name pattern, matched as for containsName.
options
An option ("Eat"), or options to try in order.
Returns
false when no item matches or no listed option resolves.

interactAny

interactAny: (Inventory, { number }, string | { string }) -> boolean

Interact with the first of itemIds that is carried and offers one of options.

It takes each id's first slot, and matches option names ignoring case and markup.

itemIds
Item ids, tried in list order rather than by slot.
options
The options to look for; the item's own option order picks among them, not this list's.

select

select: (Inventory, number) -> boolean

Select an item as the source of a following target action.

Pairs with target: select the source, then target what it is used on. useOnItem, useOnNpc and useOnObject do both halves for you.

itemId
Exact item id; the first matching slot is selected.
Returns
false when the item is absent.
Example
-- Use a knife on logs: select the source, then target what it is used on.
if inventory:select(KNIFE) then
    inventory:target(LOGS)
end

-- The same in one call.
inventory:useOnItem(KNIFE, LOGS)

target

target: (Inventory, number, number?) -> boolean

Apply an already-selected source to an inventory item.

Uses what this plugin selected (select(id), magic:select(spell)) on the item in that slot when the slot holds itemId, once per selection.

itemId
Exact item id of the destination item.
slot
The inventory slot (0-based) holding it; the first slot holding it when left out.
Returns
false when the item is absent from that slot, or nothing is selected.

useOnItem

useOnItem: (Inventory, number, number) -> boolean

Use one inventory item on another: select, then target, together in one tick.

useOnItem(a, a) targets a second slot, never the source's own. It takes the first slot holding each id.

sourceItemId
The item being used.
targetItemId
The item it is used on.
Returns
false when either item is absent.

useOnNpc

useOnNpc: (Inventory, number, NPC | number) -> boolean

Use an inventory item on an NPC: select, then target the NPC.

Takes an NPC (the top level or the boat the player stands in; false for one outside the top level and the boat the player stands in, one that is gone, or once another NPC has taken its index) or an NPC id (the nearest NPC with it); the select and the use together in one tick.

sourceItemId
The item being used.
npc
An NPC (the top level or the boat the player stands in), or an NPC id.
Returns
false when the item is absent or the NPC is gone.

useOnObject

useOnObject: (Inventory, number, TileObject | number) -> boolean

Use an inventory item on a scene object: select, then target it.

Takes a TileObject (the top level on the player's plane, or the deck of the boat the player stands in; false for one outside the top level and the boat the player stands in, removed, of a reloaded scene, or under a bridge) or an object id (the nearest object with it); the select and the use together in one tick.

sourceItemId
The item being used.
object
A TileObject (the top level or the boat the player stands in), or an object id.
Returns
false when the item is absent or the object is gone.

useOnPlayer

useOnPlayer: (Inventory, number, Player) -> boolean

Use an inventory item on a player: select, then use it on the player, together in one tick.

sourceItemId
The item being used (the first slot holding it).
player
A Player (top-level world view).
Returns
false when the item is absent, or the player is gone or in another world view.

useOnGroundItem

useOnGroundItem: (Inventory, number, TileItem) -> boolean

Use an inventory item on a ground item: select, then use it on that stack (its id and its tile), together in one tick.

sourceItemId
The item being used (the first slot holding it).
item
A TileItem (the top level or the boat the player stands in).
Returns
false when the item is absent, or the stack is gone or outside the top level and the boat the player stands in.