Home   Help Search Login Register  

Author Topic: Detecting if a group is inside a vehicle (SOLVED)  (Read 1666 times)

0 Members and 1 Guest are viewing this topic.

Offline Zipper5

  • BIS Team
  • ****
Detecting if a group is inside a vehicle (SOLVED)
« on: 21 Dec 2008, 12:58:32 »
I've got an issue which is really bugging me... Heh.

Essentially, in the mission your squad is ambushed. Now there's a possibility that certain random members of the group will die depending on who the enemy AI targets. Later you are picked up by a different vehicle, after the possible members of the squad are dead. I've named the group "grp1" and I figured there's a way to detect if the remaining members of "grp1" are in the new vehicle. So far everything I've tried has turned sour. If anyone can tell me how to accomplish this, I will be very grateful.

Thanks guys. :)
« Last Edit: 21 Dec 2008, 14:54:01 by Zipper5 »

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: Detecting if a group is inside a vehicle
« Reply #1 on: 21 Dec 2008, 13:49:39 »
Code: [Select]
{_x in nameofyourvehicle} forEach (units grp1)
For some reason couldn't get that to work on a trigger condition field unless I used
Code: [Select]
call {{_x in nameofyourvehicle} forEach (units grp1)}
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Ext3rmin4tor

  • Members
  • *
Re: Detecting if a group is inside a vehicle
« Reply #2 on: 21 Dec 2008, 14:18:06 »
I made a function to do that

Code: [Select]
/* SYNTAX: [group_leader, vehicle] call compile preprocessFileLineNumbers "detectUnits.sqf"

ARGUMENTS: group_leader: The leader of the group mounted on the vehicle
vehicle: The vehicle itself
*/


//setting local variables
_leader = _this select 0;
_vehicle = _this select 1;

//unit array
_unitArray = units group _leader;

//get all the units mounted in the vehicle
_crew = crew _vehicle;

//function returning value
_isInVehicle = false;

//array used to count the unit inside the vehicle
_vehicleUnits = [];

//check if every unit in leader group is in the vehicle
{

//if the crew unit is a member of the leader group add it to the vehicle array
if (_x in (units group _leader)) then
{
_vehicleUnits = _vehicleUnits + [_x];
};

}
forEach  _crew;

/*if the number of units in the vehicle that are members of the original group
is equal to the number of units in the orinal group then all units are in the
vehicle and the returning value is set to true*/
if ((count _vehicleUnits) == (count _unitArray)) then {_isInVehicle = true};

//function returned value
_isInVehicle


This is a function, that means you can use it in trigger or waypoint condition field. To launch the function, since the group you want to check is also the player group, you can use the following code in a trigger condition field:

[leader player, infantryCarrier] call compile preprocessFileLineNumbers "detectCargo.sqf"

where infantryCarrier is the vehicle they have to board (use the name you chose in your mission since you didn't write it) and "detectCargo.sqf" is the script name (insert your script file name if it's different from mine). I tested the script with a small ambush and it works.
How can you shoot women and children?
Easy! Ya' just don't lead'em so much! Ain't war hell?!!

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: Detecting if a group is inside a vehicle
« Reply #3 on: 21 Dec 2008, 14:23:23 »
@h-: You are only testing if the last person in the group is in the vehicle (forEach gives the LAST value in the {} when it finishes). You need:
Code: (Trigger condition: All surviving members of a group are in a vehicle) [Select]
({ _x in nameofyourvehicle } count (units grp1)) == count (units grp1)

Not really so useful to check leader's group, since if the man you check is dead, then this won't work, but, you could:
Code: (Trigger condition: All surviving members of a soldier's group are in a vehicle) [Select]
({ _x in nameofyourvehicle } count (units group theMan)) == count (units group theMan)
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Detecting if a group is inside a vehicle
« Reply #4 on: 21 Dec 2008, 14:29:05 »
Edit: Spooner posted before me, but I might have misunderstood the question. My answer remains!

Um.

The easiest way to count the number of (living, or whatever) members in anything else, is to simply use the count command:

Code: [Select]
{_x in vehicleName} count (units grp1) > 0;

If there's more than one unit in grp1 also inside vehicleName, the count command will return a number > 0 --> trigger runs. You could also use:

Code: [Select]
{_x in (crew vehicleName)} count (units grp1) > 0;
 

Untested, but should work!

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline Zipper5

  • BIS Team
  • ****
Re: Detecting if a group is inside a vehicle
« Reply #5 on: 21 Dec 2008, 14:43:27 »
Thanks for the help guys. The leader of the group is actually the player, and there's a check (&& alive aP) in the line to make sure the player's still alive before it executes the next part. I'll try these out and see if they work. Thanks again. :)

Edit: Your solution worked perfectly, Spooner. Thanks mate. And thanks to everyone else who helped me out. :)
« Last Edit: 21 Dec 2008, 14:53:27 by Zipper5 »