Thread: Nearest player
View Single Post
Old 27/07/2011, 07:11 AM   #3
MyLife
Big Clucker
 
Join Date: Mar 2010
Posts: 79
Reputation: 2
Default Re: Nearest player

pawn Code:
stock GetClosestPlayer(p1)
{
    new x,Float:dis,Float:dis2,player;
    player = -1;
    dis = 99999.99;
    for (x=0;x<MAX_PLAYERS;x++)
    {
        if(IsPlayerConnected(x))
        {
            if(x != p1)
            {
                dis2 = GetDistanceBetweenPlayers(x,p1);
                if(dis2 < dis && dis2 != -1.00)
                {
                    dis = dis2;
                    player = x;
                }
            }
        }
    }
    return player;
}
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
new vm = GetClosestPlayer(playerid);
new Float:xyz[3];
GetPlayerPos(vm,xyz[0],xyz[1],xyz[2]);
if(IsPlayerInRangeOfPoint(playerid,2.0,xyz[0],xyz[1],xyz[2]))
{
...... TogglePlayerControllable(vm,0) ; ..........
}
}

^_^
MyLife is offline