Quote:
Originally Posted by greggiles
is there a code for finding the nearest player?
|
findnearestplayer(x, y);
findnearestplayers(x, y);
There isn't a range though, so it doesn't matter how far away the player is, as long as they're closest to the NPC then they'll be picked up. You can get around it by doing:
PHP Code:
temp.pl = findnearestplayer(this.x, this.y);
if (temp.pl.x in | this.x - 5, this.x + 5 | && temp.pl.y in | this.y - 5, this.y + 5|) {
temp.pl.chat = "I'm the nearest player!";
}
You could also calculate the distance from the player to the NPC, and set a maximum distance.
PHP Code:
this.max_distance = 10;
temp.distance = vectordist({this.x, player.x}, {this.y, player.y});
if (temp.distance > this.max_distance) {
return;
}