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:

ValueWhat it is
player, targetPlayerThe number that stands for a connected player. Functions that take a player take this.
A map numberThe number the map editor shows for a map.
An item, monster or NPC numberIts number in your world's lists, as the editors show it.
monster, monsterIndexNot the kind of monster: its place on the map it is on, counted from 0. GetMonsterType turns that into the kind.
An inventory slot1 to 30.

The server#

Script nameRuns whenmain is givenAnswering false
ServerStartThe server has loaded the world, before anyone can join.Nothing.—
ServerStopThe server is shutting down, while players are still connected and before the last save.Nothing.—
MinuteTimerEvery minute.Nothing.—
DayTimeThe world's clock reaches the hour day begins.Nothing.Keeps the light as it was, until the next DayTime or NightTime.
NightTimeThe world's clock reaches the hour night begins.Nothing.The same.

Joining and leaving#

Script nameRuns whenmain is givenAnswering false
ConnectSomething connects to the server, before any sign-in.ipAddress (string)Refuses the connection.
PlayerConnectA player has chosen a character, before it enters the world.playerDisconnects them.
JoinGameA character enters the world.playerKeeps them out.
PartGameA 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—
FloodA 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 nameRuns whenmain is givenAnswering 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.
BroadcastA player broadcasts to everyone.player, message (string)The broadcast is not sent.
PlayerTellA player sends a private message.player, otherPlayer, message (string)The message is not sent.
GuildChatA player speaks in guild chat.player, guildNumber, message (string), guildRank—
DescribeA player has changed their own description.player, description (string)—
HelpMeA player asks for help with /helpme, before the help window opens.player—
CommandA 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 nameRuns whenmain is givenAnswering false
PlayerWalkingA player is about to take a step.player, newX, newY, speedThe step is refused.
PlayerWalkA player has taken a step.player—
ChangeDirectionA player turns to face another way without moving.player—
ClickMap, ClickMap{map}A player clicks a square of the map.player, mapNumber, x, y—
ClickPlayerA player clicks on another player.player, targetPlayerThe other player's details are not shown.

Tiles#

These run when a player steps onto a tile the map's author marked.

Script nameRuns whenmain is givenAnswering 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—
DoorTileA player steps onto a door and it opens.player—
DamageTileA 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 nameRuns whenmain is givenAnswering false
UseObj, UseObj{item}A player uses or equips an item.player, itemNumber, inventorySlotThe item is not used.
UnuseObj, UnuseObj{item}A player takes off something they are wearing.player, equipmentSlotIt stays on.
DropObj, DropObj{item}A player drops an item.player, inventorySlot, itemNumber, quantityIt is not dropped.
DieDropObj, DieDropObj{item}A player has died and is about to lose an item.player, itemNumber, inventorySlot, quantityThey keep it.
GetObj, GetObj{item}A player is about to pick an item up off the ground.player, inventorySlot, itemNumber, mapItemIndex, quantityIt 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, itemNumberIt is not repaired.

Two of these run at more moments than their names suggest:

  • GetObj also runs after an item is bought from an NPC or given by a script. Its answer is ignored then. On a pickup inventorySlot is 0, because the item has no slot yet, and mapItemIndex is its place on the ground. Otherwise inventorySlot is where the item landed and mapItemIndex is -1. quantity is 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, GotObj is the simpler choice.
  • DropObj also runs when a player dies, alongside DieDropObj, 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 nameRuns whenmain is givenAnswering false
AttackMonsterA player's attack is aimed at a monster.player, monsterIndex, ref damageThe attack does nothing.
AttackPlayerA player's attack is aimed at another player.player, targetPlayer, ref damage, rollThe attack does nothing.
MonsterSee, MonsterSee{monster}A monster notices a player and is about to go after them.player, monsterThe monster leaves them alone.
MonsterAttackA 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, gainedExperienceThe player gets no experience for it.
KillPlayerOne player has killed another.player, targetPlayer—
PlayerDieA player has died, whatever killed them.playerThe server does none of what it does for a death: nothing is dropped and the player is not sent back to their start.
GainExpA player is about to gain experience.player, experience, isSharedExperience (bool)They do not gain it.
PlayerLevelUpA 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 nameAskedmain is given
PlayerDamageFor every swing or shot, before the target's armour.player, ref damage, ref shortfall
PlayerArmorWhenever a player is hit.player, ref damage
PlayerHitsPlayerFor one player's swing at another. It hits when the roll is greater than the target's agility.attacker, target, ref roll
PlayerHitsMonsterFor a player's swing at a monster.player, monster, monsterAgility, ref hit (bool)
MonsterHitsPlayerFor a monster's swing at a player.player, monster, ref hit (bool)
MonsterKillValueWhen a monster dies, before the killer's equipment counts.player, monster, ref experience
ExperienceMultiplierWhen experience from a kill is given.player, fromPlayer (bool), ref experience
GuildPartyShareOnce for the killer and once for each guildmate on the map who has guild party on.killer, member, experience, partners, partnerLevels, ref share
RegenerationFor every player, every 2 seconds.player, ref hp, ref energy, ref mana
LevelUpGainsWhen a player gains a level, before PlayerLevelUp.player

Trading and the bank#

Script nameRuns whenmain is givenAnswering false
NpcTrade, NpcTrade{npc}A player asks an NPC what it trades.player, npcNumberThe 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, tradeQuantityThe trade does not happen.
SellObj{item}The same trade. {item} is the item they would hand over.The same.The trade does not happen.
TradeObjThe same trade, whatever the items.The same.The trade does not happen.
DepositA player has put money in the bank.player, money—
WithdrawA player has taken money out of the bank.player, money—
BalanceA 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 nameRuns whenmain is given
CreateGuildA player has founded a guild.player, guildNumber
InviteGuildA player invites another to a guild.player, targetPlayer, guildNumber
JoinGuildA player has joined a guild.player, guildNumber
PartGuildA player is about to leave a guild.player, guildNumber
KickGuildA player is about to be removed from a guild.player, targetPlayer (-1 if they are not online), guildNumber
SetGuildRankA member's rank has been changed.player, targetPlayer, guildRank
DisbandGuildA guild is disbanded by its founder.player, guildNumber
PayGuildA player has paid money into a guild's bank.player, guildNumber, money
GuildBalanceA player asks for a guild's balance.player, guildNumber, balance
AddGuildDeclarationA guild declares an alliance or a war.player, guildNumber, targetGuildNumber, declarationType
RemoveDeclarationA declaration is about to be withdrawn.player, guildNumber, declarationIndex
BuyGuildHallA guild has taken a hall.player, guildHallNumber, guildNumber
LeaveGuildHallA 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 nameRuns whenmain is givenAnswering false
GodChatA message is sent to staff chat.player, message (string)The message is not sent.
GlobalMessageA global message is sent.player, message (string)—
GodMotdThe message of the day is changed.player, motd (string)—
GodWarpSomebody warps themselves to a place.player, destinationMap, destinationX, destinationY—
GodWarpToMeSomebody brings another player to themselves.See below.—
GodWarpMeToSomebody goes to another player.See below.—
GodBootA player is kicked.player, targetPlayer—
GodSetSpriteA player's sprite is changed.player, targetPlayer, spriteIndexThe sprite is not changed.
GodSetGuildSpriteA guild's sprite is set.player, guildNumber, spriteIndex—
GodResetMapA map is reset.player, mapNumber—
GodDeleteGuildA guild is deleted by staff.player, guildNumber—
GodEditScriptSomebody opens a script in the in-game editor.player, scriptName (string)The script is not opened.
GodUploadScriptSomebody 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);
}