PDA

View Full Version : Getting the Nearest Player


XiLe
05-06-2004, 11:46 PM
Someone told me that if I used "with (getnearestplayer)" it'd find the player closest to active character... I found out obviously that it's not true... I'm trying to make a weapon spell for Maloria and having a hard time doing this the way the owner wants it, where it just finds the nearest person in the level and executes commands... anyone know a way I can get the nearest player?

Python523
05-07-2004, 12:00 AM
var = getnearestplayer(x,y) (serverside.)

xManiamaNx
05-07-2004, 02:41 AM
pid=getnearestplayer(x,y);
with (getplayer(#a(pid))) dostuff();

R0bin
05-07-2004, 12:28 PM
thers a getnearestplayers too i think.. returns near players in an array?

Dach
05-07-2004, 01:46 PM
yes, and a getnearestnpc(s?) I have them all in me commands

osrs
05-07-2004, 01:49 PM
If you read Stefan's hp document, it explains that:


function attackplayers() {
pid = playerid;
pindexes = getnearestplayers(this.attackx,this.attacky,player id!=pid);
dist = 0;
for (i=0; i<arraylen(pindexes); i++) {
with (players[pindexes[i]]) {
dx = playerx + 1.5 - this.attackx;
dy = playery + 2 - this.attacky;
dist = (dx*dx + dy*dy)^0.5;
if (dist<=2)
hurtplayer();
}
if (dist>2)
break;
}
}
function hurtplayer() {
newhp = strtofloat(#s(clientr.hp)) - this.attackpower;
if (newhp<=0) {
newhp = 3;
setani dead,;
} else {
setani hurt,;
}
setstring clientr.hp,#v(newhp);
}

The script uses the function getnearestplayers(x,y,condition)
to find the near players. The function gives an array
of player indexes, starting with the index of the nearest player.
By using the script command 'with' you can then manipulate
those players directly. Instead of changing the hitpoints of
the attacker, you will so change the variables of the
victim. The function hurtplayer() is setting an animation
and updating the string variable 'clientr.hp'.

Lance
05-07-2004, 11:09 PM
with (getplayer(#a(pid)))

with(players[pid])

R0bin
05-08-2004, 06:03 PM
and getareanpcs(x,y,width,height);