From 00c181c2013a88bc92bb90b928a16a136b4922db Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Fri, 6 May 2022 12:35:36 -0500 Subject: [PATCH] Use local var for closest job location util --- scripts/server/job.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/scripts/server/job.js b/scripts/server/job.js index 9cf77b2b..35140d43 100644 --- a/scripts/server/job.js +++ b/scripts/server/job.js @@ -2835,23 +2835,26 @@ function getJobFromParams(params) { /** * @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) */ function getClosestJobLocation(position, dimension = 0) { let closestJobLocation = false; - for(let i in getServerData().jobs) { - for(let j in getServerData().jobs[i].locations) { - if(getServerData().jobs[i].locations[j].dimension != dimension) { - let businessId = getClosestBusinessExit(getServerData().jobs[i].locations[j].position, getServerData().jobs[i].locations[j].dimension); + let jobs = getServerData().jobs; + for(let i in jobs) { + let locations = jobs[i].locations; + for(let j in locations) { + if(locations[j].dimension != dimension) { + let businessId = getClosestBusinessExit(locations[j].position, locations[j].dimension); if(getBusinessData(businessId) != false) { 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)) { - closestJobLocation = getServerData().jobs[i].locations[j]; + if(!closestJobLocation || locations[j].position.distance(position) < closestJobLocation.position.distance(position)) { + closestJobLocation = locations[j]; } } }