Objectives, triggering: Difference between revisions

From The DarkMod Wiki
Jump to navigationJump to search
Line 25: Line 25:
== Making things more complex ==
== 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.  
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?
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.
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: All the '''success script''' fields stay empty, the function is '''NOT''' called by any objective directly''
''Hint: If all the '''success script''' fields are empty, the function is '''NOT''' called by any objective directly.''


--[[User:Obsttorte|Obsttorte]] ([[User talk:Obsttorte|talk]]) 08:41, 2 January 2013 (EST)
--[[User:Obsttorte|Obsttorte]] ([[User talk:Obsttorte|talk]]) 08:41, 2 January 2013 (EST)

Revision as of 19:20, 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 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: If all the success script fields are empty, the function is NOT called by any objective directly.

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