Item structure
Here you can learn how to work with item data and metadata.
Getting item objects
lua
local item = getItem(itemID) -- Returns the item object for the given ID.Global helpers:
lua
getItemsCount() -- Total number of items defined in the server.
getItemAmount(id) -- Amount of a specific item (used in some contexts).
itemCount() -- Alias / helper in some scripts (context-dependent).Basic Item Data
lua
item:getName() -- Item name (string).
item:getNetID() -- Item net ID.
item:getRarity() -- Rarity value.
item:getGrowTime() -- Grow time for seeds/tree items.
item:getCategoryType() -- Category flags bitmask.
item:getEditableType() -- Editable type (signs, boards, etc).
item:isObtainable() -- True if item is obtainable in-game.
item:setPrice(number) -- Set store / price value (where supported).
item:setDescription(text) -- Set item description (where supported).
item:setActionType(value) -- Change item action type (advanced use).Examples:
lua
local item = getItem(itemID)
print(item:getName())
print(item:getNetID())
print(item:getRarity())
print(item:isObtainable())Action Type
lua
item:getActionType()
-- Returns item action type (e.g. clothing, seed, magplant, fish, etc).You might see older examples like:
lua
getActionType()In practice you want to call it on the item object:
lua
local item = getItem(itemID)
if item:getActionType() == SOME_ACTION_TYPE then
-- handle that type
endClothing Type
New methods for clothing classification:
lua
item:getClothingType()
-- Returns clothing type (hat, hair, shirt, pants, etc) as a numeric value.
item:setClothingType(number)
-- Sets clothing type (advanced use, only if you know what you’re doing).Category Flags & Untradable Check
item:getCategoryType() returns a bitmask of item categories.
You can decode it using bit.band and flags like this:
lua
local ITEM_CATEGORY_FLAGS = {
BETA = bit.lshift(1, 0),
AUTO_PICKUP = bit.lshift(1, 1),
MOD = bit.lshift(1, 2),
RANDOM_GROW = bit.lshift(1, 3),
PUBLIC = bit.lshift(1, 4),
FOREGROUND = bit.lshift(1, 5),
HOLIDAY = bit.lshift(1, 6),
UNTRADABLE = bit.lshift(1, 7),
}
local item = getItem(1804)
local cat = item:getCategoryType()
if bit.band(cat, ITEM_CATEGORY_FLAGS.UNTRADABLE) ~= 0 then
print("Untradeable")
else
print("Tradeable")
endYou can add your own helpers for other flags using the same pattern.
Examples
Price, obtainability, and name searches
lua
-- Set price
getItem(itemID):setPrice(price)
-- Check if obtainable
if getItem(itemID):isObtainable() then
print("This item can be obtained normally.")
end
-- Get netID
local netID = getItem(itemID):getNetID()
-- Name helpers
local name = getItem(itemID):getName()
print(name) -- Original
print(name:lower()) -- lowercase
print(name:lower():find("seed", 1, true)) -- simple substring searchSimple lookup loop (all items)
lua
local total = getItemsCount()
for id = 0, total - 1 do
local item = getItem(id)
print(id, item:getName(), item:isObtainable())
end