Repository navigation
LuaAPI Player
aIndex is the index of a character in game. Read functions return 0 / "" / nil for a character that is not in game; write functions return false and do nothing.
Write functions (everything that changes the character) need the character to be fully in game: they do nothing during onPlayerLogout either. A write function called with a missing or non-number value does nothing (for example Player.SetMoney(aIndex, nil) does not clear the Zen).
Player.IsOnline(aIndex) → boolean
true if aIndex is a character that is in game. Any other index (monster, NPC, empty slot, character still at character select) gives false.
if Player.IsOnline(aIndex) then
Message.Send(aIndex, 1, "Welcome back!")
endPlayer.IsOffline(aIndex) → boolean
true if the character is in offline mode (off-attack / off-store): it stays in game but nobody is playing it.
if not Player.IsOffline(aIndex) then
Message.Send(aIndex, 0, "Event starts in 5 minutes!")
endPlayer.GetName(aIndex) → string
Character name. "" if the character is not logged in.
local name = Player.GetName(aIndex)
Message.SendAll(0, name .. " has entered the game")Player.GetAccount(aIndex) → string
Account name (login) of the character.
local account = Player.GetAccount(aIndex)
Log.Add("Login: " .. account .. " / " .. Player.GetName(aIndex))Player.GetAccountID(aIndex) → number
Account ID number in the database. Use it in SQL queries instead of the account name.
local accountId = Player.GetAccountID(aIndex)
DB.Execute("UPDATE my_rewards SET claimed = 1 WHERE account_id = " .. accountId)Player.GetCharacterID(aIndex) → number
Character ID number in the database.
local charId = Player.GetCharacterID(aIndex)
DB.Execute("INSERT INTO my_log (char_id, action) VALUES (" .. charId .. ", 'login')")Player.GetIndexByName(name) → number
aIndex of the in-game character with this name (upper / lower case does not matter). -1 if no character with this name is in game on this GameServer.
local target = Player.GetIndexByName("Hero")
if target ~= -1 then
Message.Send(target, 1, Player.GetName(aIndex) .. " is looking for you")
endPlayer.GetClass(aIndex) → number
Character class, one of the CLASS_* constants (CLASS_DW, CLASS_DK, CLASS_FE ...). It does not change with evolutions: use Player.GetEvolution for that.
if Player.GetClass(aIndex) == CLASS_DK then
Message.Send(aIndex, 1, "Dark Knights get a bonus today")
endPlayer.GetDBClass(aIndex) → number
Class value stored in the database. It contains the class and the evolution together.
local dbClass = Player.GetDBClass(aIndex)
Log.Add(Player.GetName(aIndex) .. " db class " .. dbClass)Player.GetEvolution(aIndex) → number
Number of class evolutions done, from 0 (none) to 3.
if Player.GetEvolution(aIndex) < 2 then
Message.Send(aIndex, 3, "You need your second class change to enter")
endPlayer.GetVIP(aIndex) → number
VIP level of the account. -1 means no VIP.
if Player.GetVIP(aIndex) > 0 then
Message.Send(aIndex, 1, "VIP level " .. Player.GetVIP(aIndex))
endPlayer.GetVIPExpire(aIndex) → number
Time when the VIP ends, as a Unix timestamp (seconds, same unit as os.time()).
local left = Player.GetVIPExpire(aIndex) - os.time()
if left > 0 then
Message.Send(aIndex, 1, "VIP ends in " .. math.floor(left / 86400) .. " days")
endPlayer.GetAuthority(aIndex) → number
Authority value of the character (the value that marks normal players and GMs).
local authority = Player.GetAuthority(aIndex)
Log.Add(Player.GetName(aIndex) .. " authority " .. authority)Player.IsGameMaster(aIndex) → boolean
true for a GM character whose GM rights are switched on (.auth). A GM with rights switched off gives false.
if not Player.IsGameMaster(aIndex) then
Message.Send(aIndex, 3, "This command is for GMs only")
endPlayer.HasAdminFlag(aIndex, flag) → boolean
true if the character is a GM and has the admin right flag. flag is a bit value from the server GM rights list (for example 64 = mute, 512 = ban). false for normal players and for flag 0.
local FLAG_MUTE = 64
if Player.HasAdminFlag(aIndex, FLAG_MUTE) then
Message.Send(aIndex, 1, "You may mute players")
endPlayer.GetCodePage(aIndex) → number
Code page of the player's client, which tells the client language.
local codePage = Player.GetCodePage(aIndex)
Log.Add(Player.GetName(aIndex) .. " code page " .. codePage)Player.GetIP(aIndex) → string
IP address of the player.
Log.Add(Player.GetName(aIndex) .. " connected from " .. Player.GetIP(aIndex))Player.GetMac(aIndex) → string
MAC address sent by the player's client.
local mac = Player.GetMac(aIndex)
Log.Add(Player.GetAccount(aIndex) .. " MAC " .. mac)Player.GetDiskSerial(aIndex) → number
Serial number of the player's disk, as a number.
local serial = Player.GetDiskSerial(aIndex)
Log.Add(Player.GetAccount(aIndex) .. " disk " .. serial)Player.GetHardwareId(aIndex) → string
Machine ID: MAC address and disk serial (8 hex digits) joined by -. Useful to limit characters per computer.
local hwid = Player.GetHardwareId(aIndex)
DB.Execute("INSERT INTO my_hwid (hwid) VALUES ('" .. DB.Escape(hwid) .. "')")Player.GetLevel(aIndex) → number
Normal level of the character.
local level = Player.GetLevel(aIndex)
Message.Send(aIndex, 1, "Your level is " .. level)Player.GetMasterLevel(aIndex) → number
Master level of the character (0 if not a master yet).
local master = Player.GetMasterLevel(aIndex)
Message.Send(aIndex, 1, "Master level " .. master)Player.GetMajesticLevel(aIndex) → number
Majestic level of the character.
if Player.GetMajesticLevel(aIndex) >= 100 then
Message.Send(aIndex, 1, "You can enter the Majestic zone")
endPlayer.GetTotalLevel(aIndex) → number
Normal + Master + Majestic level.
if Player.GetTotalLevel(aIndex) < 400 then
Message.Send(aIndex, 3, "You need total level 400")
endPlayer.GetLevelUpPoint(aIndex) → number
Unspent stat points (normal level).
local points = Player.GetLevelUpPoint(aIndex)
Message.Send(aIndex, 1, "You have " .. points .. " free points")Player.GetMasterPoint(aIndex) → number
Unspent Master skill tree points.
local points = Player.GetMasterPoint(aIndex)
Message.Send(aIndex, 1, "Free Master points: " .. points)Player.GetMajesticPoint(aIndex) → number
Unspent Majestic skill tree points.
local points = Player.GetMajesticPoint(aIndex)
Message.Send(aIndex, 1, "Free Majestic points: " .. points)Player.GetUsedMasterPoints(aIndex) → number
Points spent in the Master skill tree (sum of the levels of all Master skills).
local used = Player.GetUsedMasterPoints(aIndex)
local free = Player.GetMasterPoint(aIndex)
Message.Send(aIndex, 1, "Master points: " .. used .. " used, " .. free .. " free")Player.GetExperience(aIndex, levelType) → number
Current experience. levelType: 0 normal (default), 1 master, 2 majestic. Another value returns 0.
local exp = Player.GetExperience(aIndex, 0)
Message.Send(aIndex, 1, "Experience: " .. exp)Player.GetNextExperience(aIndex, levelType) → number
Experience needed for the next level. levelType: 0 normal (default), 1 master, 2 majestic.
local need = Player.GetNextExperience(aIndex, 1) - Player.GetExperience(aIndex, 1)
Message.Send(aIndex, 1, "Master exp left: " .. need)Player.GetLastGainedExp(aIndex) → number
Amount of the last experience the character received.
local exp = Player.GetLastGainedExp(aIndex)
Message.Send(aIndex, 1, "Last experience gained: " .. exp)Player.GetReset(aIndex) → number
Reset count of the character.
local resets = Player.GetReset(aIndex)
Message.Send(aIndex, 1, "You have " .. resets .. " resets")stat values: STAT_STRENGTH 0, STAT_AGILITY 1, STAT_VITALITY 2, STAT_ENERGY 3, STAT_LEADERSHIP 4. Another value returns 0.
HP / MP / SD / AG and combat stats: Object.GetPower, Object.GetCombatStat (Function reference).
Player.GetStat(aIndex, stat) → number
Base stat (the points the character has put in).
local str = Player.GetStat(aIndex, STAT_STRENGTH)
Message.Send(aIndex, 1, "Base strength: " .. str)Player.GetAddStat(aIndex, stat) → number
Stat added by items, buffs and other bonuses. The value comes from the last stat calculation.
local bonus = Player.GetAddStat(aIndex, STAT_ENERGY)
Message.Send(aIndex, 1, "Energy from items and buffs: " .. bonus)Player.GetTotalStat(aIndex, stat) → number
Base stat + added stat.
if Player.GetTotalStat(aIndex, STAT_AGILITY) < 1000 then
Message.Send(aIndex, 3, "You need 1000 agility")
endPlayer.GetDefaultStat(aIndex, stat) → number
Starting value of the stat for the character's class.
local start = Player.GetDefaultStat(aIndex, STAT_VITALITY)
local added = Player.GetStat(aIndex, STAT_VITALITY) - start
Message.Send(aIndex, 1, "Vitality added since creation: " .. added)Player.GetMoney(aIndex) → number
Zen in the inventory.
if Player.GetMoney(aIndex) < 1000000 then
Message.Send(aIndex, 3, "You need 1,000,000 Zen")
endPlayer.GetRuud(aIndex) → number
Ruud of the character.
local ruud = Player.GetRuud(aIndex)
Message.Send(aIndex, 1, "Ruud: " .. ruud)Player.GetTradeZen(aIndex) → number
Zen the character has placed in the open trade window, 0 if no trade is open.
local zen = Player.GetTradeZen(aIndex)
Log.Add(Player.GetName(aIndex) .. " offers " .. zen .. " Zen in trade")Player.GetPKCount(aIndex) → number
Kill count used for the PK status.
local kills = Player.GetPKCount(aIndex)
Message.Send(aIndex, 1, "PK count: " .. kills)Player.GetPKLevel(aIndex) → number
PK level, 0..6: 3 is normal, values above 3 are murderer levels (6 = murderer level 3), values below 3 are hero levels.
if Player.GetPKLevel(aIndex) > 3 then
Message.Send(aIndex, 3, "Murderers cannot use this NPC")
endPlayer.GetPKTimer(aIndex) → number
PK points left: how much the character still has to "pay" before the PK status ends. The server checks it, not the client. The points do not go down with time: every monster the character kills takes away points equal to the monster level. When they reach 0 the character is a commoner again.
The points also set the PK level: above 43200 = murderer level 3 (hero for heroes), above 21600 = level 2, above 0 = level 1. A kill sets them to 21600 (1st), 43200 (2nd) or 86400 + 3600 per extra kill (3rd and more), up to the server's murder limit. The /pkpoints chat command shows the same value to the player.
local points = Player.GetPKTimer(aIndex)
if points > 0 then
Message.Send(aIndex, 1, "Kill monsters worth " .. points .. " levels to clear your PK status")
endPlayer.GetPKTotalCount(aIndex) → number
Total number of players this character has killed (statistics, does not go down).
local total = Player.GetPKTotalCount(aIndex)
Message.Send(aIndex, 1, "Players killed in total: " .. total)Player.GetMuteTime(aIndex) → number
Seconds of chat ban left, 0 if the character is not muted.
local left = Player.GetMuteTime(aIndex)
if left > 0 then
Message.Send(aIndex, 3, "You are muted for " .. left .. " seconds")
endPlayer.GetPartyNumber(aIndex) → number
Party number, -1 if the character is not in a party. Use it with the Party functions.
local party = Player.GetPartyNumber(aIndex)
if party ~= -1 then
Message.Send(aIndex, 1, "Party members: " .. Party.GetCount(party))
endPlayer.GetGuildNumber(aIndex) → number
Guild number, 0 if the character has no guild.
if Player.GetGuildNumber(aIndex) == 0 then
Message.Send(aIndex, 3, "You must be in a guild")
endPlayer.GetGuildName(aIndex) → string
Guild name, "" if the character has no guild.
local guild = Player.GetGuildName(aIndex)
if guild ~= "" then
Message.Send(aIndex, 2, "Welcome, member of " .. guild)
endPlayer.GetGuildStatus(aIndex) → number
Rank in the guild: 128 guild master, 64 assistant, 32 battle master, 0 member, -1 no guild.
if Player.GetGuildStatus(aIndex) == 128 then
Message.Send(aIndex, 1, "Only guild masters can register")
endPlayer.GetGuildUnionNumber(aIndex) → number
Alliance number of the character's guild, 0 if no guild or no alliance.
if Player.GetGuildUnionNumber(aIndex) ~= 0 then
Message.Send(aIndex, 1, "Your guild is in an alliance")
endPlayer.GetGuildUnionName(aIndex) → string
Name of the alliance (the alliance master guild), "" if none.
local union = Player.GetGuildUnionName(aIndex)
if union ~= "" then
Message.Send(aIndex, 2, "Alliance: " .. union)
endPlayer.GetGuildRelationship(aIndex, bIndex) → number
Guild relationship between two characters: 0 none, 1 alliance, 2 rival, 4 alliance master, 8 rival master. 0 if one of them has no guild or is not logged in.
local target = Object.GetTarget(aIndex)
if target ~= -1 and Player.GetGuildRelationship(aIndex, target) == 2 then
Message.Send(aIndex, 3, "This is a rival guild member")
endPlayer.GetGensFamily(aIndex) → number
Gens family: 0 none, 1 Duprian, 2 Vanert.
local family = Player.GetGensFamily(aIndex)
if family == 0 then
Message.Send(aIndex, 3, "Join a Gens first")
endPlayer.GetGensRank(aIndex) → number
Gens ranking position.
local rank = Player.GetGensRank(aIndex)
Message.Send(aIndex, 1, "Gens ranking: " .. rank)Player.GetGensSymbol(aIndex) → number
Gens symbol level (the badge level).
local symbol = Player.GetGensSymbol(aIndex)
Message.Send(aIndex, 1, "Gens symbol level: " .. symbol)Player.GetGensContribution(aIndex) → number
Gens contribution points.
local points = Player.GetGensContribution(aIndex)
Message.Send(aIndex, 1, "Gens contribution: " .. points)Player.GetCastleSiegeSide(aIndex) → number
Castle Siege side: 0 none, 1 defense, 2 or more attack sides.
if Player.GetCastleSiegeSide(aIndex) == 1 then
Message.Send(aIndex, 1, "You defend the castle")
endPlayer.GetQuestState(aIndex, quest) → number
State of a class-change quest: 0 not started, 1 accepted, 2 complete, 3 cleared, 255 when the quest does not exist or the character has no data for it.
if Player.GetQuestState(aIndex, 0) == 3 then
Message.Send(aIndex, 1, "First class quest is done")
endPlayer.GetSkin(aIndex) → number
Transformation (monster class the character looks like), -1 if none.
if Player.GetSkin(aIndex) ~= -1 then
Message.Send(aIndex, 3, "Remove your transformation first")
endPlayer.GetInterface(aIndex) → string
Name of the window the character has open, "interface_none" if no window is open (for example "interface_shop", "interface_warehouse", "interface_chaos_machine").
if Player.GetInterface(aIndex) ~= "interface_none" then
Message.Send(aIndex, 3, "Close the open window first")
endPlayer.GetAccumulatedDamage(aIndex) → number
Damage counter the server uses to wear down weapon durability. It goes back to 0 each time it passes 100.
local dmg = Player.GetAccumulatedDamage(aIndex)
Log.Add(Player.GetName(aIndex) .. " accumulated damage " .. dmg)Player.GetDeathLocation(aIndex) → map, x, y or nil
Place of the last death in this login session: 3 numbers. nil if the character has not died since login.
local map, x, y = Player.GetDeathLocation(aIndex)
if map then
Message.Send(aIndex, 1, "You died in " .. Map.GetName(map) .. " " .. x .. "," .. y)
endPlayer.GetItem(aIndex, slot) → table or nil
Item in an inventory slot (equipment slots included), as an item table (Item functions). nil if the slot is empty or out of range.
local item = Player.GetItem(aIndex, 0)
if item then
Message.Send(aIndex, 1, "Weapon: " .. Item.GetName(item.Index) .. " +" .. item.Level)
endPlayer.IsActionBlocked(aIndex, action) → boolean
true if the action is blocked by Player.BlockAction. action is an ACTION_* value (see Player.BlockAction).
if Player.IsActionBlocked(aIndex, ACTION_TRADE) then
Message.Send(aIndex, 3, "Trading is blocked during the event")
endWrite functions return true when the value was changed and false when nothing was done (character not in game, value missing or not a number). Values out of range are clamped to the allowed range.
Player.SetLevel(aIndex, level) → boolean
Sets the normal level (1 to the server maximum). Experience goes to 0 of the new level. The client is not updated: call Player.SendLevelUp or Player.SendInfo.
if Player.SetLevel(aIndex, 400) then
Player.SendInfo(aIndex)
endPlayer.SetMasterLevel(aIndex, level) → boolean
Sets the Master level (0 to the server maximum). Master experience goes to 0 and the Master status is sent to the client.
Player.SetMasterLevel(aIndex, 200)
Player.SendLevels(aIndex)Player.SetMajesticLevel(aIndex, level) → boolean
Sets the Majestic level (0 to the server maximum). Majestic experience goes to 0 and the Majestic points are sent to the client.
Player.SetMajesticLevel(aIndex, 50)
Player.SendLevels(aIndex)Player.SetLevelUpPoint(aIndex, points) → boolean
Sets the unspent stat points. The client is not updated: call Player.SendLevelUp or Player.SendInfo.
Player.SetLevelUpPoint(aIndex, Player.GetLevelUpPoint(aIndex) + 500)
Player.SendLevelUp(aIndex)Player.SetMasterPoint(aIndex, points) → boolean
Sets the unspent Master points and updates the client.
Player.SetMasterPoint(aIndex, Player.GetMasterPoint(aIndex) + 10)
Message.Send(aIndex, 1, "You received 10 Master points")Player.SetMajesticPoint(aIndex, points) → boolean
Sets the unspent Majestic points and updates the client.
Player.SetMajesticPoint(aIndex, Player.GetMajesticPoint(aIndex) + 5)
Message.Send(aIndex, 1, "You received 5 Majestic points")Player.SetStat(aIndex, stat, value) → boolean
Sets a base stat (STAT_*). Only the data changes: call Player.ReCalc or Player.SendInfo to apply it and update the client.
Player.SetStat(aIndex, STAT_STRENGTH, 1000)
Player.SetStat(aIndex, STAT_AGILITY, 1000)
Player.SendInfo(aIndex)Player.SetMoney(aIndex, zen) → boolean
Sets the Zen and updates the client. Capped at the server Zen limit.
local price = 5000000
if Player.GetMoney(aIndex) >= price then
Player.SetMoney(aIndex, Player.GetMoney(aIndex) - price)
endPlayer.SetRuud(aIndex, ruud) → boolean
Sets the Ruud and updates the client.
Player.SetRuud(aIndex, 0)
Message.Send(aIndex, 1, "Your Ruud has been reset")Player.AddRuud(aIndex, amount) → boolean
Adds Ruud; a negative amount takes Ruud. Returns false and takes nothing if there is not enough. Updates the client.
if Player.AddRuud(aIndex, -1000) then
Message.Send(aIndex, 1, "1000 Ruud taken")
else
Message.Send(aIndex, 3, "Not enough Ruud")
endPlayer.SetReset(aIndex, resets) → boolean
Sets the reset count. The client is not updated: call Player.SendInfo.
Player.SetReset(aIndex, Player.GetReset(aIndex) + 1)
Player.SetLevel(aIndex, 1)
Player.SendInfo(aIndex)Player.SetPKCount(aIndex, count) → boolean
Sets the PK kill count.
Player.SetPKCount(aIndex, 0)
Message.Send(aIndex, 1, "Your PK count was cleared")Player.SetPKLevel(aIndex, level) → boolean
Sets the PK level, 0..6 (3 = normal, 6 = murderer level 3), and updates the name colour.
if Player.GetPKLevel(aIndex) > 3 then
Player.SetPKLevel(aIndex, 3)
Player.SetPKTimer(aIndex, 0)
endPlayer.SetPKTimer(aIndex, points) → boolean
Sets the PK points left (see Player.GetPKTimer). Only the points change: the PK level (name colour) is recalculated at the next monster kill. To clear the PK status at once, also set the PK count and PK level.
-- Clear the PK status now
Player.SetPKTimer(aIndex, 0)
Player.SetPKCount(aIndex, 0)
Player.SetPKLevel(aIndex, 3) -- 3 = commoner, updates the name colour
Message.Send(aIndex, 1, "Your PK status has been cleared")Player.SetChatMute(aIndex, seconds) → boolean
Bans the character from chat for seconds (at most 10 years). 0 or less removes the ban.
Player.SetChatMute(aIndex, 600)
Message.Send(aIndex, 3, "You are muted for 10 minutes")Player.SetSkin(aIndex, monsterClass) → boolean
Transforms the character into a monster look, -1 removes the transformation. The character is shown again to everyone around.
Player.SetSkin(aIndex, 373)
Message.Send(aIndex, 1, "You have been transformed")Player.SetVIP(aIndex, level, expireTimestamp) → boolean
Sets the account VIP level (-1 = no VIP, up to 255) and the end time (Unix timestamp). Saves to the database at once and updates the client.
local days = 30
Player.SetVIP(aIndex, 1, os.time() + days * 86400)
Message.Send(aIndex, 1, "VIP active for " .. days .. " days")Player.GiveExperience(aIndex, exp) → boolean
Gives experience like killing a monster (buff bonuses are not applied). Returns true if the character levelled up, false otherwise (also when exp is 0 or less).
if Player.GiveExperience(aIndex, 5000000) then
Message.Send(aIndex, 1, "Level up!")
endPlayer.BlockAction(aIndex, action, block) → boolean
Blocks (block = true, the default) or allows (false) an action for the character. Not saved: cleared on logout and on Lua API reload. Returns false for an unknown action.
action values (System\Constants.lua): ACTION_TRADE ACTION_TRADE_ANSWER ACTION_PARTY ACTION_DUEL ACTION_ITEM_DROP ACTION_ITEM_LOOT ACTION_ITEM_USE ACTION_ITEM_MOVE ACTION_ITEM_BUY_NPC ACTION_ITEM_SELL_NPC ACTION_OPEN_PERSONAL_STORE ACTION_BUY_PERSONAL_STORE ACTION_TELEPORT ACTION_GAIN_EXPERIENCE ACTION_NPC_INTERACTION ACTION_ATTACK ACTION_MAGIC ACTION_CANCEL_MAGIC ACTION_WHISPER ACTION_SPEAK ACTION_CASH_SHOP_USE ACTION_GUILD_JOIN ACTION_RESET ACTION_GUILD_CREATE ACTION_POST ACTION_GENS_CHAT ACTION_PVP.
-- No trading and no shop selling during the event
Player.BlockAction(aIndex, ACTION_TRADE, true)
Player.BlockAction(aIndex, ACTION_ITEM_SELL_NPC, true)These functions return nothing.
Player.ReCalc(aIndex) → nothing
Recalculates all stats (after changing points, items or the option table) and updates the client.
Player.SetStat(aIndex, STAT_ENERGY, Player.GetStat(aIndex, STAT_ENERGY) + 100)
Player.ReCalc(aIndex)Player.SendInfo(aIndex) → nothing
Recalculates the stats and resends all character information (position, experience, points, Zen, HP / MP, PK, resets, levels).
Player.SetReset(aIndex, 0)
Player.SetLevel(aIndex, 1)
Player.SendInfo(aIndex)Player.SendLevelUp(aIndex) → nothing
Sends the normal level, free points and max HP / MP to the client.
Player.SetLevel(aIndex, Player.GetLevel(aIndex) + 1)
Player.SendLevelUp(aIndex)Player.SendMasterLevelUp(aIndex) → nothing
Sends the Master level-up effect and Master data to the client.
Player.SetMasterLevel(aIndex, Player.GetMasterLevel(aIndex) + 1)
Player.SendMasterLevelUp(aIndex)Player.SendLevels(aIndex) → nothing
Resends the levels and points of all 3 level types (normal, Master, Majestic).
Player.SetMasterLevel(aIndex, 0)
Player.SetMajesticLevel(aIndex, 0)
Player.SendLevels(aIndex)Player.SendStats(aIndex) → nothing
Resends the character stats to the client.
Player.SetStat(aIndex, STAT_VITALITY, 500)
Player.ReCalc(aIndex)
Player.SendStats(aIndex)Player.SendMoney(aIndex) → nothing
Resends the Zen amount to the client.
local p = Player.GetObject(aIndex)
p.Money = p.Money + 100000
Player.SendMoney(aIndex)Player.SendLife(aIndex, max) → nothing
Resends HP to the client. max = true sends the maximum HP, otherwise (default) the current HP.
Player.SendLife(aIndex, true)
Player.SendLife(aIndex, false)Player.SendMana(aIndex, max) → nothing
Resends MP to the client. max = true sends the maximum MP, otherwise (default) the current MP.
Player.SendMana(aIndex, true)
Player.SendMana(aIndex, false)Player.SendCommand(aIndex, type, cmd1, cmd2) → nothing
Sends a command packet from the server to the game client: the client shows an event message or window. Each value is 0..255; type chooses the kind of command, cmd1 / cmd2 are its parameters, and their meaning belongs to the client. The GameServer itself uses for example type 1 with cmd1 = 2 / 3 at the Devil Square entrance NPC and 0x14 / 0x15 at the Blood Castle entrance NPC.
This is not the chat command system. Commands that players type (/warehouse, /bless 10 ...) come to the server and are handled with LuaCommands.xml + onLuaCommand / BridgeFunctionAttach("OnCommandManager", ...): see Events and chat commands.
-- The same command the Blood Castle entrance NPC sends
Player.SendCommand(aIndex, 1, 0x15, 0)Player.SendEventTimer(aIndex, milliseconds, countUp, display, close) → nothing
Shows a timer in the screen corner. countUp = true counts up instead of down (default false), display is the timer style (default 5), close = true removes the timer.
-- 5 minute countdown
Player.SendEventTimer(aIndex, 5 * 60 * 1000, false, 5, false)
-- later: remove it
Player.SendEventTimer(aIndex, 0, false, 5, true)Player.Fireworks(aIndex, count) → nothing
Fireworks on the character. count 1..10 (default 1).
Player.GiveExperience(aIndex, 1000000)
Player.Fireworks(aIndex, 3)Player.ActionSend(aIndex, targetIndex, action) → nothing
The character does an emote (greeting, clapping ...) towards targetIndex (the character itself if the target is not valid). action is the client emote number, 0..255.
local emote = 0 -- client emote number
Player.ActionSend(aIndex, aIndex, emote)Player.SetWindowText(aIndex, text) → nothing
Changes the game window title of the player's client (UTF-8, up to 255 bytes).
local title = "MU Online - " .. Player.GetName(aIndex)
Player.SetWindowText(aIndex, title)Player.Disconnect(aIndex) → nothing
Disconnects the player at once.
local banned = { ["00-11-22-33-44-55-1A2B3C4D"] = true }
if banned[Player.GetHardwareId(aIndex)] then
Player.Disconnect(aIndex)
endPlayer.Logout(aIndex, type) → boolean
Closes the game for the player. type: 0 exit game (default), 1 back to character select, 2 back to server select. Any other value returns false.
Message.Send(aIndex, 0, "Your character was changed, please log in again")
Player.Logout(aIndex, 1)Player.Save(aIndex) → boolean
Saves the character to the database now. Returns true if the character was found. Do not call it repeatedly: each call writes to the database.
Player.SetReset(aIndex, Player.GetReset(aIndex) + 1)
Player.Save(aIndex)Player.CheckItemAction(aIndex) → boolean
true if creating or deleting items is safe now: no trade, no open window, not teleporting and not moving between servers. Check it before giving or taking items.
if Player.CheckItemAction(aIndex) then
Item.Give(aIndex, { Index = 14 * 512 + 13, Count = 1 })
else
Message.Send(aIndex, 3, "Close all windows and try again")
endPlayer.MoveGate(aIndex, gate) → boolean
Moves the character to a gate (teleport gate number). false if the character is dead, has a window open, is not allowed to teleport, does not meet the gate level, or the gate does not exist.
if not Player.MoveGate(aIndex, 17) then
Message.Send(aIndex, 3, "You cannot move now")
endPlayer.MoveTo(aIndex, map, x, y) → boolean
Teleports the character to map, x, y (x and y 0..255). The map must exist on this GameServer, otherwise it returns false.
if Map.Exists(MAP_DEVIAS) then
Player.MoveTo(aIndex, MAP_DEVIAS, 210, 40)
endPlayer.OpenWarehouse(aIndex) → boolean
Opens the warehouse without an NPC. false if the character is dead or another window is open.
if not Player.OpenWarehouse(aIndex) then
Message.Send(aIndex, 3, "Close the open window first")
endPlayer.ResetMasterTree(aIndex, group) → boolean
Resets the Master skill tree and gives the Master points back. group 0 / 1 / 2 resets one tree group, -1 (default) resets all. false if the character is not a master or has no skills in that group.
if Player.ResetMasterTree(aIndex, -1) then
Message.Send(aIndex, 1, "Master skill tree reset")
endPlayer.ResetMajesticTree(aIndex) → boolean
Resets the Majestic skill tree. Returns true if the character was found.
Player.ResetMajesticTree(aIndex)
Message.Send(aIndex, 1, "Majestic skill tree reset")Player.SummonMonster(aIndex, class, lifePercent, defensePercent, damagePercent) → number
Creates a monster that follows and fights for the character. The percent values (0..10000, default 0) add life, defense and damage on top of the monster's normal values. Returns the monster index, or -1 if the character already has a summon, the class does not exist or the map does not allow summons.
local summon = Player.SummonMonster(aIndex, 26, 100, 50, 50)
if summon == -1 then
Message.Send(aIndex, 3, "You cannot summon here")
endPlayer.KillSummon(aIndex) → nothing
Removes the character's summoned monster.
Player.KillSummon(aIndex)
Message.Send(aIndex, 1, "Your summon is gone")This version has no WCoinP: it is always 0 and the WCoinP argument is ignored.
Coins by type (Zen, WCoin, Goblin Point, Ruud) with one function: see Library.
Coin.Get(aIndex) → table
Table { WCoinC, WCoinP, GoblinPoint }. All values are 0 if the character is not logged in.
local coin = Coin.Get(aIndex)
Message.Send(aIndex, 1, "WCoinC: " .. coin.WCoinC .. ", Goblin Points: " .. coin.GoblinPoint)Coin.Add(aIndex, wcoinC, wcoinP, goblin) → boolean
Adds coins, saves to the database at once and updates the client. Negative values add nothing; a total never goes above 2,147,483,647. false if the character is not in game.
if Coin.Add(aIndex, 500, 0, 100) then
Message.Send(aIndex, 1, "You received 500 WCoinC and 100 Goblin Points")
endCoin.Sub(aIndex, wcoinC, wcoinP, goblin) → boolean
Takes coins, saves to the database at once and updates the client. If there are not enough, nothing is taken and it returns false.
if Coin.Sub(aIndex, 100, 0, 0) then
Message.Send(aIndex, 1, "100 WCoinC taken")
else
Message.Send(aIndex, 3, "Not enough WCoinC")
end45 bonuses a script can give to a character. They are added every time the character's stats are calculated.
The table is not saved: it is cleared on logout and on Lua API reload (the GameServer recalculates the stats of those characters at reload). Set it again in onPlayerLogin.
If several modules give bonuses, use OptionBonus: each module sets its own part and the parts are added together.
| Fields |
|---|
AddDamage AddPhysiDamage AddMagicDamage AddCurseDamage AddDefense AddDefenseRate AddElementalDamage AddElementalDefense AddSpeed
|
AddMaxHP AddMaxMP AddMaxBP AddMaxSD AddHPRecoveryRate AddMPRecoveryRate AddBPRecoveryRate AddSDRecoveryRate
|
AddDamageReduction AddDamageDecrease AddDamageReflect AddCriticalDamage AddExcellentDamage AddCriticalDamageRate AddExcellentDamageRate
|
AddIgnoreDefenseRate AddDoubleDamageRate AddTripleDamageRate AddFullDamageReflectRate
|
AddDefensiveFullHPRestoreRate AddDefensiveFullSDRestoreRate AddOffensiveFullHPRestoreRate AddOffensiveFullSDRestoreRate
|
MulDamage MulPhysiDamage MulMagicDamage MulCurseDamage MulDefense MulElementalDamage MulElementalDefense (percent) |
MulMaxHP MulMaxMP MulMaxBP MulMaxSD (percent) CombatPower ExpRate (percent) |
function VipBonus_OnLogin(aIndex)
if Player.GetVIP(aIndex) > 0 then
Player.SetOptionTable(aIndex, { AddDamage = 50, MulMaxHP = 10, ExpRate = 20 })
Player.ReCalc(aIndex)
end
end
BridgeFunctionAttach("OnCharacterEntry", "VipBonus_OnLogin")Player.GetOptionTable(aIndex) → table
Table with all 45 fields; a field that was never set is 0. A character that is not logged in gives a table of zeros.
local opt = Player.GetOptionTable(aIndex)
Message.Send(aIndex, 1, "Script damage bonus: " .. opt.AddDamage)Player.SetOptionTable(aIndex, table) → boolean
Stores the values. Missing fields keep their value. Call Player.ReCalc(aIndex) to apply. false if the character is not in game or the second argument is not a table.
local opt = Player.GetOptionTable(aIndex)
Player.SetOptionTable(aIndex, { AddDefense = opt.AddDefense + 100 })
Player.ReCalc(aIndex)Player.GetObject(aIndex) (or Player.GetObjectByName(name)) returns an object whose fields read and write the character directly. Every access asks the GameServer at that moment, so values are never out of date. When the character leaves the game, reads return nil and writes do nothing, even if another character gets the same index.
local p = Player.GetObject(aIndex)
if p then
p.Money = p.Money + 10000
p.Life = p.MaxLife
Message.Send(p.Index, 1, p.Name .. " level " .. p.Level)
end| Fields | |
|---|---|
| Read and write |
Level MasterLevel MajesticLevel Reset LevelUpPoint MasterPoint MajesticPoint Money Ruud PKLevel PKCount PKTimer Skin Strength Dexterity Vitality Energy Leadership Life MaxLife Mana MaxMana Shield MaxShield BP MaxBP
|
| Read only |
Index Name Account CharacterID Class Map X Y TotalLevel Evolution Experience NextExperience VIP VIPExpire Authority CodePage PartyNumber GuildNumber GuildName GuildStatus GensFamily GensContribution IsLive IsOffline IsGameMaster
|
Writing a read-only or unknown field is an error. Player.IsObjectValid(p) returns true while the object still points to the same character in game.
Next: Item functions