The function reference pages in this section fully describe the functions that GameServer provides to Lua scripts. This page summarizes the general rules that apply to every function, so the following pages do not need to repeat them.

List of function groups (namespaces)

Functions are divided into global tables (namespaces). Call them in the form Name.Function(...), for example Player.GetLevel(aIndex).

TableContents
Server, Event, LoadScriptServer information, loading Lua files
ObjectGeneric object (player / monster / NPC): position, HP/MP, iterating over lists
PlayerCharacter: read, write, send information to the client, move
CoinWCoin / GoblinPoint
MessageNotices, dialog boxes, NPC speech, getting language strings
Monster, Skill, Party, MapMonsters, skill tracking, party, map
Inventory, Warehouse, EventInventory, MuunInventoryMain inventory, warehouse, event inventory, Muun inventory
ItemCreate / drop / Gremory box / item type information
BuffEffects (buffs)
DBDatabase queries
File, ConfigRead text / INI / XML files, read and write INI files
Log, UtilLogging, random numbers, splitting parameters

Parameters and return values

  • aIndex is the object index (player, monster, NPC) in GameServer. It must be a number within the valid range; otherwise the function treats it as no object.
  • A parameter of the wrong type does not cause a Lua error: a number is replaced by the default value, a string by an empty string. Note that only the number type is accepted as a number; a string such as "5" is not converted to a number automatically.
  • A NaN number (for example 0/0) or an infinite number (math.huge) passed to any API function is treated as invalid: the default value is used or the function fails (for example Player.GiveExperience(aIndex, 0/0) returns false).
  • Read functions: if there is no character / it is invalid, they return 0 (number), an empty string (string), false (check) or nil (table).
  • Write functions (setters): if the character is missing or the value is not a number, they do nothing and return false (for example Player.SetMoney(aIndex, nil) does not clear zen).
  • Numbers are clamped to the valid range (for example a level is clamped between 1 and the maximum level) instead of raising an error.
  • Strings sent to the client that exceed the limit are cut on a UTF-8 boundary (NPC speech maximum 1024 bytes; a dialog box holds only 150 bytes of content).
  • If a C++ function hits an exception, GameServer converts it into a Lua error with the prefix C++: (it does not crash GameServer).

Permissions by character state

TypeCharacter conditionUsed for
ReadLogged in (state LOGGED or higher)Get... functions, counting, checks
SendLogged in (LOGGED or higher)Sending notices / information packets to the client
WriteIn game (state PLAYING), not inside onPlayerLogout and not in restricted modeChanging data, moving, creating / deleting items

The connection states in order: NONE = 0 (not connected), CONNECTED = 1 (connected), LOGGED = 2 (account logged in), PLAYING = 3 (in game). In System\Constants.lua these values correspond to OBJECT_OFFLINE = 0, OBJECT_CONNECTED = 1, OBJECT_LOGGED = 2, OBJECT_ONLINE = 3.

When a write function is called for a player who is leaving the game (inside onPlayerLogout) or who has not entered the game yet, the function returns false / does nothing. To save data at logout, use DB.Execute.

Restricted mode

Some blocking events (callback functions that can refuse a player's action) are called in restricted mode, when the character is in the middle of combat, dead, trading or moving. In this mode the script may only read data and send notices. The following functions are blocked (they return false / -1 / do nothing): all player write functions, creating / deleting monsters (Monster.*), creating dropped items (Item.Drop), teleporting (Object.Warp), changing buffs.

Short names

Besides the Namespace.Function form, the file Data\LuaAPI\System\Modules.lua defines many short names (for example GetObjectLevel = Player.GetLevel) so that older scripts can be reused. Each function in the following pages states its short name if there is one. Do not edit the Modules.lua file.

Tables and functions created from C++ exist only in the Namespace.Function form; the short names are Lua wrapper functions, and some have small differences in return type (for example returning 1 / 0 instead of true / false).

Item table

Functions that read items (Player.GetItem, Warehouse.GetItem, ...) return a table, and functions that create / modify items take a table in the same format. See the page "Item" for details (link Item: create, drop, random bags, Gremory box).