Jump to content
HeroesandvillainsOS

Putting an "or" condition in a trigger?

Recommended Posts

So I have a hostage mission just about done. Originally I made it with SP in mind but thinking on it, I think co-op could be doable but I need to adjust two specific triggers I set.

Currently, I have two triggers set to only be recognized when both the player (p1) and the hostage (h1) are present. One is to release the hostage from captivity and the other is for mission complete after I bring the hostage safely back to base. I'm currently using:

p1 in thislist && h1 in thislist
So obviously this works when there's only one playable unit to consider.

I have six playable units all grouped to p1 (p1, p2, p3, p4, p5, p6). Does anyone know how I can get these triggers to go off when any one of the playable units plus the hostage are present? I'm imagining a situation where most of us are dead and only one or two playable units are alive to complete the mission. I have no idea how to write it and would appreciate some help on that.

Share this post


Link to post
Share on other sites


({_x in thislist} count ((units group p1) + [h1]) == {alive _x} count ((units group p1) + [h1]))

  • Like 1

Share this post


Link to post
Share on other sites

{_x in thisList} count [p1...p6] > 0 && h1 in thisList

EDIT: ninja'd

Share this post


Link to post
Share on other sites
{_x in thislist} count [p1,p2,p3,p4,p5,p6,p7,p8,p9] > 0

Should do it.

 

Edit: Darn, getting old(er). The one from kylania is the most reliable one because alive check.

 

 

Cheers

Share this post


Link to post
Share on other sites

This might work:

{_x in thislist} count Playableunits > 0 && h1 in thislist

You can probably also switch out playableUnits against [p1,p2,p3,p4,p5,p6]

 

Edit: Like the others said. :D

Share this post


Link to post
Share on other sites
({_x in thislist} count ((units group p1) + [h1]) == {alive _x} count ((units group p1) + [h1]))
Is this the actual functioning code that I can copy/paste into the trigger condition?

If not, would it be too much of a bother to have you write it for me? Does

