Jump to content
FederalRazer89

Getting waypoint infromation for other groups

Recommended Posts

Hello

I am trying to make a function that make helicopters transport random groups to there waypoints unless they are close to the the groups waypoint (500 m). I got this to work and the helicopters transported the random AI groups to there respective destinations, but sometimes they will fly to coordinates [0,0,0] and this happens at random. It unpredictible and i have tried to make a check that compare the waypoints to [0,0,0] but that dosent solve it.
So i am wondering if there is a way to attach som locations variables to the group and when the helicopter function choses a group it can extract that variable or if there is a more reliable way to get another groups waypoint position?

The function is kind of butchered when i was trying to solve this so i will rewrite it when i get a more reliable way to handle this, but included it if someone is interested.

After work i might try and use arrays to try and solve this problem.
 

_Newpos  = waypointPosition [_randomUnit,1];   <--------------this is how i get the units waypoint position. And sometimes it 

-----------------------------------------------Cut----------------------------------------------------------------------------
 
      _biglist   = _veh nearEntities ["man",5000];    <---------------------- this is how i get a random unit.
        _SmallList = []; 
        for "_i" from 0 to ((count _biglist) - 1) do 
             {

                 if (side (_biglist select _i) == west) then 
                 {
                     _SmallList pushBack (_biglist select _i);
                 
                 
                 };

             };
            
                  
        _SmallList = _SmallList apply {[_x distance _veh, _x] };
        _SmallList sort true;
        
        _randomUnit   = group ((_SmallList select 0) select 1);  <---------------------- this is how i get the group that the random unit is assigned to.



The Complete function:
 

Spoiler

 

fn_VehicleControlAir = {

    _Array  = _this select 0;
    _side   = _this select 1;
    _grp    = _Array select 2;
    _veh    = _Array select 0;

    _loaded  = 0;
    _homepos = getPos WestSide_OfficerLeader;
    if (_side == west) then {NATO_HeliCount   = NATO_HeliCount + 1};
    if (_side == east) then {CSAT_HeliCount   = CSAT_HeliCount + 1};
    _exitvalue = 0;
    while {true} do 
    {
    _grpCount = count units _grp;
    if (side _grp == west) then {if (_grpCount <= 1) then {_exitvalue = 1; NATO_HeliCount = NATO_HeliCount - 1}};
    if (side _grp == east) then {if (_grpCount <= 1) then {_exitvalue = 1; CSAT_HeliCount = CSAT_HeliCount - 1}};
    
    
    
    _veh nearEntities ["man",5000];
    
    if (_loaded == 0) then 
        {
    
        _biglist   = _veh nearEntities ["man",5000];
        _SmallList = []; 
        for "_i" from 0 to ((count _biglist) - 1) do 
             {

                 if (side (_biglist select _i) == west) then 
                 {
                     _SmallList pushBack (_biglist select _i);
                 
                 
                 };

             };
            
                  
        _SmallList = _SmallList apply {[_x distance _veh, _x] };
        _SmallList sort true;
        
        _randomUnit   = group ((_SmallList select 0) select 1);
        _officercount = 0;

        if ((typeOf (leader _randomUnit))  == "B_officer_F") then {_officercount = 1;_randomUnit = group((_SmallList call BIS_fnc_selectRandom) select 1)};
        if ((typeOf (leader _randomUnit))  == "B_officer_F") then {_officercount = 2;_randomUnit = group((_SmallList call BIS_fnc_selectRandom) select 1)};
        if ((typeOf (leader _randomUnit))  == "B_officer_F") then {_officercount = 3;_randomUnit = group((_SmallList call BIS_fnc_selectRandom) select 1)};
        

        if (_officercount == 3) exitWith {};
        _CheckVehAcess = count assignedVehicleRole (leader _randomUnit);
        if (_CheckVehAcess >= 1) exitWith {};
        if ((leader _randomUnit) == player) then {_randomUnit = group ((_SmallList call BIS_fnc_selectRandom) select 1)};
        if ((leader _randomUnit) == player) then {_randomUnit = group ((_SmallList call BIS_fnc_selectRandom) select 1)};
        if ((leader _randomUnit) == player) exitWith {};

        _countwaypoints = count (waypoints _grp);
        if (_countwaypoints == 0) exitWith {};

        _Newpos  = waypointPosition [_randomUnit,1];
        _Unitpos = getpos (leader _randomUnit);
        if ((_Newpos distance _Unitpos) <= 500) exitWith {};
        

        _wpget = _grp addWaypoint [_Unitpos,10];
        _wp    = _grp addWaypoint [_Newpos,200];
        sleep 1;
        
 

        _UnitCount  = count units _randomUnit; 
        _loaded     = 1;
        _travleTime = time + 100;
        _timeExtend = time + 300;
        while {true} do
            {
                _NewUnitpos = getpos (leader _randomUnit);       
                _UnitCount  = count units _randomUnit;
                if ((_Newpos distance _NewUnitpos) <= 500) exitWith {_loaded = 0};
                if (_UnitCount == 0) exitWith {_loaded = 0};
                if ((_veh distance (leader _randomUnit)) <= 200) exitWith {};
                if (time > _travleTime) then {_wpget2 = _grp addWaypoint [_Unitpos,10]};
                if (time > _timeExtend) then {_wpget3 = _grp addWaypoint [_Unitpos,10]};
                
                sleep 1;
            };
            if (_loaded == 0) exitWith {};
            if (_UnitCount == 0) exitWith {_loaded == 0};
        _wp    = _grp addWaypoint [_Newpos,200];
        


        {_x assignAsCargo _veh} forEach units _randomUnit;
        {[_x] orderGetIn true}  forEach units _randomUnit;

        while {true} do 
        {
        
        if (((getpos (leader _randomUnit)) distance _veh) <=100) then 
            {
                {_x assignAsCargo _veh} forEach units _randomUnit;
                {[_x] orderGetIn true}  forEach units _randomUnit;
                while {true} do 
                {
                
                    if (vehicle player != (leader _randomUnit)) exitWith {sleep 20};
            
                    sleep 10;
                };
            };
        {_x assignAsCargo _veh} forEach units _randomUnit;
        {[_x] orderGetIn true}  forEach units _randomUnit;
        if (vehicle player != (leader _randomUnit)) exitWith {sleep 10};
            
        sleep 10;
        };
    

       hint format ["%1",_Newpos];      <------------------------------------------------------------------------------------- around here that the _Newpos gets coordinates [0,0,0]

        sleep 10;
        while {true} do
            {
            _UnitCount = count units _randomUnit;    
            if ((_veh distance _Newpos) <= 700) then 
                                                            {
                                                            {unassignVehicle _x} forEach units _randomUnit;
                                                            {[_x] orderGetIn false} forEach units _randomUnit;
                                                            _veh land "land";
                                                            
                                                            
                                                            };
           
            if (isTouchingGround _veh) exitWith {{unassignVehicle _x} forEach units _randomUnit;{[_x] orderGetIn false} forEach units _randomUnit};
            if (_UnitCount == 0) exitWith {};
            sleep 30;
            };
        _wp = _grp addWaypoint [(getPos WestSide_OfficerLeader),1];
            _loaded = 0;
        
        _Newpos = waypointPosition [_randomUnit,0]; [_grp, 0] setWPPos _Newpos;
        _Newpos = waypointPosition [_randomUnit,1]; [_grp, 1] setWPPos _Newpos;
        _Newpos = waypointPosition [_randomUnit,2]; [_grp, 2] setWPPos _Newpos;
        _Newpos = waypointPosition [_randomUnit,3]; [_grp, 3] setWPPos _Newpos;
    
        };
    
    
    
    
    if ((count (assignedCargo _veh)) == 0) then {_loaded = 0};
    
    if (((waypointPosition [_grp,1]) distance [0,0,0]) <= 150) then {_wpStart  = waypointPosition [_grp,1];[_grp, 1] setWPPos _wpStart};

    
    
    
    
    
    if (_exitvalue == 1) exitWith {};
    sleep 20;
    };
  
};

 


 

Share this post


Link to post
Share on other sites

there are so much improvements to do!

So, to start,  _biglist   = _veh nearEntities ["man",5000];  will return also rabbits and snakes! Tooo much CPU demanding

consider instead:

_bigList = (allunits select {_veh distance _x < 5000}) - crew _veh ; // faster if you drop the  filter and use allUnits only

_smallList = _bigList select {side _x == West};

 

if you sort by distance, you don't randomize!

 

_randomUnit = selectRandom _smallList;

_grp = group _randomUnit;

Share this post


Link to post
Share on other sites

Didnt notice any preformance drop when i added the functions, but i will implement them. Thanks.

I sort by distance to get the closest group and then i test the group if the leader is a player or an officer. If they are then it will chose another group at random.

Share this post


Link to post
Share on other sites

I solved my problem with a global array that i added the groups and the locations. But is there anyway to sort an array by the time that it got added?

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

×