Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → Closest player
Closest player
2005-03-10, 5:01 PM #1
I need some code to find the closest player to a thing, out of all the players in a multiplayer game. :)
Jedi Knight Enhanced
Freelance Illustrator
2005-03-10, 7:55 PM #2
Well, I'm 4 months out of practice, but something like the following should do the trick:
Code:
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
2005-03-10, 11:12 PM #3
Thanks, it works great!! :D
Jedi Knight Enhanced
Freelance Illustrator

↑ Up to the top!