((units group p1)
mean all six grouped playable units are counted?

Share this post


Link to post
Share on other sites

Oh shoot.

It just dawned on me that the trigger I "release" my hostage with...

The hostage is set to setcaptive and disableAI move. When I enter the trigger, the hostage is set "free" and is to join the player group (which is lead by p1).

If p1 dies, the other players would need to be able to take control of the group so they can command the hostage to follow them back to base.

Is there anyway around that? Will surviving players (p2 - p6) automatically be assigned group lead by default if p1 dies by the game or does it need a script?

Share this post


Link to post
Share on other sites

I'm out of likes for the day so I wanted to thank you for the reassurance. :)

Have one of mine.

Share this post


Link to post
Share on other sites

mean all six grouped playable units are counted?

 

 

Yup, and the hostage!  Here's how it works:

({_x in thislist} count ((units group p1) + [h1]) == {alive _x} count ((units group p1) + [h1]))

This is a comparison of two counts.  On the left side we're counting "How many group members of p1 including the hostage are in this trigger's list?" then comparing to see if that count is equal to "How many group members of p1 including the hostage are alive?".  If the two numbers match, trigger!

(units group p1)

On both sides this is the first thing evaluated.  It uses the units and group commands to make a list of group members where p1 is a member.  First we evaluate group p1 which returns a Group (data type) of which p1 is a member. (Actually, looks like I could have just used units p1, alas!)  Next we use the units command to get an array of units, in this case your [p1, p2, p3, p4, p5, p6].  Saves us from having to recode anything should someone else join or leave the group.  So now we have, on both sides of the equation, an array of our players.

 

Next we'll save some time and simply add the hostage to that array so we don't have to check separately on them using this code:

// This evaluates out to:  ([p1, p2, p3, p4, p5, p6] + [h1])
((units group p1) + [h1])

In this case I used the + operator to add a value to an array however I probably should have used pushBack: (in this case it's not really that important since it's a single value in a single trigger)  Using + we need h1 to be an Array since we're added the arrays but for pushBack we can just have h1 as an Object (no [ ]) since the command will just add the object to the array for us.

((units group p1) pushBack h1)

Now we're ready to count!

({_x in thislist} count ((units group p1) + [h1])

// which is now: (_x in thislist} count [p1, p2, p3, p4, p5, p6, h1])

The count command will walk through each element of the array to it's right and run the code to it's left on it.  Each time through the magic variable _x will represent the current value.  So first time through _x will be p1, second time through _x will be p2 and so on.  thislist is a special variable as well.  It means "the objects that satisfy the triggers activation settings".  So, if p1's group is all BLUFOR and so is h1, you can could have it be BLUFOR PRESENT.  If h1 is a civilian however you'd need to change it to ANYBODY PRESENT otherwise h1 won't be detected.

 

So we're using the in command to check if p1, then p2, then p3 and so on are also in the list generated by the trigger and saved as thislist.  If everyone is in the trigger area it'll evaluate out to this:

(_x in [p1, p2, p3, p4, p5, p6, h1]} count [p1, p2, p3, p4, p5, p6, h1] == 7

So if everyone is there we're looking for a value of 7.  Left side done!

 

Right side is exactly the same but instead of checking if people are in the trigger list we're checking to make sure they are alive.  So if p2 dies, we won't stop the rescue because they can never get into the trigger.

{alive _x} count [p1, p2, p3, p4, p5, p6, h1] == 7

7 == 7!  Yay!  Now, if p2 was dead then they aren't considered in the trigger list (once the game realizes they are dead "Oh no, 2, is down!") so the numbers would change to 6 == 6 and the trigger would still activate.

 

So yeah, slap this in your trigger and go save h1!

({_x in thislist} count ((units group p1) + [h1]) == {alive _x} count ((units group p1) + [h1]))

Make sense? :)

 

Just noticed that pushBack returns the added index, not the array so in this case + would be better.

  • Like 2

Share this post


Link to post
Share on other sites

Kylania, your explanations are always awesome and always make perfect sense. Thanks for the detailed breakdown! If only the actual coding part made any sense to me though. LOL!

Reading your response, and I apologize if I misunderstood, it seems that this code is going to require all alive units to be present. Am I wrong on that?

I'm looking for the trigger to accept any unit p1-p6 + the hostage. Not all p1-p6 + the hostage.

Example: Let's assume p1 and p2 are dead. P3 might want to "rescue the hostage," while p4, p5 and p6 might want to wait well outside the trigger area, clearing a path for the chopper to pick them up and return them all back to base.

In a perfect world, I'd like this trigger to get activated by any single p unit + the hostage; regardless whether any of them are alive or dead or choose to enter the trigger area.

Is the script you wrote requiring 'all' alive playable units to be in the trigger, or 'any' alive playable unit to be in the trigger?

Now I'm going back to your post to try to digest it all. It's a goldmine but makes my eyes cross. :) This scripting stuff is hard!

Share this post


Link to post
Share on other sites

Ahh, sorry I misunderstood.

({_x in thislist} count (units group p1) > 0) && h1 in thislist

 If you only need 1 member, why not just join h1 to the group as part of the rescue and simply check for:

h1 in units p1

Or even just have the rescue process itself complete whatever next step you want to have happen.  

 

How exactly are you rescuing the guy?

Share this post


Link to post
Share on other sites

Ahh, sorry I misunderstood.

({_x in thislist} count (units group p1) > 0) && h1 in thislist
If you only need 1 member, why not just join h1 to the group as part of the rescue and simply check for:

h1 in units p1
Or even just have the rescue process itself complete whatever next step you want to have happen.

How exactly are you rescuing the guy?

I'm not at home for the exact code, but here's the rescue procedure.

The hostage (h1) is set to spawn at 3 locations. One set location and two "random" markers; meaning he could end up being at any one of the three locations at mission start. If it matters, he's a BLUFOR unit (like my players), but just stripped of his gear.

