Repository navigation
LuaAPI Functions
itvnnnd87 edited this page Oct 24, 2026
·
3 revisions
Note
If the character does not exist or is not in game, read functions return 0 or "" and write functions do nothing and return false.
Write functions only work while the character is in game. Arguments of the wrong type are ignored: Player.SetMoney(i, nil) does not clear the Zen.
| Function | Description |
|---|---|
Server.GetCode() |
GameServer code (ServerCode). |
Server.GetOnlineCount() |
Players online on this GameServer. |
Works for every object: characters, monsters, NPCs.
| Function | Description |
|---|---|
Object.GetUserRange() |
Returns 2 values: lowest and highest character index. |
Object.GetMonsterRange() |
Returns 2 values: lowest and highest monster index. |
Object.GetType(index) |
0 empty, 1 character, 2 monster, 3 NPC, 5 item on the ground. |
Object.GetConnectStatus(index) |
0 empty, 1 connected, 2 logged in, 3 in game. |
Object.GetName(index) |
Name. |
Object.GetClass(index) |
Character class / monster ID. |
Object.GetMap(index), GetX, GetY
|
Map and position. |
Object.ForEachPlayer(function(aIndex) ... end) |
Calls the function for every character in game. Return false to stop. |
Object.ForEachPlayer(function(aIndex)
Message.Send(aIndex, 0, "The event has started!")
end)| Function | Description |
|---|---|
Player.IsOnline(aIndex) |
true if the character is in game. |
Player.GetName(aIndex) |
Character name. |
Player.GetAccount(aIndex) |
Account name. |
Player.GetAccountID(aIndex) |
Account ID (number, for SQL). |
Player.GetCharacterID(aIndex) |
Character ID in the database (guid). |
Player.GetIndexByName(name) |
aIndex of an online character, -1 if not found. |
Player.GetClass(aIndex) |
Character class. |
Player.GetVIP(aIndex) |
Account VIP level. |
Player.GetLevel, GetMasterLevel, GetMajesticLevel
|
Normal / Master / Majestic level. |
Player.GetLevelUpPoint, GetMasterPoint, GetMajesticPoint
|
Unspent points. |
Player.GetStat(aIndex, stat) |
Base stat. stat: 0 Strength, 1 Agility, 2 Vitality, 3 Energy, 4 Command. |
Player.GetMoney(aIndex) |
Zen. |
Player.GetReset(aIndex) |
Reset count. |
Player.GetPKCount, GetPKLevel, GetPKTimer
|
Kill count, PK level, PK time (seconds). |
Player.GetItem(aIndex, slot) |
Table of the item in an inventory slot, nil if the slot is empty (see below). |
Fields returned by Player.GetItem:
| Field | Meaning |
|---|---|
Index |
Item code (group * 512 + index). |
Serial |
Serial number. |
Level, Durability
|
Level, durability. |
Skill, Luck, Option
|
Skill, luck, additional option. |
Exc, Ancient, Harmony, Option380
|
Excellent (bit mask), ancient, harmony, 380 option. |
Sockets |
5 values: -1 no socket, 254 empty socket. |
SocketBonus, ExpireDate
|
Socket bonus, expiry time. |
Return true / false.
| Function | Description |
|---|---|
Player.SetLevel(aIndex, level) |
Normal level (experience is reset to 0). Update the client with SendLevelUp / SendInfo. |
Player.SetLevelUpPoint(aIndex, v) |
Unspent points. |
Player.SetMasterPoint(aIndex, v) |
Updates the client. |
Player.SetMajesticPoint(aIndex, v) |
Updates the client. |
Player.SetStat(aIndex, stat, v) |
Update the client with Player.ReCalc / SendInfo. |
Player.SetMoney(aIndex, zen) |
Updates the client. Capped at the server Zen limit. |
Player.SetReset(aIndex, v) |
Update the client with Player.SendInfo. |
Player.SetPKCount(aIndex, v) |
|
Player.SetPKLevel(aIndex, v) |
Updates the name colour. 0..6 (3 = normal, 6 = murderer level 3). |
Player.SetPKTimer(aIndex, seconds) |
| Function | Description |
|---|---|
Player.ReCalc(aIndex) |
Recalculates stats (after changing points / items) and updates the client. |
Player.SendInfo(aIndex) |
Resends all character information. |
Player.SendLevelUp(aIndex) |
Sends level, points and max HP / MP. |
Player.SendStats(aIndex), Player.SendMoney(aIndex)
|
|
Player.Disconnect(aIndex) |
Disconnects the player. |
Player.MoveGate(aIndex, gate) |
Moves to a gate. false if dead or a window is open. |
Player.MoveTo(aIndex, map, x, y) |
Teleports (the map must exist on this GameServer). |
Player.OpenWarehouse(aIndex) |
Opens the warehouse without an NPC. false if another window is open. |
Player.ResetMasterTree(aIndex, group) |
Resets the Master skill tree: group 0 / 1 / 2, -1 = all. |
Player.ResetMajesticTree(aIndex) |
Resets the Majestic skill tree. |
Player.SetWindowText(aIndex, text) |
Game window title (up to 255 bytes). |
| Function | Description |
|---|---|
Coin.Get(aIndex) |
Table { WCoinC, WCoinP, GoblinPoint }. |
Coin.Add(aIndex, wcoinC, wcoinP, goblin) |
Adds coins, saves to the database at once and updates the client. |
Coin.Sub(aIndex, wcoinC, wcoinP, goblin) |
Subtracts coins. If there are not enough, nothing is taken and it returns false. |
This version has no WCoinP (always 0).
if Coin.Sub(aIndex, 100, 0, 0) then
Message.Send(aIndex, 1, "100 WCoinC taken")
else
Message.Send(aIndex, 3, "Not enough WCoinC")
endMessage type: 0 gold (screen centre), 1 blue, 2 guild, 3 red.
| Function | Description |
|---|---|
Message.Send(aIndex, type, text) |
To one player. |
Message.SendAll(type, text) |
To everyone on this GameServer. |
Message.SendGlobal(type, text) |
To every GameServer (through Server_Link). |
Message.Box(aIndex, type, title, text) |
Message box in the screen centre (text up to 1023 bytes). |
Message.NpcSay(npcIndex, aIndex, text) |
An NPC talks to one player; aIndex = -1: to everyone nearby. |
Item.GremoryAdd(aIndex, table): sends an item to the Gremory Case, returns true / false.
Item.GremoryAdd(aIndex, {
Index = 12 * 512 + 37, -- item code = group * 512 + index (required)
Level = 15, Durability = 0, -- durability 0 = default
Skill = 1, Luck = 1, Option = 4, Exc = 63,
Ancient = 0, Harmony = 0, Option380 = 0,
Sockets = { -1, -1, -1, -1, -1 }, -- -1 no socket, 254 empty socket
SocketBonus = 255,
Duration = 86400, -- time in the case (seconds), 0 = 7 days
Count = 1, -- 1..100
Storage = 1, -- 1 = character case, 2 = account case
Reward = 100, -- reward source shown on the client
})| Function | Description |
|---|---|
Map.GetName(map) |
Map name. |
Log.Add(text) |
Writes to the GameServer log. |
Log.AddC(color, text) |
1 = red (error), 3 = yellow (warning), anything else = normal. |
Util.Random(min, max) |
Random integer in [min, max]. |
Util.GetTick() |
Milliseconds since the machine started. |
Util.ArgNumber(text, pos) |
Argument at pos (starting at 0) as a number. |
Util.ArgString(text, pos) |
Argument at pos as a string. |
DB.*: see Database. File.* and LoadScript: see Config files.
Next: Reading config files