Jump to content
Sign in to follow this  
travhimself

Using triggerAttachVehicle to sync a Trigger to a Group

Recommended Posts

Okay gang, bear with me while I describe what I'm trying to do.

Using the visual editor, I'm able to:

1) Create a group of units.

2) Create a trigger that activates when OPFOR is NOT PRESENT.

3) Use the Synchronize tool to attach the trigger to the group leader.

4) ...Then kill all of the units and watch the trigger fire when the last one dies. In other words, when all the group members are dead.

Sample A: http://i.imgur.com/o9yKdKv.jpg (105 kB)

Sample B: http://i.imgur.com/zzmf5GK.jpg (108 kB)

Now, I'm trying to replicate this programmatically using triggerAttachVehicle.

_emptytrigger = createTrigger["EmptyDetector", [0 , 0, 0]];
_emptytrigger setTriggerArea[25000, 25000, 0, false];
_emptytrigger setTriggerActivation["OPFOR", "NOT PRESENT", true];
_emptytrigger setTriggerStatements["this", "hint 'group killed'", "hint 'done'"];
_emptytrigger triggerAttachVehicle [enemy1];

I've created a trigger and set up all the necessary params. I've given each of the OPFOR units a name in the visual editor (enemy1, enemy2, enemy3), so I then attach the trigger to enemy1 (the group's leader). However, this results in a trigger that fires when enemy1 dies -- the other two units are basically disregarded.

Is there a way to attach a trigger to a group, and/or the group's leader, in order to mimic the functionality that I'm able to get with the visual editor? I've been fighting with this for a few hours now and not having any luck. The docs page has some notes about setting the source to a "GROUP", but frankly the description is pretty confusing.

Any help would be greatly appreciated. Thanks!

Share this post


Link to post
Share on other sites

In the respective BIKI article it says:

  • If the activation source is "VEHICLE", "GROUP", "LEADER" or "MEMBER", it's changed to "NONE".
  • When the source is "GROUP", "LEADER" or "MEMBER", it's coupled to the group, otherwise it's coupled to the vehicle and the source is changed to "VEHICLE".

So you have to change your setTriggerActivation statement to "GROUP" so it gets attached to the group of enemy1.

Share this post


Link to post
Share on other sites

Hey, thanks for chiming in.

Unfortunately that doesn't seem to work. I've simply changed "OPFOR" to "GROUP" in the activation statement (I believe that's the change you were suggesting), so now I have:

_emptytrigger = createTrigger["EmptyDetector", [0 , 0, 0]]; 
_emptytrigger setTriggerArea[25000, 25000, 0, false]; 
_emptytrigger setTriggerActivation["GROUP", "NOT PRESENT", true]; 
_emptytrigger setTriggerStatements["this", "hint 'group killed'", "hint 'done'"]; 
_emptytrigger triggerAttachVehicle [enemy1];

But the trigger will fire as soon as enemy1 dies, regardless of the other two units. I've also tried "LEADER" and "MEMBER" with the same result.

I feel like I must be missing something obvious here... Any other suggestions?

Share this post


Link to post
Share on other sites

try this:

place in the init of one of the groupmembers,

myGroupName = group this;

use the count command with alive in the trigger statement.

_emptytrigger setTriggerStatements["{alive _x} count units myGroupName == 0", "hint 'group killed'", "hint 'done'"];

Share this post


Link to post
Share on other sites

I'm trying to understand the point of having the radius of the trigger at 25,000m, if you just want something to happen after all units of that group are dead then just executed something like:

waitUntil {({alive _x} count units myGroupName) isEqualTo 0};

//whatever code you want executed after the group is dead, i.e.

hintSilent "Group Dead.";

Share this post


Link to post
Share on other sites
try this:

place in the init of one of the groupmembers,

myGroupName = group this;

use the count command with alive in the trigger statement.

_emptytrigger setTriggerStatements["{alive _x} count units myGroupName == 0", "hint 'group killed'", "hint 'done'"];

I was using this method initially. But there are a couple problems with this, for what I'm trying to accomplish.

My original post describes my test case; I was using the visual editor to illustrate something that I'm trying to accomplish via a script. In reality I'm creating groups dynamically -- this means I can't simply assign a unique variable name to each one in the init field of the editor. We start to wander down the rabbit hole here, but... My real problem was that if I had a loop that created 10 groups, I couldn't figure out a way to create a unique variable name for each one (ie myGroup01, myGroup02, etc.), and then recall that variable name in the setTriggerStatements line.

It seems to me that there must be a way to mimic the behavior of the Synchronize, and I'm guessing the answer is triggerAttachVehicle. If I can get it working the way I want/expect, I think that lends itself better to the type of looped group/trigger creation I'm after.

All the same, thanks for your reply! Definitely open to hearing other solutions.

---------- Post added at 11:51 ---------- Previous post was at 11:40 ----------

I'm trying to understand the point of having the radius of the trigger at 25,000m, if you just want something to happen after all units of that group are dead then just executed something like:

waitUntil {({alive _x} count units myGroupName) isEqualTo 0};

//whatever code you want executed after the group is dead, i.e.

hintSilent "Group Dead.";

You're right: the enormous radius isn't relevant to anything. That was just left over from testing.

Your method is super clean, and might be the ticket... But there are some complicating factors, which I described in my reply to Demonize above. I'll be creating groups in a loop, and would want to track each one separately. So that leads to two concerns:

1) How can I name groups (and then recall them by name) in a sequential order? In pseudocode:

count = 0;
while (count < 10) {
   // create a unique variable name by appending the iteration to "myGroup_"
   myGroup_count = createGroup WEST;

   // recall
   waitUntil {({alive _x} count units myGroup_count) isEqualTo 0}

   // increment the counter
   count = count + 1;
}

2) If there are 10, 20, 30 groups alive in a scenario, does waitUntil have the potential to start causing performance issues?

