The functions on this page change character data. General conditions: the character is in game (PLAYING), is not inside onPlayerLogout, and the script is not in restricted mode. If the conditions are not met, or the value passed in is not a number, the function does nothing and returns false (unless stated otherwise). The function returns true when it has been carried out.

Some functions only change data inside GameServer and do not send it to the client by themselves (stated for each function). After changing, call Player.ReCalc, Player.SendInfo, Player.SendLevelUp... (page Player: send information and actions) so the client shows the new value.

Levels and points

Player.SetLevel

Sets the normal level. The EXP of the new level is set to 0. This function does not send anything to the client by itself; call Player.SendLevelUp or Player.SendInfo.

Player.SetLevel(aIndex, level) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
levelintegerNew level; clamped from 1 to the server's maximum level

Returns: true if it was set. Short name: SetObjectLevel.

if Player.SetLevel(aIndex, 400) then Player.SendInfo(aIndex) end

Player.SetMasterLevel

Sets the Master level. EXP is set to 0 and GameServer sends the Master status to the client again.

Player.SetMasterLevel(aIndex, level) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
levelintegerMaster level; clamped from 0 to the maximum Master level

Returns: true if it was set. Short name: SetObjectMasterLevel.

Player.SetMasterLevel(aIndex, 200)

Player.SetMajesticLevel

Sets the Majestic level. EXP is set to 0 and GameServer sends the Majestic skill tree points to the client again.

Player.SetMajesticLevel(aIndex, level) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
levelintegerMajestic level; clamped from 0 to the maximum Majestic level

Returns: true if it was set. Short name: SetObjectMajesticLevel.

Player.SetMajesticLevel(aIndex, 50)

Player.SetLevelUpPoint

Sets the number of unused bonus points of the normal level (changes data only).

Player.SetLevelUpPoint(aIndex, points) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
pointsintegerNumber of points; clamped from 0 to 2147483647

Returns: true if it was set. Short name: SetObjectLevelUpPoint.

Player.SetLevelUpPoint(aIndex, Player.GetLevelUpPoint(aIndex) + 100)
Player.SendLevelUp(aIndex)

Player.SetMasterPoint

Sets the number of unused Master points and sends the Master status to the client again.

Player.SetMasterPoint(aIndex, points) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
pointsintegerNumber of points; clamped from 0 to 2147483647

Returns: true if it was set. Short name: SetObjectMasterPoint.

Player.SetMasterPoint(aIndex, 10)

Player.SetMajesticPoint

Sets the number of unused Majestic points and sends it to the client again.

Player.SetMajesticPoint(aIndex, points) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
pointsintegerNumber of points; clamped from 0 to 2147483647

Returns: true if it was set. Short name: SetObjectMajesticPoint.

Player.SetMajesticPoint(aIndex, 5)

Player.SetStat

Sets the base points of a stat (changes data only). Afterwards call Player.ReCalc or Player.SendInfo to recalculate and send it to the client.

Player.SetStat(aIndex, stat, value) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
statinteger0 Strength, 1 Agility, 2 Vitality, 3 Energy, 4 Command (STAT_* constants)
valueintegerNew points; clamped from 0 to 2147483647

Returns: true if it was set; false if stat is outside 0 to 4 or the conditions are not met. Short names: SetObjectStrength, SetObjectDexterity, SetObjectVitality, SetObjectEnergy, SetObjectLeadership (take aIndex, value).

Player.SetStat(aIndex, STAT_STRENGTH, 32767)
Player.SendInfo(aIndex)

Currency and Reset

Player.SetMoney

Sets the character's zen (and sends it to the client).

Player.SetMoney(aIndex, zen) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
zenintegerNew zen amount; clamped from 0 to the character's maximum zen

Returns: true if it was set. Short name: SetObjectMoney.

Player.SetMoney(aIndex, Player.GetMoney(aIndex) + 1000000)

