Fix range utils, move array chunk util to shared

This commit is contained in:
Vortrex
2021-12-03 10:24:01 -06:00
parent 271e512d46
commit 832545e9c9
2 changed files with 17 additions and 41 deletions

View File

@@ -367,36 +367,6 @@ function getVehiclesInRange(position, range) {
// =========================================================================== // ===========================================================================
function getPlayersInRange(position, range) {
let clients = getClients();
let inRangePlayers = [];
for(let i in clients) {
if(isPlayerSpawned(clients[i])) {
if(getDistance(position, getPlayerPosition(clients[i])) <= range) {
inRangePlayers.push(clients[i]);
}
}
}
return inRangePlayers;
}
// ===========================================================================
function getCiviliansInRange(position, range) {
let peds = getElementsByType(ELEMENT_PED).filter((ped) => !ped.isType(ELEMENT_PLAYER));
let inRangeCivilians = [];
for(let i in peds) {
if(peds[i].isType(ELEMENT_PED)) {
if(getDistance(position, peds[i].position) <= range) {
inRangeCivilians.push(peds[i]);
}
}
}
return inRangeCivilians;
}
// ===========================================================================
function getFileData(filePath) { function getFileData(filePath) {
let file = openFile(filePath, false); let file = openFile(filePath, false);
if(!file) { if(!file) {
@@ -1169,7 +1139,13 @@ function getClientsInRange(position, distance) {
// =========================================================================== // ===========================================================================
function getCiviliansInRange(position, distance) { function getCiviliansInRange(position, distance) {
return getElementsByType(ELEMENT_PED).filter(x => x.position.distance(position) <= distance); return getElementsByType(ELEMENT_PED).filter(x => !x.isType(ELEMENT_PLAYER) && x.position.distance(position) <= distance);
}
// ===========================================================================
function getPlayersInRange(position, distance) {
return getElementsByType(ELEMENT_PLAYER).filter(x => x.position.distance(position) <= distance);
} }
// =========================================================================== // ===========================================================================
@@ -1454,16 +1430,6 @@ function fixCharacterName(name) {
// =========================================================================== // ===========================================================================
function splitArrayIntoChunks(originalArray, perChunk) {
let tempArray = [];
for (let i = 0; i < originalArray.length; i += perChunk) {
tempArray.push(originalArray.slice(i, i + perChunk));
}
return tempArray;
}
// ===========================================================================
function getAllVehiclesOwnedByPlayer(client) { function getAllVehiclesOwnedByPlayer(client) {
return getServerData().vehicles.filter((v) => v.ownerType == VRR_VEHOWNER_PLAYER && v.ownerId == getPlayerCurrentSubAccount(client).databaseId); return getServerData().vehicles.filter((v) => v.ownerType == VRR_VEHOWNER_PLAYER && v.ownerId == getPlayerCurrentSubAccount(client).databaseId);
} }

View File

@@ -850,4 +850,14 @@ function getRandom(min, max) {
return Math.floor(Math.random() * (toInteger(max) - toInteger(min) + 1)) + toInteger(min) return Math.floor(Math.random() * (toInteger(max) - toInteger(min) + 1)) + toInteger(min)
} }
// ===========================================================================
function splitArrayIntoChunks(originalArray, perChunk) {
let tempArray = [];
for (let i = 0; i < originalArray.length; i += perChunk) {
tempArray.push(originalArray.slice(i, i + perChunk));
}
return tempArray;
}
// =========================================================================== // ===========================================================================