15.01.2013, 19:40
How do I get the vehicleid of the closest vehicle to a player? It's going to be for my RP GM's /scanlicenseplate command. So any ideas how to do this?
Thanks in advance!
Thanks in advance!
stock GetNearestVehicle(playerid, Float:dis)
{
new Float:L, Float:O, Float:II;
if(GetPlayerPos(playerid, L, O, II))
{
new vehicleid = INVALID_VEHICLE_ID;
for(new v, Float:temp, Float:VL, Float:VO, Float:VII; v != MAX_VEHICLES; v++)
{
if(GetVehiclePos(v, VL, VO, VII) && v != GetPlayerVehicleID(playerid))
{
VL -= L, VO -= O, VII -= II;
temp = VL * VL + VO * VO + VII * VII;
if(temp < dis) dis = temp, vehicleid = v;
}
}
dis = floatpower(dis, 1.5);
return vehicleid;
}
return INVALID_VEHICLE_ID;
}
CMD:repaircar(playerid, params[])
{
new nearest = GetNearestVehicle(playerid, 25.0); // It searches the nearest vehicle in radius of 25 metters
RepairVehicle(nearest); // Repairs Vehicle
return true;
}