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.

The 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
ParameterTypeDescription
aIndexintegerCharacter index
boxinteger1 = inventory, 2 = warehouse
slotintegerSlot 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
ParameterTypeDescription
aIndexintegerCharacter index (must be in game)
boxinteger1 = inventory (worn items and items in a personal store cannot be taken), 2 = warehouse (refused if the warehouse is password-locked)
slotintegerSlot number
serialinteger (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) and itemCode (the item code). The item has been deleted from the GameServer.
  • Failure: nil and a reason string in English.
ReasonMeaning
character is not in gameThe character is not in game
busyThe character has a window open, is trading or is teleporting
bad boxbox is other than 1 and 2
bad slotThe slot is outside the range allowed for box
warehouse lockedThe warehouse is locked
empty slotThe slot has no item
item movedThe passed serial does not match the item in the slot
item not allowedThe 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
ParameterTypeDescription
aIndexintegerCharacter index (must be in game)
recordstringThe record string of exactly 1 item (from Item.GetRecord / Item.TakeRecord)
storageinteger1 = 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:

ReasonMeaning
character is not in gameThe character is not in game
bad recordThe record string is not valid (it must contain exactly 1 item)
unknown itemThe item code in the record is not in ItemList
item already in gameThis serial already exists on the character (inventory, warehouse or Gremory): refused to prevent item duplication
gremory case is fullThe 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