2 Commits

Author SHA1 Message Date
Vortrex
133d60ffdd Merge branch 'nightly' into non-server-elements 2022-06-14 05:57:21 -05:00
Vortrex
ee014b2578 Start using IDs instead of element objects 2022-05-31 08:35:40 -05:00
4 changed files with 15 additions and 18 deletions

View File

@@ -163,12 +163,6 @@ function clearLocalPlayerWeapons(clearData) {
// ===========================================================================
function getClosestVehicle(pos) {
return getElementsByType(ELEMENT_VEHICLE).reduce((i, j) => (i.position.distance(pos) < j.position.distance(pos)) ? i : j);
}
// ===========================================================================
function setLocalPlayerPosition(position) {
logToConsole(LOG_DEBUG, `[VRR.Utilities] Setting position to ${position.x}, ${position.y}, ${position.z}`);
if (typeof localPlayer.velocity != "undefined") {

View File

@@ -1086,12 +1086,6 @@ function getVehiclesInRange(position, range) {
// ===========================================================================
function getClosestVehicle(position) {
return getClosestElementByType(ELEMENT_VEHICLE, position);
}
// ===========================================================================
function getClosestElementByType(elementType, position) {
return getElementsByType(elementType).reduce((i, j) => (getDistance(position, getElementPosition(i)) <= getDistance(position, getElementPosition(j))) ? i : j);
}

View File

@@ -963,12 +963,6 @@ function getVehiclesInRange(position, range) {
// ===========================================================================
function getClosestVehicle(position) {
return getClosestElementByType(ELEMENT_VEHICLE, position);
}
// ===========================================================================
function getClosestElementByType(elementType, position) {
return getElementsByType(elementType).reduce((i, j) => (getDistance(position, getElementPosition(i)) <= getDistance(position, getElementPosition(j))) ? i : j);
}

View File

@@ -1696,3 +1696,18 @@ function getVehicleColourInfoString(colour, isRGBA) {
}
// ===========================================================================
function getClosestVehicle(position, interior, dimension) {
let closest = 0;
let vehicles = getServerData().vehicles;
for(let i in vehicles) {
if(getDistance(getVehiclePosition(vehicles[i].vehicle), position) < getDistance(getVehiclePosition(vehicles[closest].vehicle), position) && getVehicleDimension(vehicles[i].vehicle) == dimension && getVehicleInterior(vehicles[i].vehicle) == interior) {
closest = i;
}
}
return closest;
}
// ===========================================================================