Custom function problem
#9

I guess GetVehicleDistanceFromPoint returns 0 if a vehicle doesn't exist so check if it does.

pawn Code:
GetClosestVehicle(playerid, Float: range)
{
    new
        vehicleid = INVALID_VEHICLE_ID,
        Float: pX,
        Float: pY,
        Float: pZ,
        Float: distance = 9999.0,
        Float: tmp_distance;
   
    GetPlayerPos(playerid, pX, pY, pZ);
 
    for (new v = 1; v != MAX_VEHICLES; ++v)
    {
        if (!GetVehicleModel(v)) continue;
        tmp_distance = GetVehicleDistanceFromPoint(v, pX, pY, pZ);
        if (tmp_distance <= range && tmp_distance < distance)
        {
            distance = tmp_distance;
            vehicleid = v;
        }
    }
    return vehicleid;
}
Reply


Messages In This Thread
Custom function problem - by moof2010 - 05.05.2014, 19:30
Re: Custom function problem - by Smileys - 05.05.2014, 19:39
Re: Custom function problem - by Vince - 05.05.2014, 19:48
Re: Custom function problem - by Teemo - 05.05.2014, 19:50
Re: Custom function problem - by Konstantinos - 05.05.2014, 19:51
Re: Custom function problem - by Smileys - 05.05.2014, 19:51
Re: Custom function problem - by moof2010 - 05.05.2014, 19:54
Re: Custom function problem - by moof2010 - 05.05.2014, 20:08
Re: Custom function problem - by Konstantinos - 05.05.2014, 20:18
Re: Custom function problem - by moof2010 - 05.05.2014, 20:37

Forum Jump:


Users browsing this thread: 1 Guest(s)