Skip to content

LuaAPI Player

itvnnnd87 edited this page Oct 24, 2026 · 2 revisions

Player functions

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.

Identity and account

Function Description
Player.IsOnline(aIndex) true if the character is in game.
Player.IsOffline(aIndex) true if the character is in offline mode (off-attack / off-store).
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.
Player.GetIndexByName(name) aIndex of an online character, -1 if not found.
Player.GetClass(aIndex) Character class (CLASS_*).
Player.GetDBClass(aIndex) Class value stored in the database (class + evolution).
Player.GetEvolution(aIndex) Number of class evolutions done (0..3).
Player.GetVIP(aIndex) Account VIP level.
Player.GetVIPExpire(aIndex) VIP expiry time (Unix timestamp).
Player.GetAuthority(aIndex) Character authority value.
Player.IsGameMaster(aIndex) true for a GM with authority enabled (.auth).
Player.HasAdminFlag(aIndex, flag) true if the GM has the admin flag flag.
Player.GetCodePage(aIndex) Code page of the player's client (language).
Player.GetIP(aIndex) IP address.
Player.GetMac(aIndex) MAC address.
Player.GetDiskSerial(aIndex) Disk serial number.
Player.GetHardwareId(aIndex) Machine ID (MAC + disk serial).

Levels, experience and stats

Function Description
Player.GetLevel, GetMasterLevel, GetMajesticLevel Normal / Master / Majestic level.
Player.GetTotalLevel(aIndex) Normal + Master + Majestic level.
Player.GetLevelUpPoint, GetMasterPoint, GetMajesticPoint Unspent points.
Player.GetUsedMasterPoints(aIndex) Points spent in the Master skill tree.
Player.GetExperience(aIndex, levelType) Experience. levelType: 0 normal, 1 master, 2 majestic.
Player.GetNextExperience(aIndex, levelType) Experience needed for the next level.
Player.GetLastGainedExp(aIndex) Last experience gained.
Player.GetReset(aIndex) Reset count.
Player.GetStat(aIndex, stat) Base stat. stat: STAT_STRENGTH 0, STAT_AGILITY 1, STAT_VITALITY 2, STAT_ENERGY 3, STAT_LEADERSHIP 4.
Player.GetAddStat(aIndex, stat) Stat added by items, buffs ...
Player.GetTotalStat(aIndex, stat) Base + added.
Player.GetDefaultStat(aIndex, stat) Starting stat of the class.

HP / MP / SD / AG and combat stats: Object.GetPower, Object.GetCombatStat (Function reference).

Money, PK, social

Function Description
Player.GetMoney(aIndex) Zen.
Player.GetRuud(aIndex) Ruud.
Player.GetTradeZen(aIndex) Zen placed in the open trade window.
Player.GetPKCount, GetPKLevel, GetPKTimer Kill count, PK level, PK time (seconds).
Player.GetPKTotalCount(aIndex) Total players killed (statistics).
Player.GetMuteTime(aIndex) Seconds of chat ban left, 0 if none.
Player.GetPartyNumber(aIndex) Party number, -1 if not in a party.
Player.GetGuildNumber(aIndex), GetGuildName Guild (0 / "" if none).
Player.GetGuildStatus(aIndex) Rank in the guild, -1 if none.
Player.GetGuildUnionNumber(aIndex), GetGuildUnionName Alliance.
Player.GetGuildRelationship(aIndex, bIndex) Guild relationship between two characters.
Player.GetGensFamily(aIndex) 0 none, 1 Duprian, 2 Vanert.
Player.GetGensRank, GetGensSymbol, GetGensContribution Gens ranking, symbol level, contribution.
Player.GetCastleSiegeSide(aIndex) Castle Siege side.
Player.GetQuestState(aIndex, quest) State of a class-change quest.
Player.GetSkin(aIndex) Transformation (monster class), -1 if none.
Player.GetInterface(aIndex) Window currently open.
Player.GetAccumulatedDamage(aIndex) Accumulated damage.
Player.GetDeathLocation(aIndex) 3 values map, x, y of the last death in this session, or nil.
Player.GetItem(aIndex, slot) Item table of an inventory slot (Item functions).

Write

Return true / false.

