optimize code
#2

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

PHP Code:
public PlacaVeiculoPerto(playerid)
{
    new 
Float:distance 10.0FloatcurrentDistance 11.0vehicleid 0Pos[3];
    for( new 
iMAX_VEHICLESi++) {
        
GetVehiclePos(iPos[0], Pos[1], Pos[2]);
        
currentDistance GetPlayerDistanceFromPoint(playeridPos[0], Pos[1], Pos[2]);
        if(
currentDistance <= 7.0 && currentDistance distance) {
            
vehicleid i;
            
distance currentDistance;
        }
    }
   
    return 
vehicleid;

Reply


Messages In This Thread
optimize code - by JoshNudock - 22.06.2015, 14:21
Re: optimize code - by CoaPsyFactor - 22.06.2015, 14:32
Re: optimize code - by JoshNudock - 22.06.2015, 19:33
AW: optimize code - by Mencent - 22.06.2015, 19:34
Re: AW: optimize code - by JoshNudock - 22.06.2015, 19:38

Forum Jump:


Users browsing this thread: 1 Guest(s)