At each of the 3 hostage spawn points, I've placed a trigger. These three triggers are set for him to be setcaptive (so OPFOR doesn't kill him), and his movement has been disabled (so he doesn't walk outside the trigger area(s) ).

Currently, when the player (p1) enters the trigger, h1 becomes no longer setcaptive, his movement is restored, and he's forced to join the player group.

In talking with one of my ALiVE friends, I was brainstorming whether or not this mission *could* feasibly be co-op compatible. Then it struck me that the way I have it set up, if I (p1) were to die, the remaining players (p2-p6) wouldn't ever be able to complete the mission because they'd never be allowed to activate the rescue trigger, or the mission complete trigger (which also requires p1 and h1 to both be present).

So I was looking for a way for not only any playable unit (p1-p6) to be able to activate this trigger - regardless of who is alive or dead or near the trigger area - but also to maintain the integrity of the hostage not being able to move or recognized as any enemy by OPFOR until one player, any player, manually enters the trigger area.

Sorry if I'm not making sense.

Share this post


Link to post
Share on other sites

Somebody brought to my attention the II code. Would this work?

p1 in thislist || p2 in this list || p3 in thislist || p4 in thislist || p5 in thislist || p6 in this list && h1 in thislist
Is II a substitute for "or"? I actually can't tell if they're writing two uppercase i's or |.

Share this post


Link to post
Share on other sites

Somebody brought to my attention the II code. Would this work?

 

p1 in thislist || p2 in this list || p3 in thislist || p4 in thislist || p5 in thislist || p6 in this list && h1 in thislist
Is II a substitute for "or"?

 

Yes it is. I never use it, nor do I use && when "and" is nicer to my eyes.

Share this post


Link to post
Share on other sites

Yes it is. I never use it, nor do I use && when "and" is nicer to my eyes.

Is "and" an acceptable replacement for && and is "or" and acceptable replacement for || ? I'd assume both would need "" around them to be recognized?

Share this post


Link to post
Share on other sites
(p1 in thislist || p2 in this list || p3 in thislist || p4 in thislist || p5 in thislist || p6 in this list) && h1 in thislist

Needs parentheses.

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites
(p1 in thislist || p2 in this list || p3 in thislist || p4 in thislist || p5 in thislist || p6 in this list) && h1 in thislist

Needs parentheses.

 

Cheers

 

I'm getting an error saying I'm missing ) with this code. And I corrected the space between this and list in the p5 example, same thing.

Share this post


Link to post
Share on other sites

He had some spaces between a couple of the "thisList" parts:

(p1 in thislist || p2 in thislist || p3 in thislist || p4 in thislist || p5 in thislist || p6 in thislist) && h1 in thislist

Share this post


Link to post
Share on other sites

He had some spaces between a couple of the "thisList" parts:

(p1 in thislist || p2 in thislist || p3 in thislist || p4 in thislist || p5 in thislist || p6 in thislist) && h1 in thislist

Oh haha! Yeah I missed the first one. Thanks!

Share this post


Link to post
Share on other sites

Another crude option is to just use 6 Triggers. One for each possible player.

Share this post


Link to post
Share on other sites

Here's a demo mission to take a look at for a hostage rescue idea.

Thanks, Kylania. I really appreciate all the help (as always, you are are real asset to the community). I'm sure this mission is much more elegant than what I have going so I look forward to looking at it (though thanks to you guys, what I have going seems to work! :) ).

Another crude option is to just use 6 Triggers. One for each possible player.

Speaking of assets to the community, one of my favorite add on makers! Hi Von Quest!

That's actually such a simple and brilliant idea I obviously didn't consider it on my own. :(

It never ceases to amaze me how there's so many roads and bridges that can end up in the same location in this game. Sometimes the answer is so simple it looks you dead in the eyes. You just need to know it's got a bead on you I guess.

I'll learn. Probably by the time Arma 7 is out I'll have mastered Arma 3. SQF and general all around logic are not my strong suits.

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

×