From The Mana World
m (Meko moved page TmwAthena Scripting Standards to Archive:TmwAthena Scripting Standards: (old version, please delete))
 
(No difference)

Latest revision as of 19:01, 25 November 2015

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

Formatting

  • One NPC per file, except in cases of 'flavor' NPC's who only have one or two lines.
  • When indenting is required, code is to be indented using 4 spaces per indent.
  • Code in the same block should have the same indentation.
  • Menu options are on their own lines and are given an additional indentation.
  • 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.
  • Documentation within a script should be commented out using // as a prefix.

Code and Variables

  • Permanent player/account variables should be documented at the beginning of the file.
  • Dynamic and local @variables should be set to 0 before calling close;
  • Separation of script header elements is to be done with a pipe |.
  • When checking for, creating, or deleting an item, the item name should be used instead of the item id.
  • There should be a newline before every label.
  • There should not be a newline after the label.
  • When writing conditional statements, a newline should be used between if (condition) and conditional_command;.
    • Exception to this rule is when the conditional_command is a goto at the beginning of a major script block.


Example

An example which shows correct NPC definition, indentation, label definition, and commenting:

// 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;
}

For more complex 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 the GitHub repository so you can view them in your browser:

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