Objectives, triggering: Difference between revisions

From The DarkMod Wiki
Jump to navigationJump to search
Line 10: Line 10:
== Example: Let an object appear when an objective is completed ==
== 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. After you've done so, set its name to ''object'', than go to the specific objective in the OE, and typ in the '''success script''' field ''showObject''.
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.map'' is the name of your map. Type in the following code:
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 showObject() {
Line 21: Line 21:
   }
   }


That's it. The ''main'' method is called upon map start and let the object dissapear from game. When your desired objective is completed, the method ''showObject'' is called, what let the object appear again.
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 ==
== Making things more complex ==

Revision as of 19:16, 2 January 2013

Description

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.

Basics

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() {
   $object.show();
 }
 void main() {
   $object.hide();
 }

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 amount of objectives has been completed. To achieve this, create a trigger_count and a target_callscriptfunction entity. Fill the success target field of all the possible or required objectives with the name of the trigger_count. 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. The counter goes up and gets compared with the spawnarg "count". Once it reaches this, it will trigger the target_callscriptfunction, which than calls the function to let the object appear in-game.

Hint: All the success script fields stay empty, the function is NOT called by any objective directly

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