Jump to content
Sign in to follow this  
iceman77

returning the distance from an object to any playable unit instead of player

Recommended Posts

This suicide bomber function will not work on dedicated server. I suspect it's because I'm trying to use player. How could I calculate the distance from any playable unit instead of player? Or, any west unit instead of player. Or.. maybe there's some other reason it's not working on dedicated?

IED_FNC = {

waitUntil {[color=#ff0000]_this select 0 distance player < 12[/color]};

      if (!alive (_this select 0)) exitWith {};

        if (!isServer) exitWith {};

           _position = _this select 0;
           _ied = ["Bo_FAB_250","Bo_GBU12_LGB"]call BIS_fnc_selectRandom;
           _explosion = _ied createVehicle getPos _position;
           deletevehicle _position;

  };


 {if (side _x == East) then {_x setVehicleInit "_nil = [this] spawn IED_FNC";processInitCommands} foreach allUnits;

---------- Post added at 01:00 ---------- Previous post was at 00:40 ----------

Solved: Used

waitUntil { { isPlayer _x && _x distance (_this select 0) < 12 } count playableunits > 0 };

Share this post


Link to post
Share on other sites
Or.. maybe there's some other reason it's not working on dedicated?

If it stops working when you put it on a server, you can be GUARANTEED that it's locality that's stopped it working. In this case, remember that there's no such thing as a player on a dedicated server.

Share this post


Link to post
Share on other sites

Get a list of units certain distance from the ied. Place them in an array. Select o as it should be the first/closest. If isplayer and side = west then explode. Check out fock suicide scripts. Fairly simple.

Share this post


Link to post
Share on other sites

This anygood? Turns all opfor into suicide bombers if they get within 10m of any blufor but I'm sure you could adapt it to suit your needs? Change allUnits to playableUnits for MP?

Adapted vigilante's post here: http://community.bistudio.com/wiki/nearestObjects

//init.sqf: []execVM "suicidebomber.sqf";

private ["_exclmArray","_exclm","_bomb","_fpos","_epos","_validNearestEnemy","_validNearestFriendlies"];
while {true} do{
   _validNearestEnemy = [];
   {if (alive _x && side _x == EAST) then {_validNearestEnemy set [(count _validNearestEnemy),_x];};
} foreach allUnits;

   _validNearestFriendlies = [];
   {if (alive _x && side _x == WEST) then {_validNearestFriendlies set [(count _validNearestFriendlies),_x];};
} foreach allUnits;

//player globalchat format ["E=%1",_validNearestEnemy];
//player sidechat format ["F=%1",_validNearestFriendlies];

for "_i" from 0 to (count _validNearestEnemy -1) do {
   _fpos = getPosATL (_validNearestFriendlies select floor(random (count _validNearestFriendlies)));
   _epos = getPosATL (_validNearestEnemy select _i);
     _foe = (_validNearestEnemy select _i);

if (_epos distance _fpos <= 10 && vehicle _foe == _foe) then {
   _dx = (_fpos select 0) - (_epos select 0);
     _dy = (_fpos select 1) - (_epos select 1);
       _dir = _dx atan2 _dy;
if (_dir < 0) then {_dir = _dir + 360};
sleep 0.1;

_foe setDir _dir;
 _foe switchmove "ActsPercMrunSlowWrflDf_FlipFlopPara";
   _foe setVelocity [(sin (getDir _foe))*10, (cos (getDir _foe))*10, 1];

_exclmArray = ["Ahh fuck! Suicide bomber!","BB-IED! Suicide bomber!", "Get back! Suicide bombers!"];
 _exclm = _exclmArray select floor (random (count _exclmArray));
   player globalchat _exclm;

sleep 0.1;
   _bomb = "R_57mm_HE" createVehicle _epos;
    };
  };
  sleep 1;
};

Edited by Mattar_Tharkari
added animation and code for a BBIED attack run towards the bluforAI or player, later edit: forgot -1 after count array

Share this post


Link to post
Share on other sites

waitUntil { { (_this select 0) distance _x < 12 } count (playableUnits + switchableUnits) > 0 };

Becomes true when a player or playable unit gets near (12m) of _this select 0.

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  

×