Jump to content
wyattwic

Help needed, using trigger to return players and AI.

Recommended Posts

Hello all,

 

I cant for the life of me figure out how to have a trigger return a list of alive players and AI.

 

Would anyone be able to help me on this?  This is what happens when you take an extended break from coding. lol

Share this post


Link to post
Share on other sites

Call a script with thislist as argument and in the script:

params["_list"];
private _return = [];

{if(alive _x) then {_return pushBack _x;};} foreach _list;

//Do something with _return

There is probably a more elegant way to filter dead using from an array, but it is too early here...

Share this post


Link to post
Share on other sites

Thanks!

 

Outside processing like that would work, but I am having a hard time remembering how to do it from the condition block to minimize my overhead.  There are a ton of triggers.

 

I know that "vehicle player in thisList" would be the proper condition statement for just players, but I am just unsure how to grab AI units and players.  "alive in thislist" is my guess, but thats not syntacticaly correct.

Share this post


Link to post
Share on other sites

I know that "vehicle player in thisList" would be the proper condition statement for just players, but I am just unsure how to grab AI units and players.  "alive in thislist" is my guess, but thats not syntacticaly correct.

 

That condition would not return a list of alive players. That condition would have the trigger fire if the player's vehicle (or the player itself in the case of no vehicle) entered the trigger area and met the detection conditions set in the trigger menu. The equivalent condition that would include all units, player controlled or not, would simply be "this"

 

If you actually want to get this list and save it to a variable, you would do that in the activation section of the trigger, not the condition section. To capture everyone meeting the conditions of the trigger, you could simply use myVar = thisList. If you only want to capture those that are alive, you would need two lines in your activation field: myVar = []; {if (alive _x) then {myVar pushBack _x}} forEach thisList

Share this post


Link to post
Share on other sites

If you actually want to get this list and save it to a variable, you would do that in the activation section of the trigger, not the condition section. To capture everyone meeting the conditions of the trigger, you could simply use myVar = thisList. If you only want to capture those that are alive, you would need two lines in your activation field: myVar = []; {if (alive _x) then {myVar pushBack _x}} forEach thisList

 

Processing myVar elsewhere may get complicated, at the trigger conditionally empties the array. Imagine a {hint name _x;sleep 1;} foreach myVar; for example. The results can't be predicted. Calling external processing script is probably the way to go.

Share this post


Link to post
Share on other sites

Processing myVar elsewhere may get complicated, at the trigger conditionally empties the array. Imagine a {hint name _x;sleep 1;} foreach myVar; for example. The results can't be predicted. Calling external processing script is probably the way to go.

 

I was making the implicit assumption that the trigger would only fire once. If it is a repeatable trigger, then your concern is completely valid.

Share this post


Link to post
Share on other sites

Thank you both for responding.

 

This is in fact a repeating trigger.  It is being used to detect the disposition of opposing forces in an AO, or shutdown the AI within if no one is near.  The code I have done so far just needs an array of alive players and AI to factor in those calculations.

 

I will probably just have to have a external script process whats going on for the alive checking, but how would I just return the AI and players? 

"player in thislist" would return players, but what returns just AI?  Would it work to place it as "player in thislist || AI? in thislist"?

 

 

I can handle all of this via an outside script, but with so many triggers going, I need to keep load to a minimal.

Thank you so much guys,

Share this post


Link to post
Share on other sites

Simple: Dead units don't trigger a side west/east trigger. "Activation side" and thislist only contains alive units ;)

 

This is how I spawn and despawn zones in my insurgency mission:

_atrg=createTrigger["EmptyDetector", [_xPos,_yPos],false];
_atrg setTriggerArea[A3I_ActivationRange,A3I_ActivationRange,0,true];
_atrg setTriggerActivation["WEST","PRESENT",true];
_atrg setTriggerStatements["this && isServer && A3I_ServerReady", format["%1 call A3I_fnc_activateZone;",_forEachIndex], format["%1 call A3I_fnc_deactivateZone;",_forEachIndex]];
_atrg setTriggerTimeout [1, 1, 1, false];

Share this post


Link to post
Share on other sites

I will probably just have to have a external script process whats going on for the alive checking, but how would I just return the AI and players? 

"player in thislist" would return players, but what returns just AI?  Would it work to place it as "player in thislist || AI? in thislist"?

 

It's important to understand that "player in thisList" doesn't actually return a list of players. Like all conditions, it returns either true or false; that's it. What you are doing by using that condition is making it so that the trigger only fires locally on a machine where that player meets the trigger detection criteria. Because "player" has a different value on each machine in a network game, the effect is that all players can cause the trigger to fire, but -- importantly -- each player can only cause the trigger to fire for itself. In other words, if Player A is in the trigger zone, the trigger will fire for Player A. But if Player B is NOT in the zone when this happens, the trigger will NOT fire for Player B, because from the perspective of Player B's machine, the condition of the trigger has not been met. This may very well be the desired behavior for your application, but if your end goal is to get an accurate list of the number of players in a zone that is then evaluated by some code on the server, it might not be. It's worth double-checking, anyway.

 

As I stated in the previous reply, if you want to get a list of everyone in the trigger, both player and AI, then the proper condition is just "this," which essentially means that the trigger just defers to the detection criteria set in the trigger menu. Then you can pass the contents of the "thisList" variable -- which will include all units who meet the trigger detection criteria, both player- and AI-controlled -- to your script (through the on activation field) to handle whether or not the units are alive. Alternatively, as NeoArmageddon helpfully pointed out, a check for alive status is implicitly made if you set the trigger to filter by side because all dead units are automatically moved by the engine to the civilian side (although historically this has not always happened instantly). 

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

×