Jump to content
punderland

Loop through all groups of the same side

Recommended Posts

Is there a way to loop through all groups on the field to select them all? 

 

I am trying to combine spawn ai with high command so that I can select groups spawned and add them to high command in a sector control game to allow more strategy elements. 

 

Also,  is it possible to make that certain units death can shut down high command function of one side? 

Share this post


Link to post
Share on other sites

forEach is your friend here.

 

Try something like

{ ...code } forEach allUnits side EAST;

I am not 100% sure if this works. If not you use this.

{
  if ((side _x) == West) then
  {
     code
  };
} forEach allUnits;

 

  • Thanks 1

Share this post


Link to post
Share on other sites

To select groups of a specific side:

_selection = allGroups select {side _x isEqualTo east};//returns all east groups

 

1 hour ago, punderland said:

Also,  is it possible to make that certain units death can shut down high command function of one side? 

 

Depends on how you want to do it, killed eventhandler on a certain unit would work most reliable, together with hcRemoveAllGroups on the high commander.

 

Cheers

  • Thanks 2

Share this post


Link to post
Share on other sites
14 minutes ago, Grumpy Old Man said:

No need to loop, when the select command can do the same.

 

Cheers

On a side note,  if there is anyway for spawn ai to spawn cup/rhs units and for them to get sector tactics module way point also? 

 

And many thanks for the help,  really appreciate! 

Share this post


Link to post
Share on other sites
1 hour ago, punderland said:

On a side note,  if there is anyway for spawn ai to spawn cup/rhs units and for them to get sector tactics module way point also? 

 

And many thanks for the help,  really appreciate! 

You'd probably need to spawn another module or sync the spawned groups to the existing module somehow.

No idea if the module will handle them correctly when syncing a new group during mission runtime.

I'm not even sure if synchronizeObjectsAdd is the correct command for this.

 

Cheers

Share this post


Link to post
Share on other sites

Now that I try to script it, I put 

 

Quote

_selection=[]; _selection=allGroups select {side _x isEqualTo west};

kommand_west hcSetGroup [_selection];  

where kommand_west is the unit for high command and _selection is to try to select all groups. It cites error of local variable n global scope. Why??? :((

Share this post


Link to post
Share on other sites
0 = [] spawn {
  while {true} do {
    {   _grp = _x;
        _grp setVariable ["marked",true];

       < any code with _grp here:
       _grp addWaypoint [getpos myModule,0]; // and setwaypoint... family: fast , combat mode....
       komman_west hcSetGroup [_grp];
        other lines >

    } foreach (allGroups select { side _x == West && !(_x getVariable ["marked",false]) )
    sleep 3;
  }
};

 

  • Like 1

Share this post


Link to post
Share on other sites
10 hours ago, pierremgi said:

_grp setVariable ["marked",true];

What is this for???

 

10 hours ago, pierremgi said:

0 = [] spawn { while {true} do {

And why I need this??

 

I didnt learn scripting in ARMA much....only little scripting knowledge of this language....pls help :)

Share this post


Link to post
Share on other sites

It's useful if you spawn units (new groups via scripts/triggers...) The loop ( while true do +sleep) checks for new group(s) (every 3 seconds here). As a new group hasn't a variable "marked" (or what you want) yet, the selection works (variable is false per default here), and you can script for this group(s) . The old ones have their variables set to true and are skipped for this selection.

See more at setVariable. It's very useful to determine units or groups already treated by a code. 

 

  • Like 1

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

×