PDA

View Full Version : closest vehicle


n00el
06/06/2014, 04:49 AM
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?
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;
}

BroZeus
06/06/2014, 06:04 AM
if(Dis2 < Dis && Dis2 < radius)
change this to this --
if(Dis2 < Dis && Dis2 < radius && i != GetPlayerVehicleID(playerid))