OFPEC Forum
Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: Zipper5 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. :)
-
{_x in nameofyourvehicle} forEach (units grp1)
For some reason couldn't get that to work on a trigger condition field unless I used
call {{_x in nameofyourvehicle} forEach (units grp1)}
-
I made a function to do that
/* 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.
-
@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:
({ _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:
({ _x in nameofyourvehicle } count (units group theMan)) == count (units group theMan)
-
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:
{_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:
{_x in (crew vehicleName)} count (units grp1) > 0;
Untested, but should work!
Wolfrug out.
-
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. :)