Closest Car and car id
#4

I think he wanted a GetClosestVehicle not IsVehicleInRangeOfPoint

so here a GetClosestVehicle function with distance parameter
pawn Код:
stock GetClosestVehicle(playerid, &Float:dis = (Float:0x7F800000))
{
  dis = (Float:0x7F800000);
  new Float:X, Float:Y, Float:Z;
  if(GetPlayerPos(playerid, X, Y, Z)) {
    new vehicleid = INVALID_VEHICLE_ID;
    for(new v, Float:temp, Float:VX, Float:VY, Float:VZ; v != MAX_VEHICLES; v++) {
      if(GetVehiclePos(v, VX, VY, VZ)) {
        VX -= X, VY -= Y, VZ -= Z;
        temp = VX * VX + VY * VY + VZ * VZ;
        if(temp < dis) dis = temp, vehicleid = v;
      }
    }
    dis = floatpower(dis, 0.5);
    return vehicleid;
  }
  return INVALID_VEHICLE_ID;
}
and the usage
pawn Код:
new closest_vehicle = GetClosestVehicle(playerid);
pawn Код:
//with distance
new closest_vehicle, Float:distance;
closest_vehicle = GetClosestVehicle(playerid, distance);
Reply


Messages In This Thread
Closest Car and car id - by friped93 - 25.04.2010, 16:02
Re: Closest Car and car id - by Nero_3D - 25.04.2010, 16:10
Re: Closest Car and car id - by friped93 - 25.04.2010, 16:21
Re: Closest Car and car id - by Nero_3D - 25.04.2010, 16:40
Re: Closest Car and car id - by friped93 - 25.04.2010, 16:42
Re: Closest Car and car id - by friped93 - 25.04.2010, 18:05
Re: Closest Car and car id - by friped93 - 25.04.2010, 18:31

Forum Jump:


Users browsing this thread: 1 Guest(s)