Jump to content
Sign in to follow this  
tophe

Set trigger to react when all players are present

Recommended Posts

I'm making an end trigger...

It is supposed to go off when all players are present, plus a few other variables. Like this:

Condition: variableX == true and (all player units present)

The thing is that there is no AI on the player side, so the amount of player units will vary.

I'm thinking it would be best to put the player units ina list when the missions starts and then check the trigger condition to the presence of all in that list.

But I don't know how to do that. Can anyone help me out?

Share this post


Link to post
Share on other sites

Doesn't anyone know?

How do I get a trigger to react ONLY when all units in a list is present?

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> private ["_result", "_i"];

_result = true;

_i = 1;

while { (_i < 10) and _result } do {

   if (!isnil format ["p%1", _i]) then {

       if (call compile format ["!isnull p%1", _i]) then {

           call compile format ["_result = _result and (p%1 in _this);", _i];

       };

   };

   _i = _i + 1;

};

_result

When the players are named p1 to p10, the above code will return true if all players are in the given array.

Share this post


Link to post
Share on other sites

Thank you!

But how do I get it into a trigger?

What I want in the condition box is something like this:

Condition: present all in unitList

Share this post


Link to post
Share on other sites

<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">variableX && ({_x in thislist} count [p1,...] == 10)Just add all player units in the array and make sure the number is correct. More sophisticated you could do it that way:

Define an array myPlayerArray = [p1...] somewhere, e.g. in the init.sqf or in a player's init line.

Then use this in the trigger:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">variableX && ({_x in thislist || !(alive _x)} count myPlayerArray == count myPlayerArray) smile_o.gif

Share this post


Link to post
Share on other sites

Thank you so much!

That seems like the sollution I was looking for.

Just a question on that sollution...

The mission have 8 spots, so the amount of player units will vary depending on how many people are playing it.

Will this sollution work if one or more units are not present in the mission? If there is only two players then there will be only two player units... Can I have the list created dynamically by another trigger? So that it will put all present units in the list?

Thank you again!

Share this post


Link to post
Share on other sites

Put this in the init.sqf:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_allPlayers = [p1, ...];

myPlayerArray = [];

{

if !(isNull _x) then {myPlayerArray = myPlayerArray + [_x]}

} forEach _allPlayers;

Then you have only players in the array which are in use. But this does not take JIP'ed players into account... whistle.gif

/edit: I dunno if the vehicles command is returning units as well in your version, then it would be easily possible to dynamically create this array, with JIP'ed players... (http://community.bistudio.com/wiki/vehicles)

Share this post


Link to post
Share on other sites

Thanks.

Weird though.. If I add that snippet to the init.sqf I get an error  message (missing a { ). That also happens when I add it in a script and run it from the init.

Share this post


Link to post
Share on other sites

Ah.. I solved it. I just messed up a bit.

Thank you so much for that sollution! I've been looking for it for ages!

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  

×