nearest Player
#2

pawn Код:
#define GetDistanceBetweenCoords(%1,%2,%3,%4,%5,%6) floatsqroot((%4 - %1)*(%4 - %1) + (%5 - %2)*(%5 - %2) + (%6 - %3)*(%6 - %3))

stock GetPlayerClosestPlayer(playerid,bool:NPC = true)
{
    new pid = INVALID_PLAYER_ID,
        Float:distance = 8.0,
        Float:tmp[7];
    GetPlayerPos(playerid,tmp[0],tmp[1],tmp[2]);
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        if(i == playerid) continue;
        if(!IsPlayerConnected(i)) continue;
        if(NPC == false) if(IsPlayerNPC(i)) continue;
        GetPlayerPos(i,tmp[3],tmp[4],tmp[5]);
        tmp[6] = GetDistanceBetweenCoords(tmp[0],tmp[1],tmp[2],tmp[3],tmp[4],tmp[5]);
        if(distance < tmp[6]) continue;
        distance = tmp[6];
        pid = i;
    }
    return pid;
}

// Usage: GetPlayerClosestPlayer( playerid );
Reply


Messages In This Thread
nearest Player - by GoldZoroGrab - 09.12.2012, 10:29
Re: nearest Player - by Konstantinos - 09.12.2012, 10:34
Re: nearest Player - by GoldZoroGrab - 09.12.2012, 10:46
Re: nearest Player - by Konstantinos - 09.12.2012, 10:52

Forum Jump:


Users browsing this thread: 1 Guest(s)