PDA

View Full Version : Find the shortest path to the player.



Moczulak
29th October 2013, 20:39
Hey.
Which to use function to check distances between players?
I would like to check on a regular basis that the player is closer to me.

I must use BulletTrace function?

kung foo man
29th October 2013, 21:13
It's like:




players = getentarray("player", "classname");
playerNearestDistance = 9999999999;
playerNearest = undefined;
for (i=0; i<players.size; i++)
{
if (self == players[i])
continue;
distanceToThis = distancesquared(players[i].origin, self.origin);
if (distanceToThis < playerNearestDistance)
{
playerNearestDistance = distanceToThis;
playerNearest = players[i];
}
}

if (isDefined(playerNearest))
iprintln("found the nearest player: ", playerNearest.origin, " id: ", playerNearest getEntityNumber());
else
iprintln("no near player");

Moczulak
29th October 2013, 21:40
Thanks :) It works :P

IzNoGoD
30th October 2013, 00:06
Kung, use isdefined(playerNearest) instead of playerNearest.