Events
An event is a moment the server offers to your scripts. A script answers an event by having its name. This page lists every event the server raises, what it hands to main, and what the script's answer changes.
If scripts are new to you, read An introduction to scripting first.
Reading the tables#
Script name. What to call the script. Capital letters do not matter. Where a name ends in a word in braces, such as JoinMap{map}, put a number there: JoinMap12. You can have the general script, the numbered one, or both.
main is given. The values the event hands over, by the names to use for them. Write only the ones you need, in any order. All are whole numbers (int) unless marked.
Answering false. What return false; stops. A dash means the event only tells you something happened, and its answer is ignored: write its main with void.
Where a general script and a numbered one both exist, either can answer false.
Some numbers come up throughout:
| Value | What it is |
|---|---|
player, targetPlayer | The number that stands for a connected player. Functions that take a player take this. |
| A map number | The number the map editor shows for a map. |
| An item, monster or NPC number | Its number in your world's lists, as the editors show it. |
monster, monsterIndex | Not the kind of monster: its place on the map it is on, counted from 0. GetMonsterType turns that into the kind. |
| An inventory slot | 1 to 30. |
The server#
| Script name | Runs when | main is given | Answering false |
|---|---|---|---|
ServerStart | The server has loaded the world, before anyone can join. | Nothing. | — |
ServerStop | The server is shutting down, while players are still connected and before the last save. | Nothing. | — |
MinuteTimer | Every minute. | Nothing. | — |
DayTime | The world's clock reaches the hour day begins. | Nothing. | Keeps the light as it was, until the next DayTime or NightTime. |
NightTime | The world's clock reaches the hour night begins. | Nothing. | The same. |
Joining and leaving#
| Script name | Runs when | main is given | Answering false |
|---|---|---|---|
Connect | Something connects to the server, before any sign-in. | ipAddress (string) | Refuses the connection. |
PlayerConnect | A player has chosen a character, before it enters the world. | player | Disconnects them. |
JoinGame | A character enters the world. | player | Keeps them out. |
PartGame | A player leaves the game. | player | — |
JoinMap, JoinMap{map} | A player arrives on a map. | player, mapNumber | — |
PartMap, PartMap{map} | A player leaves a map. | player, mapNumber | — |
Flood | A player has sent messages faster than your world's flood limit allows. | player, tick (how far over, in thousandths of a second) | Lets them stay. Otherwise they are disconnected. |
Chat#
| Script name | Runs when | main is given | Answering false |
|---|---|---|---|
MapSay, MapSay{map} | A player says something on a map, or emotes. | player, message (string) | The message is not shown. |
Yell, Yell{map} | A player yells. | player, message (string) | The yell is not shown. |
Broadcast | A player broadcasts to everyone. | player, message (string) | The broadcast is not sent. |
PlayerTell | A player sends a private message. | player, otherPlayer, message (string) | The message is not sent. |
GuildChat | A player speaks in guild chat. | player, guildNumber, message (string), guildRank | — |
Describe | A player has changed their own description. | player, description (string) | — |
HelpMe | A player asks for help with /helpme, before the help window opens. | player | — |
Command | A player types a /command the server does not know. | player, commandName (string), parameter0 to parameter3 (string) | The command counts as handled. Otherwise the player is told it is not a command. |
Command is how a world adds chat commands of its own. commandName is the word after the slash, and the four parameters are the words after it, with everything left over in the last.
bool main(int player, string commandName, string parameter0)
{
if (commandName.ToLower() == "home")
{
PlayerWarp(player, 1, 5, 5);
return false;
}
return true;
}
Moving#
| Script name | Runs when | main is given | Answering false |
|---|---|---|---|
PlayerWalking | A player is about to take a step. | player, newX, newY, speed | The step is refused. |
PlayerWalk | A player has taken a step. | player | — |
ChangeDirection | A player turns to face another way without moving. | player | — |
ClickMap, ClickMap{map} | A player clicks a square of the map. | player, mapNumber, x, y | — |
ClickPlayer | A player clicks on another player. | player, targetPlayer | The other player's details are not shown. |
Tiles#
These run when a player steps onto a tile the map's author marked.
| Script name | Runs when | main is given | Answering false |
|---|---|---|---|
Map{map}_{x}_{y} | A player steps on the script tile at that place on that map. | player | — |
TileScript_{number}, TS{number} | A player steps on a tile marked with that script number. Both names work. | player, playerX, playerY | — |
WarpTile, WarpTile_{map}_{x}_{y} | A player steps on a warp tile, before they are moved. The numbers in the name are where the tile leads. | player, destinationMap, destinationX, destinationY | — |
DoorTile | A player steps onto a door and it opens. | player | — |
DamageTile | A player is on a damage tile. It runs again each time they act while standing there. | player, damage (the number the map's author gave the tile) | — |
DestroyWall, DestroyWall{map}_{x}_{y} | A player destroys a breakable wall. | player, mapNumber, x, y | — |
A damage tile does nothing by itself. The DamageTile script decides what stepping on one means:
void main(int player, int damage)
{
SetPlayerHP(player, Math.Max(1, GetPlayerHP(player) - damage));
PlayerMessage(player, "The lava burns you!", BrightRed);
}
Items#
| Script name | Runs when | main is given | Answering false |
|---|---|---|---|
UseObj, UseObj{item} | A player uses or equips an item. | player, itemNumber, inventorySlot | The item is not used. |
UnuseObj, UnuseObj{item} | A player takes off something they are wearing. | player, equipmentSlot | It stays on. |
DropObj, DropObj{item} | A player drops an item. | player, inventorySlot, itemNumber, quantity | It is not dropped. |
DieDropObj, DieDropObj{item} | A player has died and is about to lose an item. | player, itemNumber, inventorySlot, quantity | They keep it. |
GetObj, GetObj{item} | A player is about to pick an item up off the ground. | player, inventorySlot, itemNumber, mapItemIndex, quantity | It stays on the ground. |
GotObj, GotObj{item} | A player has received an item: picked up, bought from an NPC, or given by a script. | player, inventorySlot, itemNumber | — |
Repair, Repair{item} | A player asks an NPC to repair an item, before they pay. | player, inventorySlot, itemNumber | It is not repaired. |
Two of these run at more moments than their names suggest:
GetObjalso runs after an item is bought from an NPC or given by a script. Its answer is ignored then. On a pickupinventorySlotis 0, because the item has no slot yet, andmapItemIndexis its place on the ground. OtherwiseinventorySlotis where the item landed andmapItemIndexis -1.quantityis how many, for money and ammunition, or how much wear the item has left. For anything that should happen once a player has an item,GotObjis the simpler choice.DropObjalso runs when a player dies, alongsideDieDropObj, and either can save the item.DropObj{item}runs as well for the item a player pays an NPC in a trade, with its answer ignored.
Combat#
| Script name | Runs when | main is given | Answering false |
|---|---|---|---|
AttackMonster | A player's attack is aimed at a monster. | player, monsterIndex, ref damage | The attack does nothing. |
AttackPlayer | A player's attack is aimed at another player. | player, targetPlayer, ref damage, roll | The attack does nothing. |
MonsterSee, MonsterSee{monster} | A monster notices a player and is about to go after them. | player, monster | The monster leaves them alone. |
MonsterAttack | A monster swings at a player. | player, monster, damage (0 if the swing misses) | The swing does not happen. |
MonsterDie, MonsterDie{monster} | A player has killed a monster. | player, monsterIndex, gainedExperience | The player gets no experience for it. |
KillPlayer | One player has killed another. | player, targetPlayer | — |
PlayerDie | A player has died, whatever killed them. | player | The server does none of what it does for a death: nothing is dropped and the player is not sent back to their start. |
GainExp | A player is about to gain experience. | player, experience, isSharedExperience (bool) | They do not gain it. |
PlayerLevelUp | A player has gained a level. | player | — |
In a name, {monster} is the kind of monster: MonsterDie7 runs when a monster of kind 7 dies.
A value marked ref is one the script may change. Write ref in front of it in main, and the server uses what you leave there:
bool main(int player, int monsterIndex, ref int damage)
{
// Double damage once the world's clock passes hour 20.
if (GetTime() >= 20)
{
damage = damage * 2;
}
return true;
}
Damage is kept between 0 and 255.
The game's arithmetic#
Ten more events ask a script to work something out. Every world starts with a script for each, described in the introduction. If one is missing or quarantined, the server uses its own rule.
| Script name | Asked | main is given |
|---|---|---|
PlayerDamage | For every swing or shot, before the target's armour. | player, ref damage, ref shortfall |
PlayerArmor | Whenever a player is hit. | player, ref damage |
PlayerHitsPlayer | For one player's swing at another. It hits when the roll is greater than the target's agility. | attacker, target, ref roll |
PlayerHitsMonster | For a player's swing at a monster. | player, monster, monsterAgility, ref hit (bool) |
MonsterHitsPlayer | For a monster's swing at a player. | player, monster, ref hit (bool) |
MonsterKillValue | When a monster dies, before the killer's equipment counts. | player, monster, ref experience |
ExperienceMultiplier | When experience from a kill is given. | player, fromPlayer (bool), ref experience |
GuildPartyShare | Once for the killer and once for each guildmate on the map who has guild party on. | killer, member, experience, partners, partnerLevels, ref share |
Regeneration | For every player, every 2 seconds. | player, ref hp, ref energy, ref mana |
LevelUpGains | When a player gains a level, before PlayerLevelUp. | player |
Trading and the bank#
| Script name | Runs when | main is given | Answering false |
|---|---|---|---|
NpcTrade, NpcTrade{npc} | A player asks an NPC what it trades. | player, npcNumber | The NPC's list is not shown, so the script can offer something of its own. |
BuyObj{item} | A player is about to make a trade with an NPC. {item} is the item they would receive. | player, boughtItemNumber, boughtQuantity, tradeItemNumber, tradeQuantity | The trade does not happen. |
SellObj{item} | The same trade. {item} is the item they would hand over. | The same. | The trade does not happen. |
TradeObj | The same trade, whatever the items. | The same. | The trade does not happen. |
Deposit | A player has put money in the bank. | player, money | — |
Withdraw | A player has taken money out of the bank. | player, money | — |
Balance | A player has asked for their bank balance. | player, balance | — |
BuyObj and SellObj only exist with a number. All three are asked about every trade, and any one of them can refuse it.
Guilds#
Every guild event tells you something happened. None can refuse it.
| Script name | Runs when | main is given |
|---|---|---|
CreateGuild | A player has founded a guild. | player, guildNumber |
InviteGuild | A player invites another to a guild. | player, targetPlayer, guildNumber |
JoinGuild | A player has joined a guild. | player, guildNumber |
PartGuild | A player is about to leave a guild. | player, guildNumber |
KickGuild | A player is about to be removed from a guild. | player, targetPlayer (-1 if they are not online), guildNumber |
SetGuildRank | A member's rank has been changed. | player, targetPlayer, guildRank |
DisbandGuild | A guild is disbanded by its founder. | player, guildNumber |
PayGuild | A player has paid money into a guild's bank. | player, guildNumber, money |
GuildBalance | A player asks for a guild's balance. | player, guildNumber, balance |
AddGuildDeclaration | A guild declares an alliance or a war. | player, guildNumber, targetGuildNumber, declarationType |
RemoveDeclaration | A declaration is about to be withdrawn. | player, guildNumber, declarationIndex |
BuyGuildHall | A guild has taken a hall. | player, guildHallNumber, guildNumber |
LeaveGuildHall | A guild has given up its hall. | player, guildHallNumber, guildNumber |
Staff commands#
These run when somebody with the right to use a command uses it. player is the person who typed it.
| Script name | Runs when | main is given | Answering false |
|---|---|---|---|
GodChat | A message is sent to staff chat. | player, message (string) | The message is not sent. |
GlobalMessage | A global message is sent. | player, message (string) | — |
GodMotd | The message of the day is changed. | player, motd (string) | — |
GodWarp | Somebody warps themselves to a place. | player, destinationMap, destinationX, destinationY | — |
GodWarpToMe | Somebody brings another player to themselves. | See below. | — |
GodWarpMeTo | Somebody goes to another player. | See below. | — |
GodBoot | A player is kicked. | player, targetPlayer | — |
GodSetSprite | A player's sprite is changed. | player, targetPlayer, spriteIndex | The sprite is not changed. |
GodSetGuildSprite | A guild's sprite is set. | player, guildNumber, spriteIndex | — |
GodResetMap | A map is reset. | player, mapNumber | — |
GodDeleteGuild | A guild is deleted by staff. | player, guildNumber | — |
GodEditScript | Somebody opens a script in the in-game editor. | player, scriptName (string) | The script is not opened. |
GodUploadScript | Somebody saves a script from the in-game editor. | player, scriptName (string) | The script is not saved. |
GodWarpToMe and GodWarpMeTo are given five whole numbers, matched by position: the player who typed the command, the other player, and the map, x and y of the destination. Write the ones you need in that order, under any names.
Timers and your own scripts#
A script started by ScriptTimer or MicroTimer is given one value, the player it was started for. A script run by another with RunScript is given what that script passed.
Neither kind has an event's list of names to match against, so values are matched by position: main takes them in the order they were given, under any names you like.
void main(int player)
{
PlayerMessage(player, "Time is up!", BrightRed);
}