Objectives, triggering

From The DarkMod Wiki
Jump to navigationJump to search


Sometimes a map requires that, after the completion of one or more objectives, something in the map changes. The example I'll use here is the appearance of an entity in the map. This method can be used for other things, too.


The first thing to understand is what the objectives editor (OE) offers. There are four fields in the OE that are interesting here. They are the success/failure target/script fields. These are the targets triggered or the script functions called when an objective succeeds or fails. Normally you won't use them very often, but they are quite useful.

Example: Let an object appear when an objective is completed

The first thing you have to do is to set up the object you want to appear once the player has finished an objective. For our example, we'll give it the name object. Then go to the specific objective in the OE, and type in the success script field showObject. This will be the name of a script function.

Now create a script file in your maps folder called mymapname.script, where mymapname is the name of your map. Type in the following code:

 void showObject() {
 void main() {

That's it. The main method is called upon map start and causes the object to disappear from the game. It's not really gone; it's just hidden. When your desired objective is completed, the method showObject is called, which causes the object to appear again.

Making things more complex

Of course, you can use a more complex setup if needed. Let's assume you want the object to appear after a certain number of objectives have been completed. To achieve this, create trigger_count and target_callscriptfunction entities. Fill the success target fields of all the possible or required objectives with the name of the trigger_count entity. On this entity set the spawnarg "count" "N", where N is the number of objectives that must be completed and let it target the target_callscriptfunction entity. On the latter, set the spawnarg "call" "showObject". That's it.

How does it work?

Once an objective is complete, it will trigger the trigger_count entity. That entity's counter goes up by 1 and gets compared with the spawnarg "count". Once the count reaches N, it will trigger the target_callscriptfunction, which then calls the script function to let the object appear in-game.

Hint: As all the success script fields are empty, the function is NOT called by any objective directly. This is done by the target entity.

--Obsttorte (talk) 08:41, 2 January 2013 (EST)