SA-MP Forums Archive
[HELP] Closest AR/TK - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [HELP] Closest AR/TK (/showthread.php?tid=558506)



[HELP] Closest AR/TK - Thoma - 17.01.2015

How would i make the /arrest and /ticket commands find the closest player that's wanted or ticket able while being in an 3.5 range


Re: [HELP] Closest AR/TK - HazardouS - 17.01.2015

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
}



Re: [HELP] Closest AR/TK - Thoma - 17.01.2015

Thank you!