From The Mana World

This is an attempt to standardize the eAthena coding. Any suggestions are welcome to be posted on the discussion page before editing.

Indentation

Code is indented using tabs. Code in the same block should have the same indentation. Labels have no indentation. Menu options are on their own lines and are indented further.

Code Blocks

  • Code blocks should be separated from the others in a dinstinct way; the best way of doing it is to insert a blank line between code blocks.
  • Individual blocks should be together (i.e. without blank lines within them).
  • The opening brackets should be at the end of the parent line, not in a new line; the closing ones should be in a line of their own.

Example

An example is given by a quest to get a key for a chest:

// A treasure chest. You need three keys to open it.
new_5-1.gat,93,37,0     script  Treasure        111,{
	mes "Would you try to open it?";
	next;
	menu
		"Yup", L_Sure,
		"Nope", close;

L_Sure:
	if (countitem(537) < 3) goto L_WrongKey;
	delitem 537, 3;
	getitem 536, 1;
	mes "You opened it and found a short sword!";
	close;

L_WrongKey:
	mes "It seems that this is not the right key...";
	close;
}

The above script starts with describing the NPC (the chest, NPC sprite 111) and its location. Then follows what happens on activation. A message is shown, then an option dialog is displayed. Then, when the player has less than 3 keys (item id 537), he is told not to have the right key. If he does, the player looses three keys and receives a short sword (item id 536). This quest in particular is questionable as the explanation given to the player doesn't match the implemented behavior (possibly to make the quest more challenging), but I've put it here because it is short and shows one basic way to use the scripting system.

For more examples of the current system, check out the current scripts in use by the server. Beware though, this could affect your enjoyment of the game as it does spoil some of the mystery. Here's a link to git so you can view them in your browser:

http://gitorious.org/tmw-eathena-data/mainline/trees/master/npc

Note that anything said by an NPC should be put in double quotes ("). You can do that like this: "\"Hello!\" she said."

Defining Map Objects

Key
<TAB> a tab
text text that must be the same
text text to be changed

These sections describe how to define map objects.

Warp Definitions

Warps are what move players between maps. They can also be used to move players around a single map, if needed. Warps are defined like this:

map1,startX,startY<TAB>warp<TAB>name<TAB>width,height,map2,endX,endY

Key:

map1
the starting map
startX
the x-coordinate of the starting warp tile
startY
the y-coordinate of the starting warp tile
name
the name of the warp, unused but must be defined
width
the width of the warp
height
the height of the warp
map2
the ending map
endX
the x-coordinate of the tile the player will end up on
endY
the y-coordinate of the tile the player will end up on

Width and height are described in detail here: Warp Details.

Monster Definitions

Monsters are defined like this:

map,x,y,width,height<TAB>monster<TAB>name<TAB>mobID,count,spawn1,spawn2,event

map
the map the monsters should appear on
x
the x-coordinate of the spawn tile
y
the y-coordinate of the spawn tile
width
the tile width of the spawn area
height
the tile height of the spawn area
name
the name of the mob, unused but must be defined
mobID
the mob identifier of the desired monster (in the monster db)
count
the number to spawn
spawn1
the minimum delay between successive spawns (per individual)
spawn2
the minimum delay between death and respawn (per individual)
event
the script event to fire upon death

A detailed description of position and area can be found here: Mob Details.

NPC Definitions

Script Functions

A function reference can be found here. Not all functions are available or work as described, so please ask if you aren't sure.