17.01.2015, 14:50
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
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
}