Getting nearest vehicle in range
#4

Quote:
Originally Posted by MP2
Посмотреть сообщение
pawn Код:
stock GetNearestVehicle(playerid, Float:max_range = 99999.0)
{
    new Float:closestDist = max_range;
    new closestVehicle = 0;
    new Float:thisDist;
   
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
   
    for(new i=1; i<=MAX_VEHICLES; i++)
    {
        thisDist = GetVehicleDistanceFromPoint(i, x, y, z);
        if(thisDist < max_range && thisDist < closestDist)
        {
            closestDist = thisDist;
            closestVehicle = i;
        }
    }
    return closestVehicle;
}
Not tested, but it compiles, and it should work.

If it returns 0 (invalid vehicle ID as they start at 1) it means there's no vehicles within range.
It give's me an invalid vehicle ID (28 in my case) but there are over 10 vehicles in range of it.
Reply


Messages In This Thread
Getting nearest vehicle in range - by Jimmy0wns - 30.01.2014, 21:23
Re: Getting nearest vehicle in range - by AlonzoTorres - 30.01.2014, 21:45
Re: Getting nearest vehicle in range - by MP2 - 31.01.2014, 00:04
Re: Getting nearest vehicle in range - by Jimmy0wns - 31.01.2014, 08:20

Forum Jump:


Users browsing this thread: 2 Guest(s)