PDA

View Full Version : Closest Vehicle


silvan
01/01/2012, 01:01 AM
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?

Jefff
01/01/2012, 02:12 AM
Something like this but You must check if vehicle is empty :P
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;
}

silvan
01/01/2012, 02:21 AM
i'll try it m8, thanks for your help, i hope it works.

parames3010
01/01/2012, 02:22 AM
Thank "Jefff" Very good I Like You

silvan
01/01/2012, 02:26 AM
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

Jefff
01/01/2012, 02:26 AM
Its for samp 0.3d, download includes

silvan
01/01/2012, 02:28 AM
+ Rep for you Jeff :)

jamesbond007
01/01/2012, 03:44 AM
d < MAX_VEHIICLES;

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