Item Definitions API

Category: API Reference

Access static item definitions from the game cache. This allows looking up item properties like name, cost, members status, without needing the item in inventory or bank.

Functions

get

item_definitions:get(item_id: number) -> ItemDefinition?

Look up a single item definition by ID.

Parameters:

ParameterTypeRequiredDescription
item_idnumberYesThe item ID to look up

Returns:

  • ItemDefinition? - The item definition, or nil if not found

Example:

local def = item_definitions:get(4151)  -- Abyssal whip
if def then
    logger:info("Item: " .. def:name())
    logger:info("Cost: " .. def:cost())
    logger:info("Members: " .. tostring(def:members()))
end

find_first

item_definitions:find_first(filter: table?) -> ItemDefinition?

Find the first item definition matching the filter.

Parameters:

ParameterTypeRequiredDescription
filtertableNoFilter options

Returns:

  • ItemDefinition? - First matching item definition, or nil

Filters:

FilterTypeDescription
idnumberExact item ID
idstableArray of item IDs to match
namestringExact name match
name_containsstringName contains text
name_anytableMatch if name equals any in array
name_contains_anytableMatch if name contains any substring

Example:

local whip = item_definitions:find_first({name = "Abyssal whip"})
if whip then
    logger:info("Found: " .. whip:name() .. " (ID: " .. whip:id() .. ")")
end

find_all

item_definitions:find_all(filter: table?) -> table

Find all item definitions matching the filter.

Parameters:

ParameterTypeRequiredDescription
filtertableNoFilter options (same as find_first)

Returns:

  • table - Array of matching ItemDefinition objects

Example:

-- Find all dragon items
local dragon_items = item_definitions:find_all({name_contains = "Dragon"})
logger:info("Found " .. #dragon_items .. " dragon items")

for _, item in ipairs(dragon_items) do
    logger:info(item:name() .. " - " .. item:cost() .. " gp")
end

-- Find specific items by name
local potions = item_definitions:find_all({
    name_contains_any = {"Super restore", "Prayer potion", "Saradomin brew"}
})

count

item_definitions:count(filter: table?) -> number

Count item definitions matching the filter.

Parameters:

ParameterTypeRequiredDescription
filtertableNoFilter options (same as find_first)

Returns:

  • number - Count of matching item definitions

Example:

local members_items = item_definitions:count({members = true})
logger:info("Members items: " .. members_items)

contains

item_definitions:contains(filter: table?) -> boolean

Check if any item definition matches the filter.

Parameters:

ParameterTypeRequiredDescription
filtertableNoFilter options (same as find_first)

Returns:

  • boolean - True if at least one item matches

Example:

if item_definitions:contains({name = "Twisted bow"}) then
    logger:info("Twisted bow exists in the game!")
end

ItemDefinition Methods

Each ItemDefinition object has methods to access item properties:

Basic Info

MethodReturnsDescription
id()numberItem ID
name()stringItem name
examine()stringExamine text
cost()numberBase cost/value
category()numberItem category (-1 if none)
team()numberTeam cape number
model_id()numberInventory model ID

Flags

MethodReturnsDescription
stackable()booleanIs item stackable
members()booleanIs members-only
tradeable()booleanIs tradeable
noted()booleanIs this a noted form
equipable()booleanCan be equipped
cosmetic()booleanIs cosmetic item

Related Items

MethodReturnsDescription
noted_id()numberNoted variant ID (-1 if none)
placeholder_id()numberPlaceholder ID (-1 if none)

Equipment

MethodReturnsDescription
wear_pos_1()numberPrimary equipment slot (-1 if not equipable)
wear_pos_2()numberSecondary slot (-1 if none)
wear_pos_3()numberTertiary slot (-1 if none)

Actions

MethodReturnsDescription
actions()tableInventory/interface actions
ground_actions()tableGround/floor actions

Common Patterns

Looking Up Item Info

local function get_item_info(item_id)
    local def = item_definitions:get(item_id)
    if not def then
        logger:warn("Item not found: " .. item_id)
        return
    end
    
    logger:info("=== " .. def:name() .. " ===")
    logger:info("ID: " .. def:id())
    logger:info("Cost: " .. def:cost() .. " gp")
    logger:info("Members: " .. tostring(def:members()))
    logger:info("Tradeable: " .. tostring(def:tradeable()))
    logger:info("Stackable: " .. tostring(def:stackable()))
    
    if def:equipable() then
        logger:info("Equipment slot: " .. def:wear_pos_1())
    end
end

get_item_info(4151)  -- Abyssal whip

Finding Items by Name Pattern

-- Find all rune items
local rune_items = item_definitions:find_all({name_contains = "Rune "})
for _, item in ipairs(rune_items) do
    if item:equipable() then
        logger:info(item:name() .. " (equipable)")
    end
end

Checking Item Properties

local function is_food(item_id)
    local def = item_definitions:get(item_id)
    if not def then return false end
    
    local actions = def:actions()
    for _, action in ipairs(actions) do
        if action == "Eat" then
            return true
        end
    end
    return false
end

if is_food(379) then  -- Lobster
    logger:info("Lobster is food!")
end

Finding Tradeable Equipment

local function find_tradeable_weapons()
    local weapons = item_definitions:find_all({name_contains = "sword"})
    local tradeable = {}
    
    for _, item in ipairs(weapons) do
        if item:tradeable() and item:equipable() then
            table.insert(tradeable, item)
        end
    end
    
    return tradeable
end

Performance Notes

  • find_all() without filters iterates through ~30,000 items and can be slow
  • Always use filters when possible to narrow results
  • get() by ID is fast and preferred when you know the item ID
  • Results are not cached; repeated queries will re-scan the cache

Related APIs

  • Inventory API - Access inventory items
  • Bank API - Bank management
  • Equipment API - Equipment slots