Jump to content
Sign in to follow this  
GieNkoV

Distance to object

Recommended Posts

So basically i want to know distance from player to an IED, and so if player speed > 7 and player distance to IED < _dist then BOOM. Code works good for driving a vehicle (explosion), shooting IED (explosion) but it dont detect a player. So now I got this:

if (((speed nearestObject [_IED])>7) and ((((nearestObject [_IED]) distance _IED)<_dist))) then
{
boomcode
}

This is the only part of the code that doesnt work.

And it does not want to work (it has to work on dedicated server). I tried using player distance _IED but it doesnt work too. Anyone can help me?

Share this post


Link to post
Share on other sites

Still cannot get it to work.

EDIT: Made it working. Can close thread.

---------- Post added at 23:10 ---------- Previous post was at 21:22 ----------

I forgot I was testing my code on ingame hosted server, not dedicated server, so I still have problem with making this code working. I will paste here all what I have written and all of this IS WORKING on ingame hosted server, but detecting player doesnt works on dedicated.

_isIED={
 _IED=_this select 0;
 _IED setvariable ["_IEDEnabled",true,true];
 _loop=true;
 _dist=10+random(15);
 while {(!isnull _IED) and (_IED getvariable "_IEDEnabled") and (_loop)} do
 {

   {
      if !(isnull _x) then
      {
		if (({(speed _x)>7 && (_x distance _IED)<_dist} count allUnits) > 0) then
			{
				[_IED] call _isIEDExplosion;
				_loop=false;
			};
		if ((speed vehicle _x)>7 and (((vehicle _x) distance _IED)<_dist )) then
			{
				[_IED] call _isIEDExplosion;
				_loop=false;
			};
		if ((damage _IED)>0.05) then
			{
				[_IED] call _isIEDExplosion;
				_loop=false;
			};
     };
   } foreach allUnits;
 sleep 1;
 };

};

Edited by gienkov

Share this post


Link to post
Share on other sites

you dont need ({(speed _x)>7 && (_x distance _IED)<_dist} count allUnits) > 0

you are doing it for every unit anyway because of foreach loop

(speed _x)>7 && (_x distance _IED)<_dist

is enough but you don't need this either because this:

(speed vehicle _x)>7 and (((vehicle _x) distance _IED)<_dist //one bracket too many?

will take care of both players on foot and in vehicles

also try playableUnits instead of allUnits on the dedi.

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  

×