PDA

View Full Version : Closest player


Shred18
03-10-2005, 08:01 PM
I need some code to find the closest player to a thing, out of all the players in a multiplayer game. :)

Quib Mask
03-10-2005, 10:55 PM
Well, I'm 4 months out of practice, but something like the following should do the trick:
potential = 0;
victim = GetPlayerThing(0);
while(potential < GetNumPlayers())
{
if(VectorDist(GetThingPos(thisthing), GetThingPos(GetPlayerThing(potential))) < VectorDist(GetThingPos(thisthing), GetThingPos(victim))) victim = GetPlayerThing(potential);
potential = potential + 1;
}
"thisthing" is the thing you're checking the distance from.

QM

Shred18
03-11-2005, 02:12 AM
Thanks, it works great!! :D