Jump to content
Sign in to follow this  
meatball

Check Respawn Point for Nearby Enemies?

Recommended Posts

I've created a simple script to move a player to a random point within 250m of where they died when they respawn, but I'm finding on occasion that they respawn right next to some enemy. Anyone have any idea of a simple way to tweak it so it'll check to make sure that there's no enemy near that point? The players are side EAST, so anyone not EAST should force it to check for a new spot. Here's the base script I have:

_posCurrent = _this select 0;
_posNeg = random(1);
if (_posNeg > 0.5) then {_posNeg = 1} else {_posNeg = -1};
_x = _posCurrent select 0;
_y = _posCurrent select 1;

_tmpPos = [_x+(_posNeg*(250+(random 250))),_y+(_posNeg*(250+(random 250))),0];
   while {surfaceiswater _tmpPos} do {
_posNeg = random(1);
if (_posNeg > 0.5) then {_posNeg = 1} else {_posNeg = -1};
_tmpPos = [_x+(_posNeg*(250+(random 250))),_y+(_posNeg*(250+(random 250))),0];
};

player setPos _tmpPos;

Thanks in advance!

Share this post


Link to post
Share on other sites

Assuming you don't want enemies in a 250mts radius from the spawnpoint:

while {(surfaceIsWater _tmpPos) and ({(side _x != EAST) and (_x distance _tmpPos < 250)} count allUnits > 0)} do....

But a more reliable and efficient way. Don't define _tmpPos before the while and:

while {true} do

{

_tmpPos = [_posCurrent,250,random 360] call BIS_fnc_relPos;

if ((!surfaceIsWater _tmpPos) and ({(side _x != EAST) and (_x distance _tmpPos < 250)} count allUnits == 0)) exitWith {};

sleep 1;

};

player setPos _tmpPos;

Or even better, to avoid in a crowded battlefield having the while loop looping eternally:

_dist = 250;

while {true} do

{

_tmpPos = [_posCurrent,250,random 360] call BIS_fnc_relPos;

if ((!surfaceIsWater _tmpPos) and ({(side _x != EAST) and (_x distance _tmpPos < 250)} count allUnits == 0)) exitWith {};

_dist = _dist + 100;

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  

×