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.
- If Creating and NPC, remember to follow the rules stated in the NPC Development section.
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 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). The quest in particular is questionable as the explanation towards 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 SVN so you can view them in your browser:
http://svn.sourceforge.net/viewcvs.cgi/themanaworld/server-data/trunk/npc/
Note that anything said by an NPC should be put in double quotes ("). You can do that like this: "\"Hello!\" she said."