Jump to content
Sign in to follow this  
Ramsen IV

Trying to find specific unit in group.

Recommended Posts

I'm trying to locate a specific unit in group by type: (I_Sniper_F and I_Spotter_F)

 

_spawn = selectRandom ["snipe1_0","snipe1_1","snipe1_2"];
_grp = [getMarkerPos _spawn, RESISTANCE, (configfile >> "CfgGroups" >> "Indep" >> "IND_F" >> "Infantry" >> "HAF_SniperTeam")] call BIS_fnc_spawnGroup;
_grp setBehaviour "STEALTH";
_grp setCombatMode "YELLOW";
_array = units _grp;

_sniper = {_x isKindOf ["Man", configfile >> "CfgVehicles" >> "I_Sniper_F"]} forEach _array;  // _x is general error so this way did not work
_spotter = allUnits select {typeOf "I_Spotter_F" in _array}; // type string expected object - For what? the _array or typeOf?

 

Anyhow no luck. I finally found out how to select all flag poles by 'Type' and I tried to implement that above with soldier types for the spotter but no luck either.

 

_types = ["Flag_AAF_F","Flag_NATO_F","Flag_White_F"];
_poles = allMissionObjects "all" select {typeOf _x in _types};

 

I want to do similar but for specific soldiers in groups.

 

Cheers.

Share this post


Link to post
Share on other sites

Mmmmmmm, kinda on the right track:

 

_sniper = ((units _grp) select {typeOf _x == "I_Sniper_F"}) select 0;
_spotter = ((units _grp) select {typeOf _x == "I_Spotter_F"}) select 0;

Using select in this case (Alternative Syntax 5) returns an array containing all units in the group that match the given type ("I_Sniper_F" or "I_Spotter_F"). Using select 0 just returns the first unit in that array (or the only unit if the array has just one unit in it).

  • Like 1

Share this post


Link to post
Share on other sites

Thx Beno that worked nicely.

 

If there was more than one of the same type (say 4 spotters) can I use rand in addition to select 0,1,2 or 3?

e.g

_spotter = ((units _grp) select {typeOf _x == "I_Spotter_F"}) select rand;

or more like...

_spotter = ((units _grp) select {typeOf _x == "I_Spotter_F"}) selectRandom;

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  

×