09.12.2012, 10:34
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 );