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=517650)
closest vehicle -
n00el - 06.06.2014
hello.
how i can get a closest vehicle without the current vehicle id?
for e.g. i am in a vehicle (id 2) and near me there is a vehicle (id 3).
when i am using this, i always get id 2. how i can get id 3?
PHP код:
stock GetClosestVehicle(playerid, Float:radius)
{
new Float:CarX, Float:CarZ, Float:CarY, Float:Dis, Float:Dis2,vehicleid;
Dis = 99999.99;
vehicleid = INVALID_VEHICLE_ID;
for(new i = 0; i < MAX_VEHICLES; i++)
{
GetVehiclePos(i, CarX, CarY, CarZ);
Dis2 = GetPlayerDistanceFromPoint(playerid, CarX, CarY, CarZ);
if(Dis2 < Dis && Dis2 < radius)
{
Dis = Dis2;
vehicleid = i;
}
}
return vehicleid;
}
Re: closest vehicle -
BroZeus - 06.06.2014
if(Dis2 < Dis && Dis2 < radius)
change this to this --
if(Dis2 < Dis && Dis2 < radius && i != GetPlayerVehicleID(playerid))