Fix get players in range util

This commit is contained in:
Vortrex
2021-01-15 03:43:51 -06:00
parent ce018eaf5f
commit 96a45065fc

View File

@@ -541,9 +541,7 @@ function getVehiclesInRange(position, distance) {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function getClientsInRange(position, distance) { function getClientsInRange(position, distance) {
//return getClients().filter(x => x.player && x.player.position.distance(position) <= distance); return getPlayersInRange(position, distance);
return getElementsByTypeInRange(ELEMENT_PLAYER, position, distance);
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@@ -955,12 +953,12 @@ function getVehiclesInRange(position, range) {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function getPlayersInRange(position, range) { function getPlayersInRange(position, range) {
let peds = getPeds(); let clients = getClients();
let inRangePlayers = []; let inRangePlayers = [];
for(let i in peds) { for(let i in clients) {
if(peds[i].isType(ELEMENT_PLAYER)) { if(isPlayerSpawned(clients[i])) {
if(getDistance(position, peds[i].position) <= range) { if(getDistance(position, getPlayerPosition(clients[i])) <= range) {
inRangePlayers.push(peds[i]); inRangePlayers.push(clients[i]);
} }
} }
} }
@@ -1818,6 +1816,10 @@ function getPlayerNameForNameTag(client) {
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
function isPlayerSpawned(client) { function isPlayerSpawned(client) {
if(client.console) {
return false;
}
return (client.player != null); return (client.player != null);
} }
@@ -1876,13 +1878,15 @@ function resetClientStuff(client) {
} }
if(isPlayerOnJobRoute(client)) { if(isPlayerOnJobRoute(client)) {
stopJobRoute(client); stopJobRoute(client, false, false);
} }
if(getPlayerData(client).rentingVehicle) { if(getPlayerData(client).rentingVehicle) {
stopRentingVehicle(client); stopRentingVehicle(client);
} }
deleteJobItems(client);
getPlayerData(client).lastVehicle = null; getPlayerData(client).lastVehicle = null;
} }
@@ -1891,7 +1895,7 @@ function resetClientStuff(client) {
function getPlayerFromCharacterId(subAccountId) { function getPlayerFromCharacterId(subAccountId) {
let clients = getClients(); let clients = getClients();
for(let i in clients) { 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) { if(getPlayerData(clients[i]).subAccounts[j].databaseId == subAccountId) {
return clients[i]; return clients[i];
} }