Use local var for closest job location util

This commit is contained in:
Vortrex
2022-05-06 12:35:36 -05:00
parent 57621bf411
commit 00c181c201

View File

@@ -2835,23 +2835,26 @@ function getJobFromParams(params) {
/** /**
* @param {Vector3} position - The position to get the closest job location for * @param {Vector3} position - The position to get the closest job location for
* @param {Number} dimension - The dimension to get the closest job location for
* @return {JobLocationData} The job location's data (class instance) * @return {JobLocationData} The job location's data (class instance)
*/ */
function getClosestJobLocation(position, dimension = 0) { function getClosestJobLocation(position, dimension = 0) {
let closestJobLocation = false; let closestJobLocation = false;
for(let i in getServerData().jobs) { let jobs = getServerData().jobs;
for(let j in getServerData().jobs[i].locations) { for(let i in jobs) {
if(getServerData().jobs[i].locations[j].dimension != dimension) { let locations = jobs[i].locations;
let businessId = getClosestBusinessExit(getServerData().jobs[i].locations[j].position, getServerData().jobs[i].locations[j].dimension); for(let j in locations) {
if(locations[j].dimension != dimension) {
let businessId = getClosestBusinessExit(locations[j].position, locations[j].dimension);
if(getBusinessData(businessId) != false) { if(getBusinessData(businessId) != false) {
if(!closestJobLocation || getBusinessData(businessId).entrancePosition.distance(position) < closestJobLocation.position.distance(position)) { if(!closestJobLocation || getBusinessData(businessId).entrancePosition.distance(position) < closestJobLocation.position.distance(position)) {
closestJobLocation = getServerData().jobs[i].locations[j]; closestJobLocation = locations[j];
} }
} }
} }
if(!closestJobLocation || getServerData().jobs[i].locations[j].position.distance(position) < closestJobLocation.position.distance(position)) { if(!closestJobLocation || locations[j].position.distance(position) < closestJobLocation.position.distance(position)) {
closestJobLocation = getServerData().jobs[i].locations[j]; closestJobLocation = locations[j];
} }
} }
} }