nearest player
#5

Here we go.

pawn Код:
#define COLOR_WHITE 0xFFFFFFAA

new Float:DistanceFromPlayer[MAX_PLAYERS];
new ThePlayer[MAX_PLAYERS];
new GotFirstDistance[MAX_PLAYERS];

/yourcommandhere

for(new i = 0; i < MAX_PLAYERS; i++)
{
    if(IsPlayerConnected(i))
    {
        new Float:pX, Float:pY, Float:pZ;
        GetPlayerPos(i, pX, pY, pZ);
       
        new Distance = GetPlayerDistanceFromPoint(playerid, pX, pY, pZ);
       
        if(GotFirstDistance[playerid] != 1)
        {
            DistanceFromPlayer[playerid] = Distance;
            ThePlayer[playerid] = i;
            GotFirstDistance[playerid] = 1;
        }
        else
        {
            if(Distance < DistanceFromPlayer[playerid])
            {
                DistanceFromPlayer[playerid] = Distance;
                ThePlayer[playerid] = i;
            }
            if(i == MAX_PLAYERS)
            {
                if(Distance < DistanceFromPlayer[playerid])
                {
                    new string[128];
                   
                    DistanceFromPlayer[playerid] = Distance;
                    ThePlayer[playerid] = i;
                   
                    new Player = ThePlayer[playerid];
                   
                    format(string, sizeof(string), "You are %0.2fm away from %s", DistanceFromPlayer[playerid], GetPlayerNameEx(Player));
                    SendClientMessage(playerid, COLOR_WHITE, string);
                }
                else
                {
                    new string[128];
                   
                    format(string, sizeof(string), "You are %0.2fm away from %s", DistanceFromPlayer[playerid], GetPlayerNameEx(Player));
                    SendClientMessage(playerid, COLOR_WHITE, string);
                }
            }
        }
    }
}
                   
//GET PLAYER NAME
stock GetPlayerNameEx(playerid)
{
    new PlayerName[24];
    GetPlayerName(playerid, PlayerName, 24);
    new string[24];
    strmid(string, PlayerName, 0, strlen(PlayerName), 24);
    return string;
}
Reply


Messages In This Thread
nearest player - by suni - 19.06.2015, 23:43
Re: nearest player - by JaydenJason - 20.06.2015, 00:49
Re: nearest player - by suni - 20.06.2015, 02:11
Re: nearest player - by SickAttack - 20.06.2015, 02:32
Re: nearest player - by FarTooBaked - 20.06.2015, 06:34
Re: nearest player - by suni - 20.06.2015, 21:42
Re: nearest player - by Crayder - 21.06.2015, 03:50
Re: nearest player - by SickAttack - 21.06.2015, 04:43

Forum Jump:


Users browsing this thread: 2 Guest(s)