var position; // твои координаты в этой переменной
// Если мы нашли какую-то другую машину на нужных координатах (и 6 "метров" рядом) - пропускаем..
let vehicle = methods.getNearestVehicleWithCoords(position, 6);
if(vehicle && mp.vehicles.exists(vehicle))
return;
methods.getNearestVehicleWithCoords = function(pos, r, dimension = 0) {
let nearest = undefined, dist;
let min = r;
methods.getListOfVehicleInRadius(pos, r).forEach(vehicle => {
dist = methods.distanceToPos(pos, vehicle.position);
if (dist < min) {
if (dimension == vehicle.dimension) {
nearest = vehicle;
min = dist;
}
}
});
return nearest;
};
methods.getListOfVehicleInRadius = function(pos, r) {
let returnVehicles = [];
mp.vehicles.forEachInRange(pos, r,
(vehicle) => {
if (!vehicles.exists(vehicle))
return;
returnVehicles.push(vehicle);
}
);
return returnVehicles;
};
methods.distanceToPos = function (v1, v2) {
return Math.abs(Math.sqrt(Math.pow((v2.x - v1.x),2) +
Math.pow((v2.y - v1.y),2)+
Math.pow((v2.z - v1.z),2)));
};