Organize a lot of utils

This commit is contained in:
Vortrex
2022-01-09 17:19:53 -06:00
parent 2684ffae7d
commit 5dfe47a3e8
16 changed files with 905 additions and 1069 deletions

View File

@@ -898,4 +898,69 @@ function addNetworkEventHandler(eventName, handlerFunction) {
addNetworkHandler(eventName, handlerFunction);
}
// ===========================================================================
function getElementId(element) {
return element.id;
}
// ===========================================================================
function getClientFromIndex(index) {
let clients = getClients();
for(let i in clients) {
if(clients[i].index == index) {
return clients[i];
}
}
}
// ===========================================================================
function getClientsInRange(position, distance) {
return getPlayersInRange(position, distance);
}
// ===========================================================================
function getCiviliansInRange(position, distance) {
return getElementsByTypeInRange(ELEMENT_PED, position, distance).filter(x => !x.isType(ELEMENT_PLAYER));
}
// ===========================================================================
function getPlayersInRange(position, distance) {
return getClients().filter(x => getDistance(position, getPlayerPosition(x)) <= distance);
}
// ===========================================================================
function getElementsByTypeInRange(elementType, position, distance) {
return getElementsByType(elementType).filter(x => getDistance(position, getElementPosition(x)) <= distance);
}
// ===========================================================================
function getClosestCivilian(position) {
return getClosestElementByType(ELEMENT_PED, position).filter(ped => !ped.isType(ELEMENT_PLAYER));
}
// ===========================================================================
function getVehiclesInRange(position, range) {
return getElementsByTypeInRange(ELEMENT_VEHICLE, position, range);
}
// ===========================================================================
function getClosestVehicle(position) {
return getClosestElementByType(ELEMENT_VEHICLE, position);
}
// ===========================================================================
function getClosestElementByType(elementType, position) {
return getElementsByType(elementType).reduce((i, j) => (getDistance(position, getElementPosition(i)) <= getDistance(position, getElementPosition(j))) ? i : j);
}
// ===========================================================================