These three functions are used to transfer an item intact between the GameServer and the website (for example an item market on the web, the WebAPI.lua file). The item is transferred as a record string in the same format as the item data stored in the database: the serial, options, sockets, Harmony, 380 and extended fields are kept as they are, so nothing is lost and no new serial is generated. The content of the record string is internal system data: only store it and pass it back verbatim, do not edit it yourself.
Item.TakeRecord function deletes the item from the GameServer as soon as it succeeds. The caller must save the returned record (for example write it to the database) before doing anything else, otherwise the item will be lost.The box value used in the functions: 1 = inventory (slots from 12, after the equipment slots, to the end of the usable inventory part; a comment in the source code states 12 to 203), 2 = warehouse.
Item.GetRecord
Reads the record of the item in a slot (read only, does not delete).
Item.GetRecord(aIndex, box, slot) -> string | nil
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character index |
box | integer | 1 = inventory, 2 = warehouse |
slot | integer | Slot number |
Returns: the record string; nil if the slot is empty or the parameters are wrong.
local rec = Item.GetRecord(aIndex, 1, 20)
if rec then Log.Add(rec) end
Item.TakeRecord
Takes an item out of the character: returns the record and deletes the item from the GameServer.
Item.TakeRecord(aIndex, box, slot [, serial]) -> record, itemCode | nil, reason
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character index (must be in game) |
box | integer | 1 = inventory (worn items and items in a personal store cannot be taken), 2 = warehouse (refused if the warehouse is password-locked) |
slot | integer | Slot number |
serial | integer (optional) | If passed, the item in the slot must have exactly this serial (used when the player picks on the web but the item has just been moved) |
Returns:
- Success: 2 values
record(the record string) anditemCode(the item code). The item has been deleted from the GameServer. - Failure:
niland a reason string in English.
| Reason | Meaning |
|---|---|
character is not in game | The character is not in game |
busy | The character has a window open, is trading or is teleporting |
bad box | box is other than 1 and 2 |
bad slot | The slot is outside the range allowed for box |
warehouse locked | The warehouse is locked |
empty slot | The slot has no item |
item moved | The passed serial does not match the item in the slot |
item not allowed | The item is blocked: it has an expiry time, is locked / not tradable, or is a Pentagram or Errtel |
Every successful take is written to the item log.
local rec, code = Item.TakeRecord(aIndex, 1, 20, serial)
if rec == nil then
Log.AddC(3, "Could not take the item: " .. tostring(code)) -- on failure, the 2nd value is the reason
else
-- Save rec to the database right here
end
Item.GremoryAddRecord
Recreates the exact item from a record (keeping the serial) in the character's Gremory Box.
Item.GremoryAddRecord(aIndex, record [, storage]) -> true | false, reason
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character index (must be in game) |
record | string | The record string of exactly 1 item (from Item.GetRecord / Item.TakeRecord) |
storage | integer | 1 = character box, 2 = account box, any other value or omitted = Personal Store tab (default 3) |
Returns: true if added; false with a reason string if it fails:
| Reason | Meaning |
|---|---|
character is not in game | The character is not in game |
bad record | The record string is not valid (it must contain exactly 1 item) |
unknown item | The item code in the record is not in ItemList |
item already in game | This serial already exists on the character (inventory, warehouse or Gremory): refused to prevent item duplication |
gremory case is full | The Gremory Box is full |
The storage period in the box follows the GremoryCase.xml configuration (key StorageExpire); the usage expiry of the item in the record is kept unchanged.
local ok, why = Item.GremoryAddRecord(aIndex, rec, 1)
if not ok then Log.AddC(3, "GremoryAddRecord: " .. tostring(why)) end