From The Mana World
Line 5: Line 5:


== Indentation ==
== Indentation ==
Code is indented with four spaces. 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. When using an if-statement, there should be a line break after the condition and the conditional command should be indented further.
* Code is indented with four spaces.  
* 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.  
* When using an if-statement, there should be a line break after the condition and the conditional command should be indented further.


== Code Blocks ==
== Code Blocks ==
Line 17: Line 21:
An example is given by a quest to get a key for a chest:
An example is given by a quest to get a key for a chest:


{| border=0
{| style="width:850px;" border=0 cellspacing="10"
|
|-valign="Top"
<pre>
|<pre>
// A treasure chest. You need three keys to open it.
// A treasure chest. You need three keys to open it.
new_5-1.gat,93,37,0     script Treasure       111,{
002-4.gat,93,37,0|script|Treasure|111,{
mes "Would you try to open it?";
next;
menu
"Yup", L_Sure,
"Nope", close;


L_Sure:
    if (TMW_Quest >= 38) goto L_Finished;
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 "There is a chest here.";
mes "It seems that this is not the right key...";
    mes "Do you want to try to open it?";
close;
    next;
    menu
        "Yes.", L_Yes,
        "No.", -;
    close;
 
L_Yes:
    if(countitem("TreasureKey") < 3) goto L_Not_Enough;
    getinventorylist;
    if (@inventorylist_count == 100 && countitem("TreasureKey") > 3) goto L_TooMany;
    mes "You opened the chest and found a short bow!";
    delitem "TreasureKey", 3;
    getitem "ShortBow", 1;
    set TMW_Quest, 38;
    close;
 
L_Not_Enough:
    mes "It seems that you do not have the right key for this chest yet...";
    close;
 
L_Finished:
    mes "You have already opened this chest.";
    close;
 
L_TooMany:
    mes "You do not have enough room to loot this chest. Maybe you should try again later.";
    close;
}
}
</pre>
</pre>
|}
|}
 
This script starts with describing the NPC (the chest, NPC sprite 111) and its location (map 002-4 X=93, Y=37, in tiles from top left of the map). Then follows what happens on activation. A message is shown (mes), 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.
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:
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
https://github.com/themanaworld/tmwa-server-data/tree/master/world/map/npc


Note that anything said by an NPC should be put in double quotes ("). You can do that like this: "'''\"'''Hello!'''\"''' she said."
Note that anything said by an NPC should be put in double quotes ("). You can do that like this: "'''\"'''Hello!'''\"''' she said."
Line 63: Line 82:
[[Media:Tester.txt]]
[[Media:Tester.txt]]
== Defining Map Objects ==
== Defining Map Objects ==
{|border="0" cellspacing="0" cellpadding="2" style="float: right;"
 
!colspan="2"| Key
|-
| <TAB>
| a tab
|-
| text
| text that must be the same
|-
| ''text''
| text to be changed
|}


These sections describe how to define map objects.
These sections describe how to define map objects.
Line 81: Line 89:
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:
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''
''map1'',''startX'',''startY''|warp|''name''|''width'',''height'',''map2'',''endX'',''endY''


Key:
Key:
Line 108: Line 116:
Monsters are defined like this:
Monsters are defined like this:


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


;map
;map

Revision as of 19:03, 14 November 2012

Template:Status outdated

This article has the following gaps: Needs to be updated with Thread 13653 and Thread 13672, which are generally accepted but there might be more discussion

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 with four spaces.
  • 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.
  • When using an if-statement, there should be a line break after the condition and the conditional command should be 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.
002-4.gat,93,37,0|script|Treasure|111,{

    if (TMW_Quest >= 38) goto L_Finished;

    mes "There is a chest here.";
    mes "Do you want to try to open it?";
    next;
    menu
        "Yes.", L_Yes,
        "No.", -;
    close;

L_Yes:
    if(countitem("TreasureKey") < 3) goto L_Not_Enough;
    getinventorylist;
    if (@inventorylist_count == 100 && countitem("TreasureKey") > 3) goto L_TooMany;
    mes "You opened the chest and found a short bow!";
    delitem "TreasureKey", 3;
    getitem "ShortBow", 1;
    set TMW_Quest, 38;
    close;

L_Not_Enough:
    mes "It seems that you do not have the right key for this chest yet...";
    close;

L_Finished:
    mes "You have already opened this chest.";
    close;

L_TooMany:
    mes "You do not have enough room to loot this chest. Maybe you should try again later.";
    close;
}

This script starts with describing the NPC (the chest, NPC sprite 111) and its location (map 002-4 X=93, Y=37, in tiles from top left of the map). Then follows what happens on activation. A message is shown (mes), 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:

https://github.com/themanaworld/tmwa-server-data/tree/master/world/map/npc

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

Using as little variables as you need

So there are some quests, which require lots of variables. Think of monster oil quest, Oric and Warum quest etc.

This can often be done by bitmasking: One variable has 32 bits. So a variabe can store 2^32 different numbers: 4294967296

But sometimes you only need numbers from 0 to 15, but more of these variables. but numbers in range 0 to 15 can be stored in 4 bits ( 2^4 = 16 different numbers)

Here is an example how to use bitmasking: Media:Tester.txt

Defining Map Objects

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|warp|name|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|monster<TAB>name|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

Actual script functions are stored or imported in the file, regardless rhey are called from a Map, NPC, Mob or item: tmwa-server-data/world/map/npc/scripts.conf The file tmwa-server-data/world/map/npc/_import.txt imports all NPC scripts wich are stored under the respective map name folders, usually under NPC name.

See EAthena Scripting Reference