Share this post


Link to post
Share on other sites

This is how you create variables dynamically.

call compile format ["myGroup_%1 = createGroup WEST;",count];

Format creates the dynamic string. Compile turns it into code. Then call... well it calls that code.

Share this post


Link to post
Share on other sites

First of all, bad misunderstanding on my side regarding triggerAttachVehicle.

It does not get you rid of the trigger area, it only defines which unit (of the side/group/all) can activate the area.

Or to say it that way, I was not able to setup the activationStatement in a way that it triggers the inexistence of a group.

waitUntil can in fact cause heavy load at some point if you have a lot of waitUntils running, because they check their condition on each frame while a trigger only checks it roughly every 0.5 seconds. You're probably better off using a while-loop with a sleep inside.

If you wanna have total control of the groups, you can use Fight9's solution with the "call compile format". What I'm actually wondering is why you want to do that, 'cus as of your loop, all you seemingly want to do is spawn 10,20,30 or so groups one after another as soon as the previous one is dead. If that's the case, you don't need to worry about group naming as groups automatically delete themselves as soon as there's no member left.

Share this post


Link to post
Share on other sites
If you wanna have total control of the groups' date=' you can use Fight9's solution with the "call compile format". What I'm actually wondering is why you want to do that, 'cus as of your loop, all you seemingly want to do is spawn 10,20,30 or so groups one after another as soon as the previous one is dead. If that's the case, you don't need to worry about group naming as groups automatically delete themselves as soon as there's no member left.[/quote']

Sort of. I have a series of potential spawn points all over the map, and three types of groups that can spawn -- "scouts", "patrols", and "static". At the start of the scenario, let's say I spawn 10 patrols, 5 scouts, and 5 static groups. Once a group of a given type is eliminated, I show the player an alert and then spawn a new group of that type at a new random location.

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
Sign in to follow this  

×