TacoTuesday 1 Posted March 2, 2014 I have two player groups who I want to get into a vehicle. How can I check that all present players on the server are in the vehicle's cargo through a trigger? Share this post Link to post Share on other sites
KC Grimes 79 Posted March 2, 2014 There's a few ways to do it. Could check to see if all members of the group are in a vehicle, could check location, or, as in my example, could check the vehicle seats themselves. Note: This would need to be executed when there are no characters in the Cargo of the vehicle, unless they are permanently in there. Also note that playableUnits includes any active AI that could have been selected via the host menu. _playercount = count playableUnits; _emptyspots = vecnamehere emptyPositions "Cargo"; _targetfill = _emptyspots - _playercount; waitUntil {_emptyspots == _targetfill}; Check out the commands playableUnits and emptyPositions to see how they work AND their limitations. Share this post Link to post Share on other sites
TacoTuesday 1 Posted March 2, 2014 (edited) well i found this code that seems to be doing the trick: this; {(alive _x) && (_x in h1)} count (playableUnits + switchableUnits) == {alive _x} count (playableUnits + switchableUnits) but i can't get the hold waypoint I have synced to it to go off Edit: nevermind this isn't working Edited March 2, 2014 by TacoTuesday Share this post Link to post Share on other sites
KC Grimes 79 Posted March 2, 2014 (edited) Ah, so you're having that part in the trigger as well. In that case, I suggest you make the trigger condition: this && trg1go == 1 And in init.sqf put: [] execVM "scriptname.sqf"; and in scriptname.sqf put: trg1go = 0; _playercount = count playableUnits; _emptyspots = vecnamehere emptyPositions "Cargo"; _targetfill = _emptyspots - _playercount; waitUntil {_emptyspots == _targetfill}; trg1go = 1; Edit: If you want an alive check, put the following in scriptname.sqf instead of the above: trg1go = 0; _aliveplayers = []; { if (alive _x) then { _aliveplayers = _aliveplayers + [_x]; }; } forEach playableUnits _playercount = count _aliveplayers; _emptyspots = vecnamehere emptyPositions "Cargo"; _targetfill = _emptyspots - _playercount; waitUntil {_emptyspots == _targetfill}; trg1go = 1; Again, look into the commands, specifically forEach. Be sure to learn why this stuff works. Edited March 2, 2014 by Grimes [3rd ID] 1 Share this post Link to post Share on other sites
John Kozak 14 Posted March 5, 2014 (edited) This can be done a bit easier: allInTheVehicle = false; while {(not allInTheVehicle)} do { allInTheVehicle = true; { if (!alive _x || vehicle _x != myVehicle) then {allInTheVehicle = false;} } forEach playableUnits; sleep 0.2; } globalAllInTheVehicle = true; trigger activation: globalAllInTheVehicle This code snippet will cycle until all alive players are in the specific myVehicle. When all players are in, it will fire corresponding trigger. The advantage is that there is no heavy code in trigger condition (which degrades performance heavily). Edited March 5, 2014 by DarkWanderer 1 Share this post Link to post Share on other sites
weparo 10 Posted March 5, 2014 (edited) Two groups? ({(alive _x) && !(_x in saidvehicle)} count (units groupone) == 0) && ({(alive _x) && !(_x in saidvehicle)} count (units grouptwo) == 0) this will become true if all living units of groupone and grouptwo are in the saidvehicle Hope this helps you, Weparo Edited March 5, 2014 by Weparo Set a ( wrong :P Share this post Link to post Share on other sites
11Bullets 10 Posted December 23, 2014 (edited) I don't mean to dredge old threads, but this thread is the most applicable to what I've been trying to do and I've used some of the code folks have listed so trying here first. I'm trying to get the same function, helo land at designated point and await players to enter then once players have entered it will fly to next waypoint. I'm setting it up in a multiplayer mission, so player counts may change from one play to the next. I've tried the various ways of getting it done, and so far things are working except for a few small issues. First issue is I give my squad the order to enter a bird, and the count fires the trigger and the bird will lift and head to next waypoint even if I as the player haven't entered. The second issue is that I'd like to have the count check for TWO helo cargos instead of just the one (24 players on the mission 3 squads each of 8 guys, only 18 fit in Huron, so need two birds). As it stands right now, things mostly work but a little bit wonky. I can give part of the squad order to move into helo 1 and when they do it lifts and flies, helo 2 sits and waits. I can give my other guys order to get into helo 2 and when they do it lifts and flies. So things are working, but something is going weird with the unit count. I'm not by any means fluent in coding, I realize it may come easy to some folks but for me it's like smashing my face into a brick wall, I just can't wrap my brain around it. I tried fiddling with the code Grimes gave (great job, btw!) to make it check for cargo of both birds and look for players AND playable units, and I just end up breaking it and don't know the proper ways to write things in. Here's my modified version of Grimes' script: trg1go = 0; _aliveplayers = []; { if (alive _x) then { _aliveplayers = _aliveplayers + [_x]; }; } forEach playableUnits _playercount = count _aliveplayers; _emptyspots = helo1 emptyPositions "Cargo" && helo2 emptyPositions "Cargo"; _targetfill = _emptyspots - _playercount; waitUntil {_emptyspots == _targetfill}; trg1go = 1; I don't know what kind of context change needs to go in since the _emptyspots is looking for multiple items. I also don't know how to add the distinction to check for playableunits and switchable units (I know that there is a diff in the two for single/multiplayer. Edited December 24, 2014 by 11Bullets added script code Share this post Link to post Share on other sites
Larrow 2827 Posted December 24, 2014 _groupMembers = ( units squad1 + units squad2 + units squad3 ); { _unit = _x; { _unit in _x; }count [ helo1, helo2 ] > 0 }count _groupMembers == { alive _x }count _groupMembers; Where squad1,2 and 3 are the names of your groups and helo1 and 2 are your helicopters. It counts each unit in the squads and checks if they are in either helicopter, this number is then compared against the number of alive units in all the squads. 1 Share this post Link to post Share on other sites
11Bullets 10 Posted December 24, 2014 Sweet, I'll give that a shot! Will it work if there are less players than the mission max? For instance, if only 12 guys decide to play, and they don't disable AI but they leave their squads at the base, will it compare the 12 in the helos versus the 12 other AI units and never lift the helos off? Also, because I really do try to learn this stuff, when it's comparing the groupmembers against zero, the code looks like it would trigger as soon as one person entered either helo. What am I not understanding? Share this post Link to post Share on other sites
Larrow 2827 Posted December 24, 2014 (edited) For instance, if only 12 guys decide to play, and they don't disable AI but they leave their squads at the base, NO. As written above it checks all squad members whether players or AI so if you leave some back at base it will fail to work.If you just want to check for players then _groupMembers = ( units squad1 + units squad2 + units squad3 ); { _unit = _x; { _unit in _x && isPlayer _unit; }count [ helo1, helo2 ] > 0 }count _groupMembers == { alive _x && isPlayer _x }count _groupMembers; If you have AI with you just make sure a player is the last person to board else the helos will take off leaving AI behind. Also, because I really do try to learn this stuff, when it's comparing the groupmembers against zero, the code looks like it would trigger as soon as one person entered either helo. What am I not understanding? Presume you mean this part { _unit in _x && isPlayer _unit; }count [ helo1, helo2 ] > 0 A count structure iterates each index supplied in the array so [ helo1, helo2] and runs the code for each index. If the code returns true then a hidden counter is increased by 1. It is this hidden counter that you are comparing against. So the above would look like... Is the unit in Helo1 and is the unit a player, if so it returns true Is the unit in Helo2 and is the unit a player, if so it returns true As we know its impossible for a unit to be in both helos at the same time then we are only looking for a result of 1 or > 0 0 = not in any of the helos 1 = is in one of the helos 2 = is in both of the helos :/ lol As this compare (count > 0) itself returns a true of false this increases the outer counter which is iterating through each unit. This is then compared to how many of all the group members are alive and are players. So if the number of units that are in a helo and are players is equal to the number of units that are alive and are players your good to go. Hope that makes sense Edited December 24, 2014 by Larrow 1 Share this post Link to post Share on other sites
11Bullets 10 Posted December 24, 2014 (edited) Larrow I tried your code in a trigger condition, it gives me an error local variable in global space just before the second "_groupmembers". Am I putting it in the wrong spot? I toyed around with another couple of ways to do it, and I can get it to work with a hold waypoint at the same location as the landing, synced with a radio trigger switch. So the birds will land and sit, and even if someone boards, they hold until the radio trigger is given. It isn't the flow of the mission I'd originally hoped for, but it works. -edit, going to try your second script. Also, thanks much for the explanation. I don't code much lol, so I was thinking it counts literally like a count of 1, 2, 3, 4, whatever number of guys in the helo. So I was thinking as soon as two guys get in a bird it's going to be 2, which is more than zero. I wish I understood this stuff better lol. Same result on the second script, error local variable in global space at same spot. Edited December 24, 2014 by 11Bullets Share this post Link to post Share on other sites
dreadedentity 278 Posted December 24, 2014 Larrow I tried your code in a trigger condition, it gives me an error local variable in global space just before the second "_groupmembers". local variables cannot be use in editor Share this post Link to post Share on other sites
Larrow 2827 Posted December 24, 2014 Larrow I tried your code in a trigger condition, it gives me an error local variable in global space just before the second "_groupmembers". Am I putting it in the wrong spot?If your using it in a trigger just remove the underscores from infront of groupmembers ..... groupMembers = ( units squad1 + units squad2 + units squad3 ); { _unit = _x; { _unit in _x && isPlayer _unit; }count [ helo1, helo2 ] > 0 }count groupMembers == { alive _x && isPlayer _x }count groupMembers; 1 Share this post Link to post Share on other sites