damian123

26/09/2013, 03:44 PM

stock GetClosestCar(playerid, exception = INVALID_VEHICLE_ID) {

new

Float: Distance,

target = -1,

Float: vPos[3];

if(!IsPlayerInAnyVehicle(playerid)) GetPlayerPos(playerid, vPos[0], vPos[1], vPos[2]);

else GetVehiclePos(GetPlayerVehicleID(playerid), vPos[0], vPos[1], vPos[2]);

for(new v; v < MAX_VEHICLES; v++) if(GetVehicleModel(v) >= 400) {

if(v != exception && (target < 0 || Distance > GetDistanceToCar(playerid, v, vPos[0], vPos[1], vPos[2]))) {

target = v;

Distance = GetDistanceToCar(playerid, v, vPos[0], vPos[1], vPos[2]); // Before the rewrite, we'd be running GetPlayerPos 2000 times...

}

}

return target;

}

new

Float: Distance,

target = -1,

Float: vPos[3];

if(!IsPlayerInAnyVehicle(playerid)) GetPlayerPos(playerid, vPos[0], vPos[1], vPos[2]);

else GetVehiclePos(GetPlayerVehicleID(playerid), vPos[0], vPos[1], vPos[2]);

for(new v; v < MAX_VEHICLES; v++) if(GetVehicleModel(v) >= 400) {

if(v != exception && (target < 0 || Distance > GetDistanceToCar(playerid, v, vPos[0], vPos[1], vPos[2]))) {

target = v;

Distance = GetDistanceToCar(playerid, v, vPos[0], vPos[1], vPos[2]); // Before the rewrite, we'd be running GetPlayerPos 2000 times...

}

}

return target;

}