This page describes the format of the item table shared by the functions that read / create / modify items, and the item-creation functions of the Item table. Information about item types (name, size, group) is on the page Item: type information (Item: item type information); the function that transfers an item intact to the website is on the page Item: record for the website (Item: record for the website).
Item table
The read functions (Player.GetItem, Warehouse.GetItem, EventInventory.GetItem, MuunInventory.GetItem, Item.GetGroundItem) return a table with the following fields. The create / modify functions (Item.Give, Item.Drop, Item.GremoryAdd, Inventory.SetItem) accept a table with the same field names.
| Field | Type | When reading | When creating / modifying |
|---|---|---|---|
Index | integer | Item code (group * 512 + sequence number) | Required when creating; must be a code that exists in ItemList. Cannot be changed with Inventory.SetItem |
Serial | number | Serial number | Not used |
Level | integer | Level + | Clamped from 0 to the item's maximum level |
Durability | number | Durability / stack count | 0 to 255. 0 or 255 = default durability |
Skill | integer | Has skill (0 / 1) | Clamped to 0 to 1 |
Luck | integer | Has luck (0 / 1) | Clamped to 0 to 1 |
Option | integer | Additional option | 0 to 255 |
Exc | integer | Excellent attributes (bit mask) | 0 to 255 |
Ancient | integer | Set / Ancient item attributes | 0 to 255 |
Harmony | integer | Harmony option (Jewel of Harmony) | 0 to 255 |
Option380 | integer | 380 option | 0 to 255 |
SocketBonus | integer | Socket bonus | 0 to 255, default 255 |
ExpireDate | number | Expiry time (timestamp); 0 = no expiry | Not used (use Duration when creating) |
Sockets | table | Table of 5 elements (indexes 1 to 5) | Table of 5 elements |
Duration | integer | (not present when reading) | The item's lifetime in seconds counted from creation, maximum 10 years. 0 = no expiry set |
Count | integer | (not present when reading) | Quantity to create (see each function) |
Each element of Sockets: -1 = no socket slot, 254 = empty socket slot, any other value = the code of the socket seed fitted in the slot. A field missing when creating uses the default value above.
Skill and Luck fields also have the old-style names Option1 and Option2; Option = Option3; Exc = NewOption; Ancient = SetOption; Harmony = JoHOption; Option380 = ["380Option"]; Sockets = SocketOption1 to SocketOption5; SocketBonus = SocketOptionBonus; ExpireDate = DurationTime. The old names only exist in tables returned by the short-name functions (InventoryGetItemTable, EventInventoryGetItemTable, MuunInventoryGetItemTable, MapGetItemTable), and are accepted in tables passed to InventorySetItemTable.Giving items to a character
Item.Give
Creates an item and puts it into the character's inventory. Creation is asynchronous (GameServer requests the serial number from the database and only then adds it to the inventory), so the function checks for free space first and limits the quantity to the remaining space.
Item.Give(aIndex, item) -> integer
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character index |
item | table | Item table (see above). Count from 1 to 50 (default 1) |
Returns: the number of items requested to be created; 0 if there is not enough space, the table is wrong (the code does not exist), the character is trading / has a window open or the conditions are not met. Rules by type:
- Event bag items: need free space in the event bag, always create 1.
- Muun items: need a free slot in the Muun bag, always create 1.
- Normal items: need space for at least 1;
Countis limited by the number of free cells divided by the item's area (width x height).
Short names: ItemGiveEx(aIndex, item, level, dur, skill, luck, option, exc, ancient, harmony, opt380, s1, s2, s3, s4, s5, socketBonus, duration), and CreateItem(useType = 1, aIndex, ...). You should call Player.CheckItemAction first.
local given = Item.Give(aIndex, { Index = 7181, Count = 5 })
if given == 0 then
Message.Send(aIndex, 1, "Your inventory is full")
end
-- An item with attributes, valid for 7 days
Item.Give(aIndex, { Index = 3 * 512 + 5, Level = 9, Luck = 1, Option = 4, Exc = 1, Duration = 7 * 86400 })
Item.GiveBag
Opens a random item bag (ItemBag) and puts the items into the character's inventory at the position where the character is standing.
Item.GiveBag(aIndex, bag) -> boolean
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character index |
bag | integer or string | Number (GUID) or name of the ItemBag |
Returns: true if the bag was executed; false if the bag was not found, the character is trading or the conditions are not met. Short name: ItemGive.
Item.GiveBag does not check for free space in the inventory. Any item that cannot be added to the inventory (inventory full) is not created: it does not drop on the ground and is not moved to the Gremory Box. If you need to be sure the full reward is received, check for free space first, or use Item.GremoryAdd to give the reward.Item.GiveBag(aIndex, "DailyReward")
Item.DropBag
Opens a random item bag and makes the items drop on the ground. The character is the owner of the items.
Item.DropBag(aIndex, bag [, map, x, y]) -> boolean
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character index |
bag | integer or string | Number (GUID) or name of the ItemBag |
map | integer | Map where it drops; defaults to the character's map |
x, y | integer | Drop coordinates (clamped from 0 to 255); defaults to the character's coordinates |
Returns: true if it was executed; false if the bag was not found, the map does not exist or the conditions are not met. Short name: ItemDrop(aIndex, map, x, y, bag).
Item.DropBag(aIndex, "BossReward", Object.GetMap(aIndex), Object.GetX(aIndex), Object.GetY(aIndex))
Items lying on the ground
Item.Drop
Makes an item drop on the ground.
Item.Drop(map, x, y, item [, ownerIndex]) -> boolean
| Parameter | Type | Description |
|---|---|---|
map | integer | Map number (must exist on this GameServer) |
x, y | integer | Drop coordinates (clamped from 0 to 255) |
item | table | Item table (see above). The Count field is not used: each call drops 1 item |
ownerIndex | integer | Index of the character / monster that owns the item (only that one can pick it up). -1 or omitted = anyone can pick it up |
Returns: true if the drop was requested; false if the map does not exist, the table is wrong or the script is in restricted mode. Short names: ItemDropEx(aIndex, map, x, y, item, level, dur, skill, luck, option, exc, ancient, harmony, opt380, s1, s2, s3, s4, s5, socketBonus, duration) (aIndex is the owner), and CreateItem(useType = 0, ...).
When there is a valid ownerIndex, only the owner can pick up the item and this right does not expire (the item stays there until it is picked up or disappears according to the item's lifetime on the ground); other players cannot pick it up, even in the same party. Administrator accounts are not subject to this restriction.
Item.Drop(MAP_LORENCIA, 130, 130, { Index = 14 * 512 + 13 }) -- a Jewel of Bless drops in the middle of Lorencia
Item.GetGroundItem
Reads the information of an item lying on the ground.
Item.GetGroundItem(map, itemIndex) -> table | nil
| Parameter | Type | Description |
|---|---|---|
map | integer | Map number |
itemIndex | integer | Index of the item on the map (from 0 to Object.GetMaxItem() - 1) |
Returns: an item table with two extra fields X and Y (the position); nil if the slot has no item or the parameters are wrong. Short name: MapGetItemTable(map, index) (the table also has the old-style field names).
local it = Item.GetGroundItem(MAP_LORENCIA, 0)
if it then Log.Add("Item " .. it.Index .. " at " .. it.X .. "," .. it.Y) end
Gremory Box
Item.GremoryAdd
Adds an item to the character's Gremory Box (used when you want to give a reward without needing free inventory space).
Item.GremoryAdd(aIndex, item) -> boolean
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character index |
item | table | Item table (see above) plus the two special fields below. Count from 1 to 100 (default 1) |
The two special fields of this function:
| Field | Value | Meaning |
|---|---|---|
Storage | 1 (default), 2, 3 | Where it is stored: 1 = the character's box, 2 = the account's box, 3 = the Personal Store tab (150 slots, used for items put up for sale). Values other than 2 and 3 are treated as 1 |
Reward | integer 0 to 255 | Reward source shown in the box. The default is the "GM reward" source (with Storage = 3 the default is the event source) |
Returns: true if the addition was requested; false if the character does not meet the conditions, item is not a table or the item code does not exist. The function does not check whether the box has space: use Item.GremoryFreeSlots first if needed.
Short names: InsertItem_GremoryCaseEx(aIndex, storage, reward, index, level, dur, skill, luck, option, ancient, opt380, harmony, exc, unused, s1, s2, s3, s4, s5, socketBonus, duration, count) and InsertItem_GremoryCase(aIndex, storage, reward, index, level, dur, skill, luck, option, ancient, isSocket, isElemental, muunEvo, exc, masteryExe, s1, s2, s3, s4, s5, socketBonus, receiptDuration, duration, count). With the second short name, the receiptDuration value is used as Duration and duration is ignored; the parameters isSocket, isElemental, muunEvo, masteryExe are ignored.
The Duration field (seconds), when greater than 0, sets the item's usage time limit (counted from the moment it is added to the box, and kept as is when the player takes it out into the inventory); 0 = the item has no usage time limit. Duration is not the time the item is kept in the box.
Item.GremoryAdd(aIndex, { Index = 14 * 512 + 13, Count = 10, Storage = 2 })
Item.GremoryFreeSlots
Returns the number of free slots in the Gremory Box.
Item.GremoryFreeSlots(aIndex [, storage]) -> integer
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character index |
storage | integer | 1 = character box (default), 2 = account box, 3 = Personal Store tab |
Returns: the number of free slots; 0 if invalid. Short name: GCTotalFreeSlotCount(aIndex, storage).
if Item.GremoryFreeSlots(aIndex, 1) >= 3 then
Item.GremoryAdd(aIndex, { Index = 14 * 512 + 13, Count = 3 })
end
Item.RandomLevel
Returns a random item level (+) in the range minLevel to maxLevel (both ends included). Use it when building rewards with a random level yourself.
Item.RandomLevel(minLevel, maxLevel) -> integer
| Parameter | Type | Description |
|---|---|---|
minLevel | integer | Lowest level (limited to 0 up to the item's maximum level, which is 15) |
maxLevel | integer | Highest level (limited to 0 to 15) |
Returns: an integer from minLevel to maxLevel. If minLevel is greater than maxLevel, the two numbers are swapped automatically; a missing parameter is treated as 0. Short name: GetBagItemLevel(min, max).
-- give 1 sword (group 0, number 0) with a random level from +7 to +9
local level = Item.RandomLevel(7, 9)
Item.Give(aIndex, { Index = 0 * 512 + 0, Level = level })