Closest Vehicle
#1

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?
Reply
#2

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;
}
Reply
#3

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

Thank "Jefff" Very good I Like You
Reply
#5

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
Reply
#6

Its for samp 0.3d, download includes
Reply
#7

+ Rep for you Jeff
Reply
#8

d < MAX_VEHIICLES;

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


Forum Jump:


Users browsing this thread: 1 Guest(s)