Skip to content

Item

Item Class

The Item class represents items in the game world, including inventory items, ground items, and equipment.

Constructor

Item(uid)
Item(itemId, count, position)
ParameterTypeDescription
uidnumberUnique item ID in Lua context
itemIdnumberItem type ID
countnumberStack count (optional)
positionPositionLocation (optional)

Type Checking

MethodReturnsDescription
isItem()booleanIs an item

Basic Properties

MethodReturnsDescription
getId()numberItem type ID
getName()stringItem name
getPluralName()stringPlural name
getArticle()stringArticle (a/an)
getDescription(distance)stringLook description
getSpecialDescription()stringSpecial description
getSubType()numberSubtype value
getCount()numberStack count
getCharges()numberCharges remaining
getFluidType()numberFluid type
getWeight()numberWeight
getWorth()numberGold value

Position & Parent

MethodReturnsDescription
getPosition()PositionItem position
getTile()TileTile item is on
getParent()CylinderParent (container/tile)
getTopParent()CylinderTop-level parent

IDs

MethodReturnsDescription
getUniqueId()numberUnique ID attribute
getActionId()numberAction ID attribute
setActionId(id)-Set action ID
-- Check action ID
if item:getActionId() == 1000 then
-- Quest item
end
-- Set action ID
item:setActionId(2000)

Attributes

MethodReturnsDescription
hasAttribute(attributeType)booleanHas attribute
getAttribute(attributeType)variesGet attribute value
setAttribute(attributeType, value)-Set attribute
removeAttribute(attributeType)-Remove attribute

Attribute Types:

  • ITEM_ATTRIBUTE_ACTIONID
  • ITEM_ATTRIBUTE_UNIQUEID
  • ITEM_ATTRIBUTE_DESCRIPTION
  • ITEM_ATTRIBUTE_TEXT
  • ITEM_ATTRIBUTE_WRITER
  • ITEM_ATTRIBUTE_NAME
  • ITEM_ATTRIBUTE_ATTACK
  • ITEM_ATTRIBUTE_DEFENSE
  • ITEM_ATTRIBUTE_ARMOR
  • ITEM_ATTRIBUTE_DURATION
  • ITEM_ATTRIBUTE_CHARGES
-- Set custom name
item:setAttribute(ITEM_ATTRIBUTE_NAME, "Magic Sword")
-- Get attack value
local attack = item:getAttribute(ITEM_ATTRIBUTE_ATTACK)

Custom Attributes

MethodReturnsDescription
getCustomAttribute(key)variesGet custom attribute
setCustomAttribute(key, value)-Set custom attribute
removeCustomAttribute(key)-Remove custom attribute
-- Set custom data
item:setCustomAttribute("owner", player:getName())
item:setCustomAttribute("created", os.time())
-- Get custom data
local owner = item:getCustomAttribute("owner")

Manipulation

MethodReturnsDescription
clone()ItemCreate copy
split(count)ItemSplit stack
remove(count)booleanRemove item/count
moveTo(destination, flags)ReturnValueMove item
transform(itemId, count)booleanTransform to another item
decay()-Start decay timer
-- Remove 1 from stack
item:remove(1)
-- Remove entire item
item:remove()
-- Transform item
item:transform(2160) -- Transform to crystal coin
-- Move to player
item:moveTo(player)

Properties

MethodReturnsDescription
hasProperty(property)booleanHas property
isLoadedFromMap()booleanIs map item
isStoreItem()booleanIs store item
setStoreItem(isStore)-Set store item flag

Imbuements

MethodReturnsDescription
getImbuementSlots()numberTotal imbue slots
getFreeImbuementSlots()numberAvailable slots
canImbue()booleanCan be imbued
addImbuementSlots(count)-Add imbue slots
removeImbuementSlots(count)-Remove slots
hasImbuementType(type)booleanHas imbue type
hasImbuements()booleanHas any imbues
addImbuement(imbuement)booleanAdd imbuement
removeImbuement(slot)booleanRemove imbuement
getImbuements()tableGet all imbues

Augments

MethodReturnsDescription
addAugment(augment)booleanAdd augment
removeAugment(augment)booleanRemove augment
isAugmented()booleanHas any augments
hasAugment(augment)booleanHas specific augment
getAugments()tableGet all augments

Custom Skills

MethodReturnsDescription
giveSkill(name, params)-Add custom skill
addSkill(name, levels)-Add levels
subtractSkill(name, levels)-Remove levels
removeSkill(name)-Remove skill
hasSkill(name)booleanHas skill
getSkillLevel(name)numberSkill level
canGainLevels()booleanCan gain levels

Stats

MethodReturnsDescription
giveStat(name, params)-Add custom stat
removeStat(name)-Remove stat
increaseStat(name, value)-Increase stat
decreaseStat(name, value)-Decrease stat
hasStat(name)booleanHas stat
getStat(name)StatGet stat
getStats()tableAll stats

Examples

Quest Item Check

local function isQuestItem(item)
return item:getActionId() >= 1000 and item:getActionId() < 2000
end

Create Custom Item

local function createEnchantedSword(player)
local item = player:addItem(2400, 1) -- Sword
if item then
item:setAttribute(ITEM_ATTRIBUTE_NAME, "Enchanted Sword")
item:setAttribute(ITEM_ATTRIBUTE_ATTACK, 50)
item:setAttribute(ITEM_ATTRIBUTE_DEFENSE, 35)
item:setCustomAttribute("enchantLevel", 1)
end
return item
end

Split Stack

local function splitHalf(item)
local count = item:getCount()
if count > 1 then
return item:split(math.floor(count / 2))
end
return nil
end

Transform on Use

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
-- Transform empty vial to full
if item:getId() == 2006 then
item:transform(2007) -- Full vial
return true
end
return false
end

Move Item Safely

local function moveItemTo(item, destination)
local result = item:moveTo(destination)
if result ~= RETURNVALUE_NOERROR then
local message = Game.getReturnMessage(result)
return false, message
end
return true
end