Jump to content
Sign in to follow this  
hogmason

check speed of player withing 5 mtrs of object

Recommended Posts

ok so i am trying to make some code run if the speed of a player within 5mtrs of an object is above a set speed

something like this i tried but diddnt work


_iedpos = _this select 0;// comes from a calling script
_spd = [0.5,0.8,1] call BIS_fnc_selectRandom;
_distance = _distance = [3,5,6,8,10] call BIS_fnc_selectRandom;


// before i go on the ESCORT_Units in the below if command is an of unit names found in my common.sqf

if (({(_x distance _iedpos) <_distance} count ESCORT_Units) > 0 && speed > _spd) then
{

// now my detonation script goes in here

};

Share this post


Link to post
Share on other sites

Maybe count ESCORT_Units again for the speed? Not sure if it kind of saves the count within the if-statement or not.

Share this post


Link to post
Share on other sites

_distance = _distance = [3,5,6,8,10] call BIS_fnc_selectRandom;

Why do you have two _distance local variables? Maybe I'm not understanding, or that's not supposed to be.

Also, I'm sure this won't work, but try this

(({(_x distance _iedpos) <_distance} count ESCORT_Units) > 0 && (_x speed > _spd))

Edited by Iceman77

Share this post


Link to post
Share on other sites

I'll have a shot at this for my first post ;)

private ["_iedpos","_spd","_distance","_cond","_dis","_speed"];

_iedpos = _this select 0;// comes from a calling script
_speed = [0.5,0.8,1] call BIS_fnc_selectRandom;
_distance = [3,5,6,8,10] call BIS_fnc_selectRandom;

_cond = false;

{
_dis = _x distance _iedpos;
_spd = speed _x;
   if ((_dis <= _distance) && (_spd >= _speed)) exitWith {_cond = true;};

} forEach ESCORT_Units;

if (_cond) then {
   //CODE HERE
};


havent tested this, hope it helps

Share this post


Link to post
Share on other sites

thanks for the replies guys got it working with this


if (({(_x distance _iedpos) <_distance && (speed _x) >2} count Player_Units) > 0) exitwith

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

iceman that extra _distance is a copy and past error ;)

just in case any 1 needs it in the future this is the full code

how i got it working

waituntil {!isnil "bis_fnc_init"};

   _iedpos = _this select 0; 
   while {true} do 
{	
   _wait = [0.2,1,2,4] call BIS_fnc_selectRandom;
   _distance = [3,5,6,8,10] call BIS_fnc_selectRandom;	

       if (({(_x distance _iedpos) <_distance && (speed _x) >2} count Player_Units) > 0) exitwith		
       { 	
           hint "FUCK IED RUN";// CHANGE TO PLAY A SOUND
            sleep _wait;			
		_bombtype = ["Sh_105_HE","BO_GBU12_LGB"] call BIS_fnc_selectRandom;
	     _bomb = _bombtype createVehicle position _iedpos;							
	      deletevehicle _iedpos;			  
       };		
	    if (HOG_debug) then 
        { 
             [player,nil,rsideChat,"IED detonate LOOP."] call RE;		
		}; 

    sleep 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
Sign in to follow this  

×