This page covers the functions that send data to the client and the functions that perform actions on the character. Conditions:

  • Send functions (Send..., Fireworks, ActionSend, SetWindowText): the character is logged in (LOGGED or higher).
  • Action functions (ReCalc, SendInfo, movement, logout, save...): the character is in game (PLAYING), is not inside onPlayerLogout, and the script is not in restricted mode.
  • If the conditions are not met the function does nothing. A function with no Returns entry has no return value.

Recalculate stats and send information

Player.ReCalc

Recalculates all of the character's stats (after changing points, items or the script stat table) and sends them to the client.

Player.ReCalc(aIndex)

Parameter: aIndex (integer, character index). Short names: UserCalcAttribute, CalculateCharacter.

Player.SetStat(aIndex, STAT_VITALITY, 500)
Player.ReCalc(aIndex)

Player.SendInfo

Recalculates stats and sends the character information being played back to the client: level, points, maximum HP / MP, stats, zen, PK status.

Player.SendInfo(aIndex)

Parameter: aIndex. Short name: UserInfoSend. The function does not send the "enter game" packet, so it is safe to call while playing.

Player.SetLevel(aIndex, 300)
Player.SendInfo(aIndex)

Player.SendLevelUp

Sends the level and bonus points of the normal level to the client again.

Player.SendLevelUp(aIndex)

Parameter: aIndex. Short name: LevelUpSend.

Player.SendLevelUp(aIndex)

Player.SendMasterLevelUp

Sends the Master level-up information to the client again.

Player.SendMasterLevelUp(aIndex)

Parameter: aIndex. Short name: MasterLevelUpSend.

Player.SendMasterLevelUp(aIndex)

Player.SendLevels

Sends the level and points of all three level types (normal, Master, Majestic) again.

Player.SendLevels(aIndex)

Parameter: aIndex. Short name: UpdatePlayerLevels.

Player.SendLevels(aIndex)

Player.SendStats

Sends the character's stats (Strength, Agility...) to the client again.

Player.SendStats(aIndex)

Parameter: aIndex.

Player.SendStats(aIndex)

Player.SendMoney

Sends the zen amount to the client again.

Player.SendMoney(aIndex)

Parameter: aIndex. Short name: MoneySend.

Player.SendMoney(aIndex)

Player.SendLife

Sends HP to the client.

Player.SendLife(aIndex [, max])
ParameterTypeDescription
aIndexintegerCharacter index
maxbooleantrue = send the maximum value; false or omitted = send the current value
Player.SendLife(aIndex, true)
Player.SendLife(aIndex)

Player.SendMana

Sends MP (and AG) to the client.

Player.SendMana(aIndex [, max])
ParameterTypeDescription
aIndexintegerCharacter index
maxbooleantrue = send the maximum value; false or omitted = send the current value

One packet sends both MP and AG (stamina) at the same time: the current value, or the maximum value when max = true.

Player.SendMana(aIndex, true)

Client-specific packets

Player.SendCommand

Sends a command from the server to the client (effects, opening windows...).

Player.SendCommand(aIndex, type, cmd1, cmd2)
ParameterTypeDescription
aIndexintegerCharacter index
typeintegerCommand type (0 to 255)
cmd1integerCommand parameter 1 (0 to 255)
cmd2integerCommand parameter 2 (0 to 255)

Short name: CommandSend.

The three values are sent as they are (each clamped to 0 to 255); GameServer does not check their meaning. The client decides what each type / cmd1 / cmd2 combination does. Only use combinations whose effect you know well on your own client.

Player.SendCommand(aIndex, 0, 1, 0)

Player.Fireworks

Launches fireworks at the spot where the character is standing.

Player.Fireworks(aIndex [, count])
ParameterTypeDescription
aIndexintegerCharacter index
countintegerNumber of fireworks, from 1 to 10 (default 1)

To launch fireworks at any coordinates on the map, use Map.Fireworks.

Player.Fireworks(aIndex, 5)

Player.ActionSend

Makes the character perform an action (salute, clap...).

Player.ActionSend(aIndex, targetIndex, action)
ParameterTypeDescription
aIndexintegerIndex of the character performing the action
targetIndexintegerIndex of the object being faced. If invalid, the function uses the character itself
actionintegerAction code (0 to 255)

Short name: UserActionSend.

Player.ActionSend(aIndex, aIndex, 1)

Player.SendEventTimer

Shows a clock in the corner of the client screen.

Player.SendEventTimer(aIndex, milliseconds, countUp, display, close)
ParameterTypeDescription
aIndexintegerCharacter index
millisecondsintegerTime, in milliseconds
countUpbooleantrue = count up, false = count down (default)
displayintegerDisplay style (0 to 255, default 5): 1 Time Limit, 2 Remaining Time, 3 Hunting Time, 4 Disassembly Failed, 5 Quest Survival Time
closebooleantrue = close the clock (default false)
Player.SendEventTimer(aIndex, 60000, false, 5, false)   -- count down 60 seconds
Player.SendEventTimer(aIndex, 0, false, 5, true)        -- turn off the clock

Player.SetWindowText

Changes the title of the player's game window.

Player.SetWindowText(aIndex, text)
ParameterTypeDescription
aIndexintegerCharacter index
textstringNew title, in UTF-8, maximum 255 bytes (any excess is cut off)

Short name: SetWindowText.

Player.SetWindowText(aIndex, "TSWMU - " .. Player.GetName(aIndex))

Movement and opening windows

Player.MoveGate

Teleports the character through one of the server's teleport gates.

Player.MoveGate(aIndex, gate) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
gateintegerGate number (0 to 65535)

Returns: true if the teleport is possible; false if the character is dead, has a window open, the gate is wrong or the conditions are not met. Short name: MoveUser.

if not Player.MoveGate(aIndex, 17) then Message.Send(aIndex, 1, "Unable to teleport") end

Player.MoveTo

Teleports the character to the specified map and coordinates (within the same GameServer).

Player.MoveTo(aIndex, map, x, y) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
mapintegerMap number; must exist on this GameServer
xintegerX coordinate (clamped from 0 to 255)
yintegerY coordinate (clamped from 0 to 255)

Returns: true if the teleport was requested; false if the parameters are wrong, the map does not exist on this GameServer or the conditions are not met. Short name: MoveUserEx; SetObjectMap(aIndex, map) keeps the current coordinates.

Player.MoveTo(aIndex, MAP_LORENCIA, 130, 130)

Player.OpenWarehouse

Opens the warehouse for the character without needing to stand next to the NPC.

Player.OpenWarehouse(aIndex) -> boolean

Parameter: aIndex. Returns: true if it was opened; false if the character is dead or has another window open. Short name: UserWarehouseOpen.

Player.OpenWarehouse(aIndex)

Player.CheckItemAction

Checks whether it is currently safe to create or delete the character's items (not trading, no window open, not teleporting...).

Player.CheckItemAction(aIndex) -> boolean

Parameter: aIndex. Returns: true if it is safe; false if not. Should be called before functions such as Inventory.DeleteItems, Item.Give...

if not Player.CheckItemAction(aIndex) then
    Message.Send(aIndex, 1, "Please close all windows and try again")
    return
end

Logout and save

Player.Disconnect

Disconnects the player (kick).

Player.Disconnect(aIndex)

Parameter: aIndex. Short name: UserDisconnect.

Player.Disconnect(aIndex)

Player.Logout

Makes the character leave the game in one of several ways: exit completely, return to the character selection screen or return to the server selection screen. The function cancels every activity the character is running before leaving.

Player.Logout(aIndex, type) -> boolean
ParameterTypeDescription
aIndexintegerCharacter index
typeinteger0 exit the game, 1 return to character selection, 2 return to server selection (default 0)

Returns: true if it was carried out; false if type is outside 0 to 2 or the conditions are not met. Short name: UserGameLogout.

Player.Logout(aIndex, 1)   -- back to the character selection screen

Player.Save

Saves the character to the database immediately.

Player.Save(aIndex) -> boolean

Parameter: aIndex. Returns: true if it was saved; false if the conditions are not met.

Do not call it continuously (for example every second for every player): each save costs a data write operation.
Player.SetMoney(aIndex, 0)
Player.Save(aIndex)

Summoned monsters

Player.SummonMonster

Creates a summoned monster that follows the character (each character can only have one summoned monster).

Player.SummonMonster(aIndex, class, lifePercent, defensePercent, damagePercent) -> integer
ParameterTypeDescription
aIndexintegerCharacter index (the owner)
classintegerMonster code (must exist in the monster data)
lifePercentintegerPercentage added to maximum HP (0 to 10000, default 0)
defensePercentintegerPercentage added to defense (0 to 10000, default 0)
damagePercentintegerPercentage added to physical damage (0 to 10000, default 0)

Returns: the index of the summoned monster; -1 on failure (the character already has a summoned monster, the monster code does not exist, the map does not allow summoning, the object could not be created, the conditions are not met). Short name: MonsterSummonCreate(aIndex, class, lifeRate, defenseRate, defenseSuccessRate, damageRate); the defenseSuccessRate parameter is ignored.

local summon = Player.SummonMonster(aIndex, 26, 50, 0, 20)
if summon == -1 then Message.Send(aIndex, 1, "Unable to summon") end

Player.KillSummon

Removes the character's summoned monster.

Player.KillSummon(aIndex)

Parameter: aIndex. Short name: MonsterSummonDelete.

Player.KillSummon(aIndex)