Repository navigation
LuaAPI Items
Item code = group * 512 + index (Helpers.MakeItemId(group, index), see Library).
Codes used in the examples: Jewel of Bless (14, 13), Jewel of Soul (14, 14), Jewel of Chaos (12, 15), Jewel of Life (14, 16), Jewel of Creation (14, 22).
Functions that change items (delete, set, give) need the character to be in game. Most of them also return false / 0 while the character is trading or has a window open (shop, warehouse, chaos machine ...). Player.CheckItemAction(aIndex) tells you if it is safe right now.
Functions that return an item (Player.GetItem, Warehouse.GetItem, EventInventory.GetItem, MuunInventory.GetItem, Item.GetGroundItem) return this table, or nil for an empty slot:
| Field | Meaning |
|---|---|
Index |
Item code. |
Serial |
Serial number. |
Level, Durability
|
Level, durability (stack size for stackable items). |
Skill, Luck, Option
|
Skill, luck, additional option. |
Exc, Ancient, Harmony, Option380
|
Excellent (bit mask), ancient, harmony, 380 option. |
Sockets |
5 values: -1 no socket, 254 empty socket. |
SocketBonus, ExpireDate
|
Socket bonus, expiry time (Unix timestamp, 0 = none). |
X, Y
|
Only Item.GetGroundItem: position on the ground. |
Functions that create an item (Item.Give, Item.Drop, Item.GremoryAdd) take the same fields (all optional except Index), plus Duration (seconds before it expires, 0 = never) and Count. Durability = 0 or 255 means the default durability.
Inventory.GetSizes() → number, number, number
Three values: number of equipment slots (12), end of the main inventory (76), total number of inventory slots (239). Slots 0..11 are equipment, the main inventory starts at slot 12.
local equipSlots, mainEnd, total = Inventory.GetSizes()
for slot = equipSlots, mainEnd - 1 do
local item = Player.GetItem(aIndex, slot)
if item ~= nil then Log.Add(Item.GetName(item.Index)) end
endInventory.CountItem(aIndex, itemCode, level) → number
Number of items with this code in the inventory. level -1 = any level. Stacks count their size. Returns 0 for an invalid character or code.
local bless = Inventory.CountItem(aIndex, Helpers.MakeItemId(14, 13), -1)
Message.Send(aIndex, 1, "You have " .. bless .. " Jewels of Bless")Inventory.FreeSlots(aIndex) → number
Number of free 1x1 cells in the inventory.
if Inventory.FreeSlots(aIndex) < 10 then
Message.Send(aIndex, 3, "Free at least 10 cells in your inventory first")
return
endInventory.HasSpaceForItem(aIndex, itemCode) → boolean
true if one item of this code fits in the inventory (uses the item size). false for an unknown item code.
local SOUL = Helpers.MakeItemId(14, 14)
if Inventory.HasSpaceForItem(aIndex, SOUL) then
Item.Give(aIndex, { Index = SOUL })
endInventory.HasSpace(aIndex, width, height) → boolean
true if an item of width x height cells fits. width and height must be 1..8, otherwise false.
if not Inventory.HasSpace(aIndex, 2, 4) then
Message.Send(aIndex, 3, "You need a free 2x4 space for the reward")
endInventory.DeleteSlot(aIndex, slot) → boolean
Deletes the item in one slot, equipment slots included (stats and the character look are updated). false if the slot is empty, the character is trading or has a window open.
local item = Player.GetItem(aIndex, 12)
if item ~= nil and item.Index == Helpers.MakeItemId(12, 15) then
Inventory.DeleteSlot(aIndex, 12) -- removes the Jewel of Chaos in the first cell
endInventory.DeleteItems(aIndex, itemCode, level, count) → boolean
Deletes exactly count items (default 1) of this code. level -1 = any level. If there are not enough, nothing is deleted and it returns false. Also false during a trade or with a window open.
-- Take 10 Jewels of Bless for a reward
local BLESS = Helpers.MakeItemId(14, 13)
if Inventory.DeleteItems(aIndex, BLESS, -1, 10) then
Coin.Add(aIndex, 100, 0, 0)
endInventory.SetItem(aIndex, slot, table) → boolean
Changes only the fields given in the table: Level, Durability, Skill, Luck, Option, Exc, Ancient, Harmony, Option380, Sockets, SocketBonus. The item code (Index) cannot be changed. The slot is sent to the client; for an equipped item the stats are recalculated. false for an empty slot, during a trade or with a window open.
local weapon = Player.GetItem(aIndex, 0)
if weapon ~= nil and weapon.Level < 15 then
Inventory.SetItem(aIndex, 0, { Level = weapon.Level + 1, Luck = 1 })
endInventory.SendSlot(aIndex, slot) → nothing
Sends one inventory slot to the client again. Returns nothing.
-- Refresh the first cell of the main inventory on the client
Inventory.SendSlot(aIndex, 12)Inventory.SendList(aIndex) → nothing
Sends the whole inventory to the client again. Returns nothing.
if Player.CheckItemAction(aIndex) then
Inventory.SendList(aIndex)
endInventory.ReduceDurability(aIndex, slot, amount) → boolean
Lowers the durability of the item in slot by amount (at most 255 at once), like normal wear. false if the slot is empty or amount is 0 or less.
-- The armor (slot 3) loses 5 durability when entering the trap zone
if Inventory.ReduceDurability(aIndex, 3, 5) then
Message.Send(aIndex, 3, "Your armor is damaged by the trap")
endWarehouse.GetItem(aIndex, slot) → item table or nil
Item in a warehouse slot. nil if the slot is empty, out of range, or the warehouse data is not loaded.
local item = Warehouse.GetItem(aIndex, 0)
if item ~= nil then
Message.Send(aIndex, 1, "First warehouse slot: " .. Item.GetName(item.Index) .. " +" .. item.Level)
endWarehouse.CountItem(aIndex, itemCode, level) → number
Number of items with this code in the warehouse. level -1 = any level. Stacks count their size. 0 if the warehouse data is not loaded.
local life = Warehouse.CountItem(aIndex, Helpers.MakeItemId(14, 16), -1)
Message.Send(aIndex, 1, "Jewels of Life in your warehouse: " .. life)EventInventory.GetSize() → number
Number of slots of the event inventory.
local size = EventInventory.GetSize()
Log.Add("Event inventory slots: " .. size)EventInventory.GetItem(aIndex, slot) → item table or nil
Item in an event inventory slot, nil if empty or out of range.
for slot = 0, EventInventory.GetSize() - 1 do
local item = EventInventory.GetItem(aIndex, slot)
if item ~= nil then Log.Add(slot .. ": " .. Item.GetName(item.Index)) end
endEventInventory.CountItem(aIndex, itemCode, level) → number
Number of items with this code in the event inventory. level -1 = any level. Stacks count their size.
-- itemCode: an item that goes to the event inventory
local function HasEventItem(aIndex, itemCode, amount)
return EventInventory.CountItem(aIndex, itemCode, -1) >= amount
endMuunInventory.GetSizes() → number, number
Two values: equipped Muun slots (3), total Muun inventory slots (103). Slots 0..2 are the equipped Muuns.
local equipped, total = MuunInventory.GetSizes()
for slot = 0, equipped - 1 do
if MuunInventory.GetItem(aIndex, slot) == nil then Message.Send(aIndex, 1, "Muun slot " .. slot .. " is empty") end
endMuunInventory.GetItem(aIndex, slot) → item table or nil
Item in a Muun inventory slot (equipped slots included), nil if empty or out of range.
local muun = MuunInventory.GetItem(aIndex, 0)
if muun ~= nil then
Message.Send(aIndex, 1, "First equipped Muun: " .. Item.GetName(muun.Index))
endMuunInventory.CountItem(aIndex, itemCode, level) → number
Number of items with this code in the Muun inventory. level -1 = any level.
local muun = MuunInventory.GetItem(aIndex, 0)
if muun ~= nil and MuunInventory.CountItem(aIndex, muun.Index, -1) > 1 then
Message.Send(aIndex, 1, "You have more than one " .. Item.GetName(muun.Index))
endMuunInventory.DeleteSlot(aIndex, slot) → boolean
Deletes a Muun from the Muun inventory and updates the client. Equipped slots cannot be used. false if the slot is empty or not allowed, during a trade or with a window open.
local _, total = MuunInventory.GetSizes()
local last = total - 1
if MuunInventory.GetItem(aIndex, last) ~= nil then
MuunInventory.DeleteSlot(aIndex, last)
endItem.Give(aIndex, table) → number
Creates the item in the right inventory (main, event or Muun). Count 1..50 (default 1); in the main inventory it is limited by the free cells, event and Muun items are created one at a time. Returns how many were created; 0 if there is no space, the code is invalid, or a trade / window is open.
The item is created a moment later (the server gets a serial number first). Always check the space before giving, or use the Gremory Case.
local given = Item.Give(aIndex, { Index = Helpers.MakeItemId(14, 13), Count = 5 })
if given < 5 then
Message.Send(aIndex, 3, "Not enough space in your inventory")
endItem.Drop(map, x, y, table, ownerIndex) → boolean
Drops the item on the ground. ownerIndex: only that character can pick it up; -1 or nothing: anyone. false if the map is not on this GameServer, x / y are missing or the item table is invalid.
local map, x, y = Object.GetMap(aIndex), Object.GetX(aIndex), Object.GetY(aIndex)
Item.Drop(map, x, y, { Index = Helpers.MakeItemId(14, 22) }, aIndex) -- Jewel of Creation for this characterItem.GiveBag(aIndex, bag) → boolean
Opens a random item bag (ItemBag GUID number or name) into the inventory. false if the bag does not exist, the character is trading or has a window open.
local BAG_ID = 1 -- GUID of a bag from ItemBagList.xml
if not Item.GiveBag(aIndex, BAG_ID) then
Message.Send(aIndex, 3, "The reward could not be given now")
endItem.DropBag(aIndex, bag, map, x, y) → boolean
Drops the items of a random item bag on the ground; the character is the owner. Without map, x, y: at the character. false if the bag does not exist or the map is not on this GameServer.
local BAG_ID = 1 -- GUID of a bag from ItemBagList.xml
Item.DropBag(aIndex, BAG_ID) -- at the character
Item.DropBag(aIndex, BAG_ID, MAP_LORENCIA, 130, 130) -- at a fixed pointItem.GremoryAdd(aIndex, table) → boolean
Sends the item to the Gremory Case. Extra fields: Duration (time in the case in seconds, 0 = 7 days), Count (1..100), Storage (1 = character case, 2 = account case), Reward (reward source shown on the client). Returns false for an invalid character or item code, otherwise true (the item is created a moment later).
Item.GremoryAdd(aIndex, {
Index = Helpers.MakeItemId(12, 37),
Level = 15, Skill = 1, Luck = 1, Option = 4, Exc = 63,
Sockets = { -1, -1, -1, -1, -1 },
Duration = 86400, -- time in the case (seconds), 0 = 7 days
Count = 1, -- 1..100
Storage = 1, -- 1 = character case, 2 = account case
Reward = 100, -- reward source shown on the client
})Item.GremoryFreeSlots(aIndex, storage) → number
Free slots of the Gremory Case. storage 1 = character case (default), 2 = account case.
if Item.GremoryFreeSlots(aIndex, 1) < 5 then
Message.Send(aIndex, 3, "Your Gremory Case is almost full")
endItem.IsValid(itemCode) → boolean
true if the item exists in the item list.
local code = Helpers.MakeItemId(14, 16)
if Item.IsValid(code) then Item.Give(aIndex, { Index = code }) endItem.GetName(itemCode) → string
Item name from the item list, "" for an unknown code.
local code = Helpers.MakeItemId(14, 14)
Message.Send(aIndex, 1, "You received a " .. Item.GetName(code))Item.GetKindA(itemCode) → number
The KindA value of the item in the item list (0 for an unknown code).
local weapon = Player.GetItem(aIndex, 0)
if weapon ~= nil then
Log.Add("KindA of the weapon: " .. Item.GetKindA(weapon.Index))
endItem.GetKindB(itemCode) → number
The KindB value of the item in the item list (0 for an unknown code).
local code = Helpers.MakeItemId(14, 13)
Log.Add(Item.GetName(code) .. " KindA=" .. Item.GetKindA(code) .. " KindB=" .. Item.GetKindB(code))Item.GetSize(itemCode) → number, number
Two values: width and height in inventory cells (0, 0 for an unknown code).
local code = Helpers.MakeItemId(12, 37)
local w, h = Item.GetSize(code)
if Inventory.HasSpace(aIndex, w, h) then Item.Give(aIndex, { Index = code }) endItem.IsSocket(itemCode) → boolean
true if the item is a socket item.
local weapon = Player.GetItem(aIndex, 0)
if weapon ~= nil and Item.IsSocket(weapon.Index) then
Message.Send(aIndex, 1, "Your weapon has sockets")
endItem.IsExcSocketAccessory(itemCode) → boolean
true if the item is a socket pendant or ring.
for slot = 9, 11 do -- pendant and rings
local item = Player.GetItem(aIndex, slot)
if item ~= nil and Item.IsExcSocketAccessory(item.Index) then Log.Add("Socket accessory in slot " .. slot) end
endItem.IsElemental(itemCode) → boolean
true if the item is a pentagram or an errtel (elemental items).
local item = Player.GetItem(aIndex, 12)
if item ~= nil and Item.IsElemental(item.Index) then
Message.Send(aIndex, 3, "Elemental items cannot be exchanged here")
endItem.IsPentagram(itemCode) → boolean
true if the pentagram system knows this code as a pentagram item.
local _, mainEnd = Inventory.GetSizes()
for slot = 12, mainEnd - 1 do
local item = Player.GetItem(aIndex, slot)
if item ~= nil and Item.IsPentagram(item.Index) then Log.Add("Pentagram in slot " .. slot) end
endItem.IsMasterPentagram(itemCode) → boolean
true if the item is a pentagram with mastery.
local item = Player.GetItem(aIndex, 12)
if item ~= nil and Item.IsMasterPentagram(item.Index) then
Message.Send(aIndex, 1, "Mastery pentagram found")
endItem.IsPentagramJewel(itemCode) → boolean
true if the item is an errtel (pentagram jewel).
local item = Player.GetItem(aIndex, 12)
if item ~= nil and Item.IsPentagramJewel(item.Index) then
Message.Send(aIndex, 1, "Errtel: " .. Item.GetName(item.Index))
endItem.IsMasterPentagramJewel(itemCode) → boolean
true if the item is an errtel with mastery.
local item = Player.GetItem(aIndex, 12)
if item ~= nil and Item.IsMasterPentagramJewel(item.Index) then
Message.Send(aIndex, 1, "Mastery errtel: " .. Item.GetName(item.Index))
endItem.GetMaxStack(itemCode) → number
Maximum stack size (0 = not stackable).
local code = Helpers.MakeItemId(14, 13)
local stack = Item.GetMaxStack(code)
Log.Add(Item.GetName(code) .. (stack > 0 and (" stacks up to " .. stack) or " does not stack"))Item.RandomAncientOption(itemCode) → number
A random ancient option value for this item, to use as Ancient when creating it (0 = the item has no set).
local code = Helpers.MakeItemId(12, 37)
local ancient = Item.RandomAncientOption(code)
Item.GremoryAdd(aIndex, { Index = code, Ancient = ancient })Item.RandomLevel(min, max) → number
Random level in [min, max]. Written in Lua in System\Library.lua (calls Util.Random).
local level = Item.RandomLevel(7, 11)
Item.Give(aIndex, { Index = Helpers.MakeItemId(12, 37), Level = level })Item.GetGroundItem(map, itemIndex) → item table or nil
Item on the ground of a map; the table also has X and Y. itemIndex is 0 .. Object.GetMaxItem() - 1. nil if there is no item at this index.
local map = Object.GetMap(aIndex)
for i = 0, Object.GetMaxItem() - 1 do
local item = Item.GetGroundItem(map, i)
if item ~= nil and item.Index == Helpers.MakeItemId(14, 13) then
Message.Send(aIndex, 1, string.format("Jewel of Bless on the ground at %d, %d", item.X, item.Y))
end
endindex can be a character or a monster. Changing the buffs of a character needs the character to be in game.
Buff.Add(index, buffId, seconds, effect1, value1, effect2, value2) → boolean
Adds a buff for seconds seconds. Without effect1: the effects and values of the buff data. Returns true if the target has the buff afterwards; false for an unknown buff id or seconds 0 or less.
local BUFF_ID = 1 -- a buff id from the buff data of your server
if Buff.Add(aIndex, BUFF_ID, 600) then
Message.Send(aIndex, 1, "Buff active for 10 minutes")
endBuff.AddItem(index, itemCode, seconds) → boolean
Adds the buff of an item (potions, scrolls ...) for seconds seconds. false if the item has no buff or seconds is 0 or less.
-- Jack O'Lantern Blessings (14, 46) for 30 minutes
Buff.AddItem(aIndex, Helpers.MakeItemId(14, 46), 1800)Buff.AddCashShop(index, itemCode, seconds) → boolean
Adds the buff of a cash shop item. Characters only. The buff is saved: it is still there after logging in again.
-- Seal of Ascension (13, 43) for 1 day
if Buff.AddCashShop(aIndex, Helpers.MakeItemId(13, 43), 86400) then
Message.Send(aIndex, 1, "Seal active for 24 hours")
endBuff.Remove(index, buffId) → boolean
Removes a buff. false if the target does not have it.
local BUFF_ID = 1
if Buff.Remove(aIndex, BUFF_ID) then
Message.Send(aIndex, 1, "Buff removed")
endBuff.Has(index, buffId) → boolean
true if the buff is active on the character or monster.
local BUFF_ID = 1
if not Buff.Has(aIndex, BUFF_ID) then
Buff.Add(aIndex, BUFF_ID, 300)
endBuff.Clear(index, all) → boolean
Removes the combat buffs; all = true: cash shop buffs too. Returns false if the target is not valid.
-- Remove all combat buffs when entering the arena
if Object.GetMap(aIndex) == MAP_ARENA then
Buff.Clear(aIndex, false)
endNext: Game events