Posts: 415
Threads: 51
Joined: Oct 2007
Reputation:
0
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?
Posts: 2,593
Threads: 34
Joined: Dec 2007
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;
}
Posts: 415
Threads: 51
Joined: Oct 2007
Reputation:
0
i'll try it m8, thanks for your help, i hope it works.
Posts: 102
Threads: 33
Joined: Oct 2011
Reputation:
0
Thank "Jefff" Very good I Like You
Posts: 415
Threads: 51
Joined: Oct 2007
Reputation:
0
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
Posts: 2,593
Threads: 34
Joined: Dec 2007
Its for samp 0.3d, download includes
Posts: 791
Threads: 65
Joined: Oct 2009
Reputation:
0
d < MAX_VEHIICLES;
nice... this is a new variable of yours? :P