Change /Rob <ID> into /Rob (GetClosestPlayer)
#4

Well, this was just my shot at it :S
If you're using a team based gamemode, I would recommend you do team checks to make sure a player isn't robbing someone of the same team (excluding civilians for example)...

pawn Код:
stock GetClosestPlayer(playerid)
{
    new closestplayer = INVALID_PLAYER_ID;
    new Float:closex, Float:closey, Float:closez;
    for(new i = 0; i < MAX_PLAYERS; i++) //Foreach is better
    {
        if(IsPlayerConnected(i))
        {
            if(i == playerid) continue;
            //if(Team[i] == Team[playerid]) continue; //Recommended if you're going to use this for a /rob command
            new Float:X, Float:Y, Float:Z;
            GetPlayerPos(i, X, Y, Z);
            if(closestplayer == INVALID_PLAYER_ID)
            {
                closestplayer = i;
                closex = X;
                closey = Y;
                closez = Z;
            }
            else
            {
                if(GetPlayerDistanceFromPoint(playerid, X, Y, Z) < GetPlayerDistanceFromPoint(playerid, closex, closey, closez))
                {
                    closestplayer = i;
                    closex = X;
                    closey = Y;
                    closez = Z;
                }
            }
        }
    }
    return closestplayer;
}
Should honestly work...
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 4 Guest(s)