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).
| Table | Contents |
|---|---|
Server, Event, LoadScript | Server information, loading Lua files |
Object | Generic object (player / monster / NPC): position, HP/MP, iterating over lists |
Player | Character: read, write, send information to the client, move |
Coin | WCoin / GoblinPoint |
Message | Notices, dialog boxes, NPC speech, getting language strings |
Monster, Skill, Party, Map | Monsters, skill tracking, party, map |
Inventory, Warehouse, EventInventory, MuunInventory | Main inventory, warehouse, event inventory, Muun inventory |
Item | Create / drop / Gremory box / item type information |
Buff | Effects (buffs) |
DB | Database queries |
File, Config | Read text / INI / XML files, read and write INI files |
Log, Util | Logging, random numbers, splitting parameters |
Parameters and return values
aIndexis 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
NaNnumber (for example0/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 examplePlayer.GiveExperience(aIndex, 0/0)returnsfalse). - Read functions: if there is no character / it is invalid, they return
0(number), an empty string (string),false(check) ornil(table). - Write functions (setters): if the character is missing or the value is not a number, they do nothing and return
false(for examplePlayer.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
| Type | Character condition | Used for |
|---|---|---|
| Read | Logged in (state LOGGED or higher) | Get... functions, counting, checks |
| Send | Logged in (LOGGED or higher) | Sending notices / information packets to the client |
| Write | In game (state PLAYING), not inside onPlayerLogout and not in restricted mode | Changing 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.
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).