Difference between revisions of "My first map script"

From The DarkMod Wiki
Jump to navigationJump to search
m (add note about includes)
(use the right file name)
Line 41: Line 41:
 
</pre>
 
</pre>
  
{{infobox|Note: These include lines '''MUST''' go into a file called '''"script/tdm_custom_include.script"''' (and not your main map script), otherwise savegames cannot be loaded back!}}
+
{{infobox|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 ==
 
== See also ==

Revision as of 09:33, 1 September 2012

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.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.kill();     // kill the player
}

Other useful things:

  • 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