SA-MP Forums Archive
Closest Vehicle - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Closest Vehicle (/showthread.php?tid=307755)



Closest Vehicle - silvan - 01.01.2012

Hello peaple, I need some help regarding on how to get the CLOSEST and NOT the first ID of the loop.

And on the forums all i could find was the first ID that found in a loop can someone give me a snippet of how this could be found out?


Re: Closest Vehicle - Jefff - 01.01.2012

Something like this but You must check if vehicle is empty :P
pawn Код:
stock GetClosestVehicle(playerid)
{
    new Float:DefaultDistance = 99999999999.9;
    new Float:Distance,VehID;
    new Float:X,Float:Y,Float:Z;
    for(new d=1; d < MAX_VEHIICLES; d++)
    {
        if(GetVehicleModel(d))
        {
            GetPlayerPos(playerid,X,Y,Z);
            Distance = GetVehicleDistanceFromPoint(d,X,Y,Z);
            if(Distance < DefaultDistance)
            {
                VehID = d;
                DefaultDistance = Distance;
            }
        }
    }
    return VehID;
}



Re: Closest Vehicle - silvan - 01.01.2012

i'll try it m8, thanks for your help, i hope it works.


Re: Closest Vehicle - parames3010 - 01.01.2012

Thank "Jefff" Very good I Like You


Re: Closest Vehicle - silvan - 01.01.2012

Erm do you got the GetVehicleDistanceFromPoint? function pls


Nevermind xD i thout its a custom function XD sorry, my bad, Again thanks for giving it up and i'm gonna test it just now xD i have just compiled it xD


Re: Closest Vehicle - Jefff - 01.01.2012

Its for samp 0.3d, download includes


Re: Closest Vehicle - silvan - 01.01.2012

+ Rep for you Jeff


Re: Closest Vehicle - jamesbond007 - 01.01.2012

d < MAX_VEHIICLES;

nice... this is a new variable of yours? :P