Function Description
Player.SetLevel(aIndex, level) Normal level (experience is reset to 0). Update the client with SendLevelUp / SendInfo.
Player.SetMasterLevel(aIndex, level), SetMajesticLevel Master / Majestic level. Update the client with SendLevels.
Player.SetLevelUpPoint(aIndex, v) Unspent points.
Player.SetMasterPoint(aIndex, v), SetMajesticPoint Updates the client.
Player.SetStat(aIndex, stat, v) Base stat. Update the client with Player.ReCalc / SendInfo.
Player.SetMoney(aIndex, zen) Updates the client. Capped at the server Zen limit.
Player.SetRuud(aIndex, v) Updates the client.
Player.AddRuud(aIndex, amount) Negative = take. false if there is not enough.
Player.SetReset(aIndex, v) Update the client with Player.SendInfo.
Player.SetPKCount(aIndex, v), SetPKTimer(aIndex, seconds)
Player.SetPKLevel(aIndex, v) Updates the name colour. 0..6 (3 = normal, 6 = murderer level 3).
Player.SetChatMute(aIndex, seconds) Chat ban, 0 = remove.
Player.SetSkin(aIndex, monsterClass) Transformation, -1 = remove.
Player.SetVIP(aIndex, level, expireTimestamp) Saves to the database at once and updates the client.
Player.GiveExperience(aIndex, exp) Gives experience like killing a monster (no buff bonus). Returns true if the character levelled up.
Player.BlockAction(aIndex, action, block) Blocks (true) or allows (false) an action. Not saved: cleared on logout and on reload.
Player.IsActionBlocked(aIndex, action) true if blocked by Player.BlockAction.

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)

Client updates and actions

Function Description
Player.ReCalc(aIndex) Recalculates stats (after changing points, items or the option table) and updates the client.
Player.SendInfo(aIndex) Resends all character information.
Player.SendLevelUp(aIndex) Sends level, points and max HP / MP.
Player.SendMasterLevelUp(aIndex) Master level-up effect and data.
Player.SendLevels(aIndex) Resends the levels and points of all 3 level types.
Player.SendStats(aIndex), SendMoney(aIndex)
Player.SendLife(aIndex, max), SendMana(aIndex, max) Resends HP / MP. max = true: the maximum.
Player.SendCommand(aIndex, type, cmd1, cmd2) Server command to the client (effects, windows ...).
Player.SendEventTimer(aIndex, milliseconds, countUp, display, close) Timer in the screen corner.
Player.Fireworks(aIndex, count) Fireworks on the character.
Player.ActionSend(aIndex, targetIndex, action) The character does an emote (greeting, clapping ...).
Player.Disconnect(aIndex) Disconnects the player.
Player.Logout(aIndex, type) 0 exit game, 1 back to character select, 2 back to server select.
Player.Save(aIndex) Saves the character to the database now. Do not call it repeatedly.
Player.CheckItemAction(aIndex) true if creating or deleting items is safe now (no trade, no open window, not teleporting).
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.SummonMonster(aIndex, class, lifePercent, defensePercent, damagePercent) A monster that follows the character.
Player.KillSummon(aIndex) Removes the character's summon.
Player.SetWindowText(aIndex, text) Game window title (UTF-8, up to 255 bytes).

Coin (Cash Shop)

Function Description
Coin.Get(aIndex) Table { WCoinC, WCoinP, GoblinPoint }. This version has no WCoinP (always 0).
Coin.Add(aIndex, wcoinC, wcoinP, goblin) Adds coins, saves to the database at once and updates the client.
Coin.Sub(aIndex, wcoinC, wcoinP, goblin) Takes coins. If there are not enough, nothing is taken and it returns false.

Coins by type (Zen, WCoin, Goblin Point, Ruud) with one function: see Library.

if Coin.Sub(aIndex, 100, 0, 0) then
    Message.Send(aIndex, 1, "100 WCoinC taken")
else
    Message.Send(aIndex, 3, "Not enough WCoinC")
end

Option table

45 bonuses a script can give to a character. They are added every time the character's stats are calculated.

Function Description
Player.GetOptionTable(aIndex) Table of the 45 values (0 when not set).
Player.SetOptionTable(aIndex, table) Stores the values. Missing fields keep their value. Call Player.ReCalc(aIndex) to apply.

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 object

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

Clone this wiki locally