From 96a45065fceaa7e5b3c749df439b600c74b9ac4f Mon Sep 17 00:00:00 2001 From: Vortrex <3858226+VortrexFTW@users.noreply.github.com> Date: Fri, 15 Jan 2021 03:43:51 -0600 Subject: [PATCH] Fix get players in range util --- scripts/server/utilities.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/scripts/server/utilities.js b/scripts/server/utilities.js index 9de2a05b..616ada68 100644 --- a/scripts/server/utilities.js +++ b/scripts/server/utilities.js @@ -541,9 +541,7 @@ function getVehiclesInRange(position, distance) { // --------------------------------------------------------------------------- function getClientsInRange(position, distance) { - //return getClients().filter(x => x.player && x.player.position.distance(position) <= distance); - - return getElementsByTypeInRange(ELEMENT_PLAYER, position, distance); + return getPlayersInRange(position, distance); } // --------------------------------------------------------------------------- @@ -955,12 +953,12 @@ function getVehiclesInRange(position, range) { // --------------------------------------------------------------------------- function getPlayersInRange(position, range) { - let peds = getPeds(); + let clients = getClients(); let inRangePlayers = []; - for(let i in peds) { - if(peds[i].isType(ELEMENT_PLAYER)) { - if(getDistance(position, peds[i].position) <= range) { - inRangePlayers.push(peds[i]); + for(let i in clients) { + if(isPlayerSpawned(clients[i])) { + if(getDistance(position, getPlayerPosition(clients[i])) <= range) { + inRangePlayers.push(clients[i]); } } } @@ -1818,6 +1816,10 @@ function getPlayerNameForNameTag(client) { // ------------------------------------------------------------------------- function isPlayerSpawned(client) { + if(client.console) { + return false; + } + return (client.player != null); } @@ -1876,13 +1878,15 @@ function resetClientStuff(client) { } if(isPlayerOnJobRoute(client)) { - stopJobRoute(client); + stopJobRoute(client, false, false); } if(getPlayerData(client).rentingVehicle) { stopRentingVehicle(client); } + deleteJobItems(client); + getPlayerData(client).lastVehicle = null; } @@ -1891,7 +1895,7 @@ function resetClientStuff(client) { function getPlayerFromCharacterId(subAccountId) { let clients = getClients(); for(let i in clients) { - for(let j in getPlayerData(clients).subAccounts) { + for(let j in getPlayerData(clients[i]).subAccounts) { if(getPlayerData(clients[i]).subAccounts[j].databaseId == subAccountId) { return clients[i]; } @@ -1940,4 +1944,4 @@ function applyOffsetToVector3(position, position2) { return toVector3(position.x+position2.x, position.y+position2.y, position.z+position2.z); } -// ------------------------------------------------------------------------- +// ------------------------------------------------------------------------- \ No newline at end of file