From The Mana World
Revision as of 20:50, 9 June 2012 by Kandiman (talk | contribs) (tmwAthena Scripting Standards)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This page defines the scripting and formatting standards to be used for scripts submitted to The Mana World project.

Formatting

  • Code is to be indented using 4 spaces per indent.
  • 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.
  • Multiple sentences should carry a single space between the period at the end of the first sentence and the first letter of the next sentence.
  • Any dialog by an NPC should be put in double quotes (").
  • There should be no trailing whitespaces.
  • Separation of script header elements is to be done with a pipe (|).
  • Documentation within a script should be commented out using // as a prefix.
  • When checking for, creating, or deleting an item, the item name should be used instead of the item id.


Code and Variables

  • Code blocks should be separated from the others in a distinct 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.

001-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("treasurekey") < 3) goto L_WrongKey;
    delitem "treasurekey", 3;
    getitem "shortsword", 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, he is told not to have the right key. If he does, the player looses three keys and receives a short sword.

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


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 variable 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

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

See EAthena Scripting Reference