Jump to content
ethrendil

Trigger that counts object in an area and then fires.

Recommended Posts

I'm looking to build a trigger for an area that will act as a logistics base. I want the players to deliver supply boxes from different areas on the map to a specific area. Once they are delivered I want it to progressively unlock new things. I've figured out how to create a trigger that activates on the following condition:

 

{_x isKindOf "CargoNet_01_box_F"} count thislist == 2; 

 

Which works fine when two cargo boxes are delivered, but I don't know how to continuously check/activate the trigger when more boxes are added. For example I'd like i script to fire when 2 boxes are delivered, and then a different script to fire when 4 boxes are delivered, and on and on.

Would I need to create a function with a switch do block that runs down case by case? If so I'm not sure what the formatting would look like. Any help would be appreciated, I'm trying to learn but scripting confuses the heck out of me sometimes.

Share this post


Link to post
Share on other sites

thisList? What is your predefined condition? (activation CIVILIAN PRESENT ?)

 

If box are delivered one by one (at least with a short delay > 0.5 sec.), you can do a repeatable trigger with:

count (thisList select {_x isKindOf "CargoNet_01_box_F"}) mod 2 == 0

This triggers every 2 boxes.

Then it's on your hand for the activation script (counter on how many times, you run it).

Share this post


Link to post
Share on other sites
16 minutes ago, pierremgi said:

thisList? What is your predefined condition? (activation CIVILIAN PRESENT ?)

 

If box are delivered one by one (at least with a short delay > 0.5 sec.), you can do a repeatable trigger with:

count (thisList select {_x isKindOf "CargoNet_01_box_F"}) mod 2 == 0

This triggers every 2 boxes.

Then it's on your hand for the activation script (counter on how many times, you run it).


The trigger I mentioned activates on ANYBODY present and is repeatable (my script deletes the boxes afterwards).

With this script

count (thisList select {_x isKindOf "CargoNet_01_box_F"}) mod 2 == 0

does that just divide the total by 2, and then if there is a remainder it doesn't fire?

 

I tried it and it works, but it always fires the same script. I'm not sure how to activate a different script when the count is 4 or 6 instead of 2. The other problem I have is that if the boxes already delivered are moved and then put back in the trigger it re-activates.

Share this post


Link to post
Share on other sites

Civilian is better than anybody (filter)

Yes, the mod (modulo) works as remainder of your number of crates divided per 2.

Your script can be written like this:

if (isNil "crateBiCount") then {crateBiCount = 0};   // works just on 1st occurrence

crateBiCount = crateBiCount + 1;

call {

  if (crateBiCount == 1) exitWith { <1st code>};

  if (crateBiCount == 2) exitWith { <2nd code>};

  ....

};

 

For skipping some "moving" crates, add a variable on them and filter:

count (thisList select {_x isKindOf "CargoNet_01_box_F" && isNil {_x getVariable "alredyCount"}) mod 2 == 0

 

and before your script,  (on activation) add:

{_x setVariable ["alredyCount",TRUE] } forEach (thisList select {_x isKindOf "CargoNet_01_box_F" && isNil {_x getVariable "alredyCount"});

then your script (execVMed sqf or called code or spawned one...)

NOTE: if you filter the crates, there is no more reason for modulo, you can write:

count (thisList select {_x isKindOf "CargoNet_01_box_F" && isNil {_x getVariable "alredyCount"})== 2

as well (there is no reason to have more than 2 crates unfiltered).

Share this post


Link to post
Share on other sites

You are awesome pierremgi! It works perfectly. Now I will try and incorporate it into a Warlords mission where the crates spawn on sectors and when the player airlifts them back to base they are rewarded with different unlocks (uav, weapons crate, etc).

Thank you!

  • Like 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×