Player.SetRuud

Sets the Ruud amount and sends it to the client.

Player.SetRuud(aIndex, ruud) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
ruudintegerNew Ruud amount; clamped from 0 to 2147483647

Returns: true if it was set. Short name: SetObjectRuud.

Player.SetRuud(aIndex, 0)

Player.AddRuud

Adds or subtracts Ruud. A negative number subtracts.

Player.AddRuud(aIndex, amount) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
amountintegerAmount to add (positive) or subtract (negative); limited to the range -2147483647 to 2147483647

Returns: true if it was changed; false if you subtract more than the character has (nothing is subtracted) or the conditions are not met. The result is clamped to the range 0 to 2147483647 and sent to the client (when adding, the amount received is displayed). Short name: RuudSend.

if not Player.AddRuud(aIndex, -500) then
    Message.Send(aIndex, 1, "Not enough Ruud")
end

Player.SetReset

Sets the number of Resets and updates the client.

Player.SetReset(aIndex, count) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
countintegerNumber of Resets; clamped from 0 to 2147483647

Returns: true if it was set. Short names: ChangeObjectReset, SetObjectReset.

On a non-Reset server (ResetServer in Common.ini is off), the function does not allow increasing the Reset count: a value greater than the current one is rejected (returns false, a log entry is written). Decreasing or keeping the same value is still allowed.
Player.SetReset(aIndex, Player.GetReset(aIndex) + 1)

PK

Player.SetPKCount

Sets the character's PK count.

Player.SetPKCount(aIndex, count) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
countintegerNew value; clamped from 0 to 2147483647

Returns: true if it was set. Short name: SetObjectPKCount.

Player.SetPKCount(aIndex, 0)

Player.SetPKLevel

Sets the PK level and sends it to the client.

Player.SetPKLevel(aIndex, level) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
levelintegerNew PK level; clamped to the range 0 to 6 (0 Hero, 1 Hero level 2, 2 Hero level 1, 3 Commoner, 4 - 6 Murderer level 1 - 3; same value table as Player.GetPKLevel)

Returns: true if it was set. Short names: SetObjectPKLevel, PKLevelSend (both take aIndex, value).

Player.SetPKLevel(aIndex, 3)  -- back to commoner status

Player.SetPKTimer

Sets the character's PK counter (PKPoints).

Player.SetPKTimer(aIndex, value) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
valueintegerNew value; clamped from 0 to 2147483647

Returns: true if it was set. Short name: SetObjectPKTimer.

Player.SetPKTimer(aIndex, 0)

VIP, EXP, chat mute, transformation

Player.SetVIP

Sets the account's VIP level and expiry. The function saves to the database immediately and sends the VIP information to the client.

Player.SetVIP(aIndex, level, expire) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
levelintegerVIP level; clamped from -1 to 255
expireintegerExpiry time (timestamp, in seconds). Omitted or negative = 0

Returns: true if it was set. Short name: UserSetAccountLevel.

Player.SetVIP(aIndex, 1, os.time() + 30 * 86400)   -- VIP 1 for 30 days

Player.GiveExperience

Gives EXP to the character as if it had killed a monster (EXP boost buffs are not applied).

Player.GiveExperience(aIndex, exp) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
expnumberAmount of EXP to add (must be greater than 0; maximum about 9e15)

Returns: true if the character levels up thanks to this EXP; false if it does not level up, exp is not positive, is NaN / infinite (for example 0/0), or the conditions are not met (the function does not distinguish between these cases).

if Player.GiveExperience(aIndex, 1000000) then
    Message.Send(aIndex, 1, "Congratulations, you leveled up!")
end

Player.SetChatMute

Mutes the character's chat for a period of time, or removes the mute.

Player.SetChatMute(aIndex, seconds) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
secondsintegerNumber of seconds muted (maximum 10 years). 0 or negative = remove the mute

Returns: true if it was set. Short name: SetObjectChatLimitTime. Check the remaining time with Player.GetMuteTime.

Player.SetChatMute(aIndex, 600)   -- mute chat for 10 minutes

Player.SetSkin

Transforms the character into a type of monster, or removes the transformation. The function sends the appearance to the surrounding players again.

Player.SetSkin(aIndex, monsterClass) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
monsterClassintegerCode of the monster to transform into (0 to 65535). A negative number or one outside the range = remove the transformation

Returns: true if it was set. Short name: SkinChangeSend.

Player.SetSkin(aIndex, 3)    -- transform
Player.SetSkin(aIndex, -1)   -- back to normal

Blocking actions

Player.BlockAction

Blocks or re-enables an action of the character. The block is only temporary: it is not saved to the database and is lost when LuaAPI is reloaded. The function only requires the character to be logged in (it does not need to be PLAYING).

Player.BlockAction(aIndex, action [, block]) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
actionintegerAction code, an ACTION_* constant (0 to 26): trade, party invite, drop / pick up / use / move items, buying and selling at NPC shops, opening a personal store, teleport, receiving EXP, NPC interaction, attack, spells, whisper, chat, using cash shop items, joining a guild, Reset, creating a guild, post, Gens chat, PvP
blockbooleantrue = block (default), false = re-enable

Returns: true if it was applied; false if the character or action is invalid.

Permission-style short names (perm): PermissionCheck(aIndex, perm) returns 1 if allowed, 0 if blocked; PermissionRemove(aIndex, perm) blocks; PermissionInsert(aIndex, perm) re-enables. Mapping table: perm 1 move items, 2 sell to NPC, 3 buy from NPC, 4 use items, 5 drop items, 6 pick up items, 7 trade, 8 open personal store, 10 use cash shop, 11 chat, 12 teleport. Any other perm (for example 9): PermissionCheck returns 1, the other two functions return false.

Player.BlockAction(aIndex, ACTION_TRADE, true)    -- forbid trading
Player.BlockAction(aIndex, ACTION_TRADE, false)   -- allow again

Skill trees and script-defined stats

Player.ResetMasterTree

Resets the Master skill tree and refunds the Master points.

Player.ResetMasterTree(aIndex [, group]) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
groupinteger (optional)Tree branch 0, 1 or 2; -1 or omitted = the whole tree. Other values are treated as -1

Returns: the result of the reset (true on success); false if the conditions are not met. Short name: MasterSkillTreeRebuild.

Player.ResetMasterTree(aIndex)       -- whole tree
Player.ResetMasterTree(aIndex, 1)    -- branch 1 only

Player.ResetMajesticTree

Resets the Majestic skill tree.

Player.ResetMajesticTree(aIndex) -> boolean

Parameter: aIndex. Returns: true if the character meets the conditions (it was carried out); false if not. Short name: ResetMajesticTree.

Player.ResetMajesticTree(aIndex)

Player.SetOptionTable

Stores a table of bonus stats for the character (see Player.GetOptionTable for the list of fields). GameServer applies these stats every time it recalculates the character's stats, after items, buffs and skill trees have been added up. The function does not recalculate by itself: call Player.ReCalc or Player.SendInfo to see the effect immediately.

Player.SetOptionTable(aIndex, options) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
optionstableTable of numeric fields. Missing fields keep their old value; each value is clamped to the range -1e9 to 1e9

Returns: true if it was stored; false if options is not a table or the conditions are not met. Short name: UserSetOptionTable.

This table is stored per character in GameServer memory and is not written to the database. It is cleared when the character leaves the game and when LuaAPI is reloaded, so the script needs to set it again when the character logs in (onPlayerLogin).
local opt = Player.GetOptionTable(aIndex)
opt.AddDamage = 100
opt.AddMaxHP = 500
Player.SetOptionTable(aIndex, opt)
Player.ReCalc(aIndex)