Getting nearest vehicle in range
#1

I've been trying to make a function that gets the nearest vehicle within 10 meters, so far i only got the nearest vehicle, but don't know how to add the range to it.

Here's the current function:
pawn Код:
stock GetNearestVehicle(playerid)
{
    new Float:dist = 1000.0;
    new targetid = INVALID_PLAYER_ID;
    new Float:x1,Float:y1,Float:z1;
    new Float:x2,Float:y2,Float:z2;
    new Float:tmpdis;
    GetPlayerPos(playerid,x1,y1,z1);
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        if(i == playerid) continue;
        GetPlayerPos(i,x2,y2,z2);
        tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
        if(tmpdis < dist)
        {
            dist = tmpdis;
            targetid = i;
        }
    }
    return targetid;
}
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: 1 Guest(s)