whats wrong with this function?

thread says all. it always returning 0, instead of vehicleid or invalid_vehicle_id value

pawn Код:
stock GetClosestVehicle(playerid, Float: fRadius) // by RyDeR`
        iClosestID = INVALID_VEHICLE_ID,
        Float: fFinalDistance,
        Float: fDistance,
        Float: fX,
        Float: fY,
        Float: fZ;
    GetPlayerPos(playerid, fX, fY, fZ);
    fFinalDistance = fRadius;

    for(new i; i != Cars; ++i)
        if((fDistance = GetVehicleDistanceFromPoint(i, fX, fY, fZ)) < fFinalDistance)
            fFinalDistance = fDistance;
            iClosestID = i;
    return iClosestID;

If its from RyDeR, nothing because he is king at distances, unless you tweeked it... all I see that is weird is in the loop.

for(new i; i != Cars; ++i)

... try for(new i = 0; i < MAX_VEHICLES; i++)

Cars is value of created vehicles, its the same. Instead of loop 2000 vehicles, when ~200 is created Im looping created vehicles only (200)

Then try,

for(new i = 0; i < (Cars + 1); i++)

because the != will make it loop to infinity -.-

Forum Jump:

Users browsing this thread: 1 Guest(s)