Jump to content
Sign in to follow this  
galzohar

forEach over all units in a side?

Recommended Posts

How can I make a forEach run over all units in a given side (including manned but excluding unmanned vehicles)? I can see how I can get an array of all players in a group but how do I get all units (or all groups) in a side?

Share this post


Link to post
Share on other sites

make a really really big trigger, have it activated by the side of your choice

on Act: something = [thislist] execVM "myscript.sqf"

then create the "myscript.sqf"- script.

private ["_trgList","_listOfAllUnits","_iX"];
_trgList = _this select 0;
_listOfAllUnits = [];
_iX = 0;
{
   _obj = _x; //Fixed stuff...
   if((count crew _obj) > 0) then{
       //Is a vehicle
       {
           _listOfAllUnits set [_iX,_x];
       }forEach (crew _obj);
   }else{
           _listOfAllUnits set [_iX,_obj];
   };
_iX = _iX + 1;
}forEach _trgList;
//Do what you want with the list of units array "_listOfAllUnits"
....

Untested but it should work.

Edited by Taurus

Share this post


Link to post
Share on other sites

Actually there is absolutely no need for a trigger and to be on the safe side (and be sure to really catch all) you probably should better make a call to allUnits. I can imagine this command will be faster than any trigger anyway, since the units ingame are probably already neatly stored there somewhere in a nice list...

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

Share this post


Link to post
Share on other sites

Sry to be a dum dum, but what is an agent?

Description:

Return a list of all units (all persons except agents).

Share this post


Link to post
Share on other sites

Looking at the wiki (under agent and agents values) doesn't really say much about what an agent actually is either...

Share this post


Link to post
Share on other sites

As I understand agents are basically dumbed down units. In practice you want to use createAgent to spawn all sorts of animals. And now that I think of it, could it be that you could use agents for soldiers as a base to build your own FSM upon it? You know, so the hardcoded FSM doesn't kick in? mh...

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  

×