From The Mana World
m (User:Kess/eAthena scripting moved to User:Kess/Scripting: I'm going to rework this)
(Narrow down scope a bit; rewrote punctuation)
Line 1: Line 1:
This is an attempt to standardize the eAthena scripting. Any suggestions are welcome to be posted on the discussion page before editing.
This is a proposal-in-making on standardizing both eAthena and TMWserv scripting. Any suggestions are welcome to be posted on the discussion page.


==Conventions==
== Typographical style ==
There exist various schools on typographical conventions, and most of them vary depending on situation. The following are recommendations for writing scripts in the Mana World. Examples for both [[eAthena Scripting Standards|eAthena]] and [[scripting|TMWserv]] will follow alongside each other. These style recommendations should of course be adjusted to the language in question when doing [[translations]].


===Typographical style===
=== Punctuation ===
Typographical conventions vary depending on situation. The following are recommendations for an international English on the eAthena client (which does not support Unicode at this writing).
# Ending a sentence:
#* Use multiple punctuation marks sparingly.
#* Refrain from separating sentences with two or more spaces.
# Something cut off or missing:
#* Use an [http://en.wikipedia.org/wiki/Ellipsis ellipsis] (…) for something missing. (Replace with three dots, ..., in eAthena scripting.)
#* Use an [http://en.wikipedia.org/wiki/Dash#Em_dash em dash] (—) for something cut off. (Replace with two normal dashes in eAthena scripting.)
# Offsetting text parenthetically:
#* Use the [http://en.wikipedia.org/wiki/Dash#Em_dash em dash] (—) surrounded by a single pair of spaces. (Replace with two normal dashes in eAthena scripting.)
# Intervals and other ranges:
#* Use an [http://en.wikipedia.org/wiki/Dash#En_dash en dash] (–) for marking ranges, both numeric and other. (Replace with two normal dashes in eAthena scripting.)
#* Compounds use the normal dash.


'''Punctuation'''
'''eAthena example'''
* Use only one space ( ) after the punctuation ending a sentence.
// 1. Sentence ending punctuation
* Use three dots (...) for an ellipsis, which marks something cut off.
mes "A sentence. Another sentence!";
* Use two dashes (--) for wider dashes, which are used in several constructions, among them denoting ranges and offsetting parts of a text.
** Please add spaces around the dashes when they are used parenthetically.
// 2. Missing or cut off text
mes "\"No, I don't want to--\"";
mes "It seems ... he died.";
// 3. Parenthetically offset text
mes "By this apple -- and not any other -- she will rule the world.";
// 4. Ranges
mes "Lately the Tulimshar--Hurnscald highway is rather non-lethal.";
mes "\"Give me 100--200 itens, pliz!\"";


  // Punctuation example
'''TMWserv example'''
mes "[Luca the Hunter]";
  -- 1. Sentence ending punctuation
mes "\"Luckily I had a camera with me! Here's a picture of it<span style="color:green;">...</span>\"";
do_message(npc, char, "A sentence. Another sentence!")
mes "A liquid<span style="color:green;"> -- </span>smelling strangely of fermented apples<span style="color:green;"> -- </span>is applied.";
-- 2. Missing or cut off text
do_message(npc, char, "“No, I don’t want to—”")
do_message(npc, char, "It seems … he died.")
-- 3. Parenthetically offset text
do_message(npc, char, "By this apple — and not any other — she will rule the world.")
-- 4. Ranges
do_message(npc, char, "Lately the Tulimshar–Hurnscald highway is rather non-lethal.")
do_message(npc, char, "“Give me 100–200 itens, pliz!”")


'''Quotes'''
=== Quotes ===
* Use \" for direct speech.
* Use \" for direct speech.
** For the double quotation mark not to interfere with the scripting code, a backslash needs to be prepended it.
** For the double quotation mark not to interfere with the scripting code, a backslash needs to be prepended it.
Line 26: Line 56:
  mes "<span style="color:green;">\"</span>Aw, you <span style="color:green;">don't</span> have enough gold on you!<span style="color:green;">\"</span>";
  mes "<span style="color:green;">\"</span>Aw, you <span style="color:green;">don't</span> have enough gold on you!<span style="color:green;">\"</span>";


'''Formatting text'''
=== Text formatting ===
* Item and monster names, please use the names in the way shown by the client (e.g., Black Scorpion, Bottle of Sand) outside direct speech in the dialogues.
* Item and monster names, please use the names in the way shown by the client (e.g., Black Scorpion, Bottle of Sand) outside direct speech in the dialogues.
* Emphasis may be formatted with capital letters, use it sparingly.
* Emphasis may be formatted with capital letters, use it sparingly.
Line 35: Line 65:
  mes "\"I fought, of course! It hit me here <span style="color:green;">*points at a bruise at his shoulder*</span>.\"";
  mes "\"I fought, of course! It hit me here <span style="color:green;">*points at a bruise at his shoulder*</span>.\"";


===Coding conventions===
== Scripting style ==
'''Comments'''
Should in general follow the [[Hacking#Coding_style_guidelines|coding style guidelines]].
 
=== Comments ===
* Each file should begin with a comment block describing the scope and use of the file.
* Each file should begin with a comment block describing the scope and use of the file.
** <span style="color:red;">Put a template here?</span>
** <span style="color:red;">Put a template here?</span>


'''Indentation'''
=== Indentation ===
* All indentations are made with tabs, one for each indentation level.
* All indentations are made with tabs, one for each indentation level.
* Labels use no indentations at all.
* Labels use no indentations at all.
Line 55: Line 87:
  close;
  close;


'''Various'''
=== Blocks of code ===
* Script files should end with a newline (a empty line).
 
 
'''Code blocks'''
* Code blocks should be separated from each other in a dinstinct way; the best way of doing it is to insert a blank line between code blocks.
* Code blocks should be separated from each other in a dinstinct way; the best way of doing it is to insert a blank line between code blocks.
* Do not add blank lines within individual blocks.
* Do not add blank lines within individual blocks.
* The opening brackets should be at the end of the parent line, not in a new line; the closing ones should be on a line of their own.
* The opening brackets should be at the end of the parent line, not in a new line; the closing ones should be on a line of their own.
* In creating an 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:
{| border=0
|
<pre>
// 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;
}
</pre>
|}
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 SVN so you can view them in your browser:
http://themanaworld.svn.sourceforge.net/viewvc/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."
==Map objects==
{|border="0" cellspacing="0" cellpadding="2" style="float: right;"
!colspan="2"| Key
|-
| <TAB>
| a tab
|-
| text
| static text, do not change
|-
| '''text'''
| obligatory value, change this
|-
| '''''text'''''
| optional value, may be skipped
|}
These sections describe how to define map objects.
=== Warps ===
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'''
Where
* '''map1''' is the map which the player will warp from
* '''startX''' is the x-coordinate of the tile the player will warp from
* '''startY''' is the y-coordinate of the tile the player will warp from
* '''name''' is the name of the warp, unused but must be defined
* '''width''' is the width of the warp
* '''height''' is the height of the warp
* '''map2''' is the map which the player will warp to
* '''endX''' is the x-coordinate of the tile the player will end up on
* '''endY''' is the y-coordinate of the tile the player will end up on
Width and height are described in detail in [[EAthena Scripting Standards/Warp Details|Warp Details]].
<pre>// Warp example (npc/new_10-1-xmas/passages.txt)
new_10-1.gat,69,19 warp tovillage 4,1,new_11-1.gat,69,127</pre>
=== Monsters ===
Monsters are defined like this:
'''map''','''x''','''y''','''width''','''height'''<TAB>monster<TAB>'''name'''<TAB>'''mobID''','''count''','''spawn1''','''spawn2''','''event'''
Where
* '''map''' is the map the monsters should appear on
* '''x''' is the x-coordinate of the spawn tile
* '''y''' is the y-coordinate of the spawn tile
* '''width''' is the tile width of the spawn area
* '''height''' is the tile height of the spawn area
* '''name''' is the name of the mob, unused but must be defined
* '''mobID''' is the mob identifier of the desired monster (in the monster database [http://themanaworld.svn.sourceforge.net/viewvc/themanaworld/server-data/trunk/db/mob_db.txt?view=markup])
* '''count''' is the number to spawn
* '''spawn1''' is the minimum delay between successive spawns (per individual)
* '''spawn2''' is the minimum delay between death and respawn (per individual)
* '''event''' is the script event to fire upon death
A detailed description of position and area can be found in [[EAthena Scripting Standards/Mob Details|Mob Details]].
<pre>// Monster example (npc/new_9-1-woodland/monsters.txt)
new_9-1.gat,0,0,0,0 monster EvilMushroom 1013,25,0,0,0
new_9-1.gat,0,0,0,0 monster SleepFlower 1014,40,0,0,0
new_9-1.gat,0,0,0,0 monster Alzarin 1032,1,2700000,1800000,0</pre>
=== NPCs ===
NPCs are defined like
'''map''','''x''','''y''','''direction'''<TAB>script<TAB>'''name'''<TAB>'''npcID''','''''area1''''','''''area2''''',{
:'''''script'''''
}
Where
* '''map''' is the map the NPC is located in
* '''x''' is the x-coordinate of the NPC
* '''y''' is the y-coordinate of the NPC
* '''direction''' is the direction the NPC faces, unused but must be defined
* '''name''' is the name of the NPC, to hide (the latter part of) a name to the client begin (that part of) the name with a hash (#)
* '''npcID''' is the NPC identifier (in the NPC database [http://themanaworld.svn.sourceforge.net/viewvc/themanaworld/tmwdata/trunk/npcs.xml?view=markup])
* '''''area1''''' and '''''area2''''' describe the map area which activates the NPC, optional
* '''''script''''' is the NPC script, see the below
The name of the NPC can be hidden to the player, part of the name or the whole. Begin the name with a hash (#) to hide the whole name, or add it before the part which should be truncated (it will be truncated to the end).
<pre>// NPC example with activation area (npc/new_37-1-woodland-mine/miners.txt)
new_37-1.gat,78,59,0 script Miner 109,1,1,{
mes "[Miner]";
mes "\"I'm sorry, but this area is closed off.\"";
}</pre>
=== Shops ===
Shops are defined like
'''map''','''x''','''y''','''direction'''<TAB>shop<TAB>'''name'''<TAB>'''npcID''','''inventory'''
Where
* '''map''' is the map the shop is located in
* '''x''' is the x-coordinate of the shop
* '''y''' is the y-coordinate of the shop
* '''direction''' is the direction the shop faces, unused but must be defined
* '''name''' is the name of the shop, to hide (the latter part of) a name to the client begin (that part of) the name with a hash (#)
* '''npcID''' is the NPC identifier for the shop
* '''inventory''' is a comma separated inventory list of items to sale
The inventory is defined like
'''itemID''':'''price'''[,'''itemID''':'''price''']*
Where [...]* means that part can be repeated as necessary, and
* '''itemID''' is the item identifier (in the item database [http://themanaworld.svn.sourceforge.net/viewvc/themanaworld/server-data/trunk/db/item_db.txt?view=markup])
* '''price''' is the price the item is sold for
You add an item:price pair for any item that should be sold by the shop.
<pre>// Shop example (npc/new_23-1-dimonds-cove/dimonds.txt)
new_23-1.gat,24,27,0 shop Bartender 107,539:175,567:500,568:500</pre>
== Script Functions ==

Revision as of 12:51, 25 February 2009

This is a proposal-in-making on standardizing both eAthena and TMWserv scripting. Any suggestions are welcome to be posted on the discussion page.

Typographical style

There exist various schools on typographical conventions, and most of them vary depending on situation. The following are recommendations for writing scripts in the Mana World. Examples for both eAthena and TMWserv will follow alongside each other. These style recommendations should of course be adjusted to the language in question when doing translations.

Punctuation

  1. Ending a sentence:
    • Use multiple punctuation marks sparingly.
    • Refrain from separating sentences with two or more spaces.
  2. Something cut off or missing:
    • Use an ellipsis (…) for something missing. (Replace with three dots, ..., in eAthena scripting.)
    • Use an em dash (—) for something cut off. (Replace with two normal dashes in eAthena scripting.)
  3. Offsetting text parenthetically:
    • Use the em dash (—) surrounded by a single pair of spaces. (Replace with two normal dashes in eAthena scripting.)
  4. Intervals and other ranges:
    • Use an en dash (–) for marking ranges, both numeric and other. (Replace with two normal dashes in eAthena scripting.)
    • Compounds use the normal dash.

eAthena example

// 1. Sentence ending punctuation
mes "A sentence. Another sentence!";

// 2. Missing or cut off text
mes "\"No, I don't want to--\"";
mes "It seems ... he died.";

// 3. Parenthetically offset text
mes "By this apple -- and not any other -- she will rule the world.";

// 4. Ranges
mes "Lately the Tulimshar--Hurnscald highway is rather non-lethal.";
mes "\"Give me 100--200 itens, pliz!\"";

TMWserv example

-- 1. Sentence ending punctuation
do_message(npc, char, "A sentence. Another sentence!")

-- 2. Missing or cut off text
do_message(npc, char, "“No, I don’t want to—”")
do_message(npc, char, "It seems … he died.")

-- 3. Parenthetically offset text
do_message(npc, char, "By this apple — and not any other — she will rule the world.")

-- 4. Ranges
do_message(npc, char, "Lately the Tulimshar–Hurnscald highway is rather non-lethal.")
do_message(npc, char, "“Give me 100–200 itens, pliz!”")

Quotes

  • Use \" for direct speech.
    • For the double quotation mark not to interfere with the scripting code, a backslash needs to be prepended it.
  • Contractions and quotes within the direct speech use the single quote '.
// Quote example
	mes "\"Ah, Agostine! The 'legendary tailor'!\"";
	mes "\"Aw, you don't have enough gold on you!\"";

Text formatting

  • Item and monster names, please use the names in the way shown by the client (e.g., Black Scorpion, Bottle of Sand) outside direct speech in the dialogues.
  • Emphasis may be formatted with capital letters, use it sparingly.
  • Actions may be put inside asterisks, use it sparingly.
// Formatting example
	mes "\"I was fighting scorpions for experience and I bumped into a RED one.\"";
	mes "\"I fought, of course! It hit me here *points at a bruise at his shoulder*.\"";

Scripting style

Should in general follow the coding style guidelines.

Comments

  • Each file should begin with a comment block describing the scope and use of the file.
    • Put a template here?

Indentation

  • All indentations are made with tabs, one for each indentation level.
  • Labels use no indentations at all.
  • Menus have all their options on their own lines, and indented one level.
  • If clauses...
// Indentation example
L_label:
	mes "What do you want to do?";
	next;
	menu
		"Spend money", -,
		"Script a fun quest", L_good_choice;
	close;

Blocks of code

  • Code blocks should be separated from each other in a dinstinct way; the best way of doing it is to insert a blank line between code blocks.
  • Do not add blank lines within individual blocks.
  • The opening brackets should be at the end of the parent line, not in a new line; the closing ones should be on a line of their own.