26.08.2014, 17:54
For some reason, even being in spectate mode, or on admin duty, I keep getting messages that I was the closest player.
If ANYONE has a better get closest player script, that actually works. feel free to post it.
pawn Код:
public GetClosestPlayerToPlayer(playerid)
{
new Float:dist = 10.0;
new targetid = -1;
new Float:x1,Float:y1,Float:z1;
new Float:x2,Float:y2,Float:z2;
new Float:tmpdis;
GetPlayerPos(playerid,x1,y1,z1);
for(new i=0;i<MAX_PLAYERS;i++)
{
if(i == INVALID_PLAYER_ID) continue;
if(i == playerid) continue;
if(!IsPlayerConnectedEx(i)) continue;
if(Spectator[i][SpecSpectatingPlayer] != -1) continue;
if(Player[i][AdminDuty] == 1) continue;
GetPlayerPos(i,x2,y2,z2);
tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
if(tmpdis < dist)
{
dist = tmpdis;
targetid = i;
}
}
return targetid;
}