View Single Post
  #9  
Old 05-28-2012, 10:31 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Quote:
Originally Posted by greggiles View Post
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.xthis.y);
if (
temp.pl.x in this.5this.| && temp.pl.y in this.5this.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.xplayer.x}, {this.yplayer.y});

if (
temp.distance this.max_distance) {
  return;

Reply With Quote