My first map script

From The DarkMod Wiki
Jump to navigationJump to search

Create the script file

If your map is called for example maps/mydir/mymap.map, you must create a text file maps/mydir/mymap.script.

The contents

The map script needs to contain a main function. This function is called at the very start of your map, e.g. when the map is loaded for the first time. So if you want something to happen later, you need to pause the script and then do something. Here is an example:

// This is a comment and gets ignored by the script engine

// the main function does not take arguments nor returns something
void main () {         

    sys.waitFrame(); // always wait one frame before doing anything in main()
                     // this ensures that the init() routines have all finished

    sys.wait(100);   // wait 100 seconds

    /* $entityName here acts upon a specific entity. Be careful, if you rename
       the entity in DR, your script will break! $player1 is the player entity,
       and this only works in single player mode. However, there is no multiplayer
       in TDM, so we can safely use it for now: */

    // put some information in the console
    sys.println("Going to kill the entity " + $player1.getName() );

     $player1.setHealth(0); // kill the player. Use this instead of trying $player1.kill();
}

Other useful things:

  • $entity.remove() - removes an entity from the game
  • sys.waitFrame() - waits until the next frame

Includes

To organize your scripts, you can put different parts, for instance routines, into their own file and then include it.

#include script/myscript.script
Note: These include lines MUST go into a file called script/tdm_custom_scripts.script (and not your main map script), otherwise savegames cannot be loaded back!

See also