22.06.2015, 14:32
well, you should not return on IsPlayerInRange of point, but instead save in variable distance and vehicle id and continue with loop, when you get to another vehicle that is in radius check distance again and compare it with last one, if it is smaller than update variable with vehicle id and variable with distance to new values.
And after that return vehicle id out of loop.
something like this
And after that return vehicle id out of loop.
something like this
PHP Code:
public PlacaVeiculoPerto(playerid)
{
new Float:distance = 10.0, Float: currentDistance = 11.0, vehicleid = 0, Pos[3];
for( new i; i < MAX_VEHICLES; i++) {
GetVehiclePos(i, Pos[0], Pos[1], Pos[2]);
currentDistance = GetPlayerDistanceFromPoint(playerid, Pos[0], Pos[1], Pos[2]);
if(currentDistance <= 7.0 && currentDistance < distance) {
vehicleid = i;
distance = currentDistance;
}
}
return vehicleid;
}