[HELP] Closest AR/TK
#2

pawn Код:
new closestPlayer = -1, Float:closestDist = 3.5; //Set the closestDist to your range for later
for(new i = 0; i < MAX_PLAYERS; i++) // or the foreach loop, you should definitely use foreach if you can
{
    if(IsPlayerConnected(i) && i != playerid) //the connection check is included in the foreach loop, but you'd still have to check if "i" is equal to "playerid"
    {
        new Float:X, Float:Y, Float:Z, Float:distance;
        GetPlayerPos(i, X, Y, Z);
        distance = GetPlayerDistanceFromPoint(playerid, X, Y, Z);
        if(distance <= closestDist)
        {
            closestDist = distance; //you're setting the new minimum to the closestDist var
            closestPlayer = i; //you're saving the closest player id
        }
    }
}
if(closestPlayer != -1) //this means you found a player within your radius
{
    //do something here, check if he should get arrested or receive a ticket
}
Reply


Messages In This Thread
[HELP] Closest AR/TK - by Thoma - 17.01.2015, 14:50
Re: [HELP] Closest AR/TK - by HazardouS - 17.01.2015, 15:03
Re: [HELP] Closest AR/TK - by Thoma - 17.01.2015, 15:15

Forum Jump:


Users browsing this thread: 1 Guest(s)