getclosestplayer problem
#3

Hi Kar. You could try a different way of approaching it. Take a look at this function I quickly made up..


Код:
public GetClosestPlayer(playerid,Float:maxdis)
{
	new minid = -1;
	new Float:mindis;
	new Float:X, Float:Y, Float:Z;
	for(new i=0; i<MAX_PLAYERS; i++)
	{
	
	    if(IsPlayerConnected(i) && !IsPlayerNPC(i))
	    {
	    
			GetPlayerPos(i,X,Y,Z);
			if(IsPlayerInRangeOfPoint(playerid,maxdis,X,Y,Z))
			{
			
			    if(minid == -1) { minid = i; mindis = GetDistanceBetweenPlayers(playerid,i); }
			    else if(GetDistanceBetweenPlayers(playerid,i) < mindis) { minid = i; mindis = GetDistanceBetweenPlayers(playerid,i); }
			
			}
	    
	    }
	
	}
	return minid;
}
maxdis = The maximum possible distance between the players. If the function returns -1 there is noone within range. Give it a try.

Cheers,

TJ
Reply


Messages In This Thread
getclosestplayer problem - by Kar - 29.07.2010, 23:09
Re: getclosestplayer problem - by Kar - 30.07.2010, 03:06
Re: getclosestplayer problem - by TTJJ - 30.07.2010, 08:50

Forum Jump:


Users browsing this thread: 1 Guest(s)