My first map script: Difference between revisions

From The DarkMod Wiki
Jump to navigationJump to search
Tels (talk | contribs)
use the right file name
Geep (talk | contribs)
 
(One intermediate revision by one other user not shown)
Line 12: Line 12:
// the main function does not take arguments nor returns something
// the main function does not take arguments nor returns something
void main () {         
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
     sys.wait(100);  // wait 100 seconds
Line 23: Line 26:
     sys.println("Going to kill the entity " + $player1.getName() );
     sys.println("Going to kill the entity " + $player1.getName() );


    $player1.kill();     // kill the player
    $player1.setHealth(0); // kill the player. Use this instead of trying $player1.kill();
}
}
</pre>
</pre>
Line 29: Line 32:
Other useful things:
Other useful things:


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


== Includes ==
== Includes ==

Latest revision as of 18:12, 23 May 2023

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