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 insideonPlayerLogout, 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])
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character index |
max | boolean | true = 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])
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character index |
max | boolean | true = 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)
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character index |
type | integer | Command type (0 to 255) |
cmd1 | integer | Command parameter 1 (0 to 255) |
cmd2 | integer | Command 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])
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character index |
count | integer | Number 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)
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Index of the character performing the action |
targetIndex | integer | Index of the object being faced. If invalid, the function uses the character itself |
action | integer | Action 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)
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character index |
milliseconds | integer | Time, in milliseconds |
countUp | boolean | true = count up, false = count down (default) |
display | integer | Display style (0 to 255, default 5): 1 Time Limit, 2 Remaining Time, 3 Hunting Time, 4 Disassembly Failed, 5 Quest Survival Time |
close | boolean | true = 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)
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character index |
text | string | New 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
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character index |
gate | integer | Gate 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
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character index |
map | integer | Map number; must exist on this GameServer |
x | integer | X coordinate (clamped from 0 to 255) |
y | integer | Y 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
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character index |
type | integer | 0 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.
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
| Parameter | Type | Description |
|---|---|---|
aIndex | integer | Character index (the owner) |
class | integer | Monster code (must exist in the monster data) |
lifePercent | integer | Percentage added to maximum HP (0 to 10000, default 0) |
defensePercent | integer | Percentage added to defense (0 to 10000, default 0) |
damagePercent | integer | Percentage 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)