Jump to content
Sign in to follow this  
hogmason

check distance of units in array from object

Recommended Posts

gday i have got an array built up of units that are spawned

_grp = [POW,POW1,POW2,POW3,POW4];

now im trying to get the distance of all alive units in that array to a flag pole named POW_safe.

im using this i get no errors but the task doesnt finish when all remaining units are 30 mtrs from the pole

	 if ({(_x distance POW_safe) <30} count _grp  == (count _grp)) then 
	   {
	     _POWs_rescued = true;
		 hint "all living POWs made it!";
         ["Task1","succeeded"] call SHK_Taskmaster_upd; 
         [] call SHK_addTask;
          };


i know the array is good as i use it for this code

      if (count _grp <3) then 
	   {

	    hint "Too many POWs died!";
        ["Task1","failed"] call SHK_Taskmaster_upd;
        [] call SHK_addTask;
	   _POWs_death_Limit = true;

          };

and all works fine if less then 3 units from the array are dead then the task does fail.

does any 1 know how i can make my distance check work with the array thanks.

Share this post


Link to post
Share on other sites

I put five units on the map, named them POW1-5 and placed an ammo box called POW_safe. I put this in init.sqf

_grp = [POW,POW1,POW2,POW3,POW4];
while {true} do 
{
{player sidechat format ["%1",(_x distance POW_safe)]}forEach _grp;
if ({(_x distance POW_safe) <30} count _grp  == (count _grp)) then 
{
	hint "all living POWs made it!";
};
sleep 0.5;
};

Works just fine. I get the hint when all of them are close enough to the box.

Edited by cuel

Share this post


Link to post
Share on other sites

can you test this for me mate please

note = at the end the 2 conditions dont work for me but when i change the 1st condition to > instead of < tat condition works ===strange====

//create POWS
//count alive POWs
if (isServer) then {

waituntil {!isnil "bis_fnc_init"};
_POWgrp = createGroup resistance;
_jail = getMarkerPos "jail";
if (isnil "POWs_rescued") then {POWs_rescued = 0;};    ///// set at begining
if (isnil "POWs_death_Limit") then {POWs_death_Limit = 0;};///// set at begining

POWs_rescued = 1; publicvariable "POWs_rescued";///// set to 1 at start
POWs_death_Limit = 1; publicvariable "POWs_death_Limit";///// set to 1 at start


  //create POWs 
     _POWman = ["UN_CDF_Soldier_AAT_EP1","UN_CDF_Soldier_AMG_EP1","UN_CDF_Soldier_Officer_EP1"] call BIS_fnc_selectRandom;  
  POW = _POWgrp createUnit [_POWman, _jail, [], 0, "FORM"];
     POW setcaptive true;
     POW setBehaviour "CARELESS";
     removeAllWeapons POW;
     POW call {[POW,20,3] execVM "missions\scripts\pow_positions.sqf"};	 
     POW setVehicleInit "this addAction ['Rescue Him!', 'missions\scripts\rescue.sqf'];";
     processInitCommands;



  //create POWs 
     _POW1man = ["UN_CDF_Soldier_AAT_EP1","UN_CDF_Soldier_AMG_EP1","UN_CDF_Soldier_Officer_EP1"] call BIS_fnc_selectRandom; 
  POW1 = _POWgrp createUnit [_POW1man, _jail, [], 0, "FORM"];
     POW1 setcaptive true;
     POW1 setBehaviour "CARELESS";
     removeAllWeapons POW1;
     POW1 call {[POW1,20,3] execVM "missions\scripts\pow_positions.sqf"};	 
     POW1 setVehicleInit "this addAction ['Rescue Him!', 'missions\scripts\rescue.sqf'];";
     processInitCommands;		  


  //create POWs 
     _POW2man = ["UN_CDF_Soldier_AAT_EP1","UN_CDF_Soldier_AMG_EP1","UN_CDF_Soldier_Officer_EP1"] call BIS_fnc_selectRandom; 
  POW2 = _POWgrp createUnit [_POW2man, _jail, [], 0, "FORM"];
     POW2 setcaptive true;
     POW2 setBehaviour "CARELESS";
     removeAllWeapons POW2;
     POW2 call {[POW2,20,3] execVM "missions\scripts\pow_positions.sqf"};	 
     POW2 setVehicleInit "this addAction ['Rescue Him!', 'missions\scripts\rescue.sqf'];";
     processInitCommands;



  //create POWs 
     _POW3man = ["UN_CDF_Soldier_AAT_EP1","UN_CDF_Soldier_AMG_EP1","UN_CDF_Soldier_Officer_EP1"] call BIS_fnc_selectRandom;    
  POW3 = _POWgrp createUnit [_POW3man, _jail, [], 0, "FORM"];
     POW3 setcaptive true;
     POW3 setBehaviour "CARELESS";
     removeAllWeapons POW3;
     POW3 call {[POW3,20,3] execVM "missions\scripts\pow_positions.sqf"};	 
     POW3 setVehicleInit "this addAction ['Rescue Him!', 'missions\scripts\rescue.sqf'];";
     processInitCommands;



  //create POWs 
     _POW4man = ["UN_CDF_Soldier_AAT_EP1","UN_CDF_Soldier_AMG_EP1","UN_CDF_Soldier_Officer_EP1"] call BIS_fnc_selectRandom;    
  POW4 = _POWgrp createUnit [_POW4man, _jail, [], 0, "FORM"];
     POW4 setcaptive true;
     POW4 setBehaviour "CARELESS";
     removeAllWeapons POW4;
     POW4 call {[POW4,20,3] execVM "missions\scripts\pow_positions.sqf"};	 
     POW4 setVehicleInit "this addAction ['Rescue Him!', 'missions\scripts\rescue.sqf'];";
     processInitCommands;

_grp = [POW,POW1,POW2,POW3,POW4];
   while{(POWs_death_Limit == 1)} do 
{


      if (count _grp < 3) then 
	   {
	    [sgt,nil,rgroupChat,"Too many POW's died!"] call RE;

	    POWs_death_Limit = 0; publicvariable "POWs_death_Limit";		   
          };

	   if ({(_x distance POW_safe) <30} count _grp  == (count _grp)) then 
	      {
	        POWs_rescued = 0; publicvariable "POWs_rescued";
		    hint "all living POWs made it!";

	        POWs_rescued = 0; publicvariable "POWs_rescued";				
             }

};



}; 




---------- Post added at 20:53 ---------- Previous post was at 20:30 ----------

that works but if 1 dies it doesnt

Share this post


Link to post
Share on other sites

I had to edit it a little but it works just fine.

if (isServer) then {
createcenter RESISTANCE;
_POWgrp = createGroup RESISTANCE;
_jail = getMarkerPos "jail";
if (isnil "POWs_rescued") then {POWs_rescued = 0;};    ///// set at begining
if (isnil "POWs_death_Limit") then {POWs_death_Limit = 0;};///// set at begining

POWs_rescued = 1; publicvariable "POWs_rescued";///// set to 1 at start
POWs_death_Limit = 1; publicvariable "POWs_death_Limit";///// set to 1 at start
//create POWs 
_POWman = ["UN_CDF_Soldier_AAT_EP1","UN_CDF_Soldier_AMG_EP1","UN_CDF_Soldier_Officer_EP1"] call BIS_fnc_selectRandom;  
POW = _POWgrp createUnit [_POWman, (markerPos "jail"), [], 0, "FORM"];
sleep 0.2;
// player setpos POW;
POW setcaptive true;
POW setBehaviour "CARELESS";
removeAllWeapons POW; 
POW setVehicleInit "this addAction ['Rescue Him!', 'rescue.sqf'];";

//create POWs 
_POW1man = ["UN_CDF_Soldier_AAT_EP1","UN_CDF_Soldier_AMG_EP1","UN_CDF_Soldier_Officer_EP1"] call BIS_fnc_selectRandom; 
POW1 = _POWgrp createUnit [_POW1man, _jail, [], 0, "FORM"];
sleep 0.2;
POW1 setcaptive true;
POW1 setBehaviour "CARELESS";
removeAllWeapons POW1;
POW1 setVehicleInit "this addAction ['Rescue Him!', 'rescue.sqf'];";

//create POWs 
_POW2man = ["UN_CDF_Soldier_AAT_EP1","UN_CDF_Soldier_AMG_EP1","UN_CDF_Soldier_Officer_EP1"] call BIS_fnc_selectRandom; 
POW2 = _POWgrp createUnit [_POW2man, _jail, [], 0, "FORM"];
sleep 0.2;
POW2 setcaptive true;
POW2 setBehaviour "CARELESS";
removeAllWeapons POW2; 
POW2 setVehicleInit "this addAction ['Rescue Him!', 'rescue.sqf'];";

//create POWs 
_POW3man = ["UN_CDF_Soldier_AAT_EP1","UN_CDF_Soldier_AMG_EP1","UN_CDF_Soldier_Officer_EP1"] call BIS_fnc_selectRandom;    
POW3 = _POWgrp createUnit [_POW3man, _jail, [], 0, "FORM"];
sleep 0.2;
POW3 setcaptive true;
POW3 setBehaviour "CARELESS";
removeAllWeapons POW3;
POW3 setVehicleInit "this addAction ['Rescue Him!', 'rescue.sqf'];";

//create POWs 
_POW4man = ["UN_CDF_Soldier_AAT_EP1","UN_CDF_Soldier_AMG_EP1","UN_CDF_Soldier_Officer_EP1"] call BIS_fnc_selectRandom;    
POW4 = _POWgrp createUnit [_POW4man, _jail, [], 0, "FORM"];
sleep 0.2;
POW4 setcaptive true;
POW4 setBehaviour "CARELESS";
removeAllWeapons POW4;
POW4 setVehicleInit "this addAction ['Rescue Him!', 'rescue.sqf'];";

sleep 1;
processInitCommands;

_grp = units _POWgrp;
while{(POWs_death_Limit == 1)} do 
{
	if (count _grp < 3) then 
	{
		[sgt,nil,rGroupChat,"Too many POW's died!"] call RE;
		POWs_death_Limit = 0; publicvariable "POWs_death_Limit";		   
	};

	if ({(_x distance POW_safe) <30} count _grp  == (count _grp)) then 
	{
		POWs_rescued = 0; publicvariable "POWs_rescued";
		hint "all living POWs made it!";		
	};

	{
		if (!alive _x) then {_grp = _grp - [_x]};
	}foreach _grp;
	sleep 1;
};
};

I don't understand why you're using call here :)

POW call {[POW,20,3] execVM "missions\scripts\pow_positions.sqf"};

Edited by cuel

Share this post


Link to post
Share on other sites

thanks mate works perfect lol ill also admit to a stupid foulup i did i just found that in the code my flag is called POW_safe but on the editor my flag is called POWsafe

Doh Doh Doh Doh

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  

×