Organize a lot of utils
This commit is contained in:
@@ -70,4 +70,22 @@ function listAccentsCommand(command, params, client) {
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getAccentFromParams(params) {
|
||||
if(isNaN(params)) {
|
||||
for(let i in getGlobalConfig().accents) {
|
||||
if(toLowerCase(getGlobalConfig().accents[i]).indexOf(toLowerCase(params)) != -1) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(typeof getGlobalConfig().accents[params] != "undefined") {
|
||||
return toInteger(params);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -75,7 +75,7 @@ function showAnimationListCommand(command, params, client) {
|
||||
|
||||
let chunkedList = splitArrayIntoChunks(animList, 10);
|
||||
|
||||
messagePlayerInfo(client, makeChatSectionHeader(getLocaleString(client, "HeaderAnimationsList")));
|
||||
messagePlayerInfo(client, makeChatBoxSectionHeader(getLocaleString(client, "HeaderAnimationsList")));
|
||||
|
||||
for(let i in chunkedList) {
|
||||
messagePlayerNormal(client, chunkedList[i].join(", "));
|
||||
@@ -138,4 +138,22 @@ function makePlayerStopAnimation(client) {
|
||||
getPlayerData(client).animationForced = false;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getAnimationFromParams(params) {
|
||||
if(isNaN(params)) {
|
||||
for(let i in getGameData().animations[getServerGame()]) {
|
||||
if(toLowerCase(getGameData().animations[getServerGame()][i][0]).indexOf(toLowerCase(params)) != -1) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(typeof getGameData().animations[getServerGame()][params] != "undefined") {
|
||||
return toInteger(params);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -248,4 +248,44 @@ function isPlayerExemptFromAntiCheat(client) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function canPlayerUsePoliceJob(client) {
|
||||
if(getPlayerData(client).accountData.flags.moderation & getServerBitFlags().moderationFlags.policeBanned) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function canClientUseFireJob(client) {
|
||||
if(getPlayerData(client).accountData.flags.moderation & getServerBitFlags().moderationFlags.fireBanned) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function canClientUseAmmunations(client) {
|
||||
if(getPlayerData(client).accountData.flags.moderation & getServerBitFlags().moderationFlags.AmmuBanned) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function canClientUseGuns(client) {
|
||||
if(getPlayerData(client).accountData.flags.moderation & getServerBitFlags().moderationFlags.GunBanned) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -517,7 +517,7 @@ function lockUnlockBusinessCommand(command, params, client) {
|
||||
setEntityData(getBusinessData(businessId).entrancePickup, "vrr.label.locked", getBusinessData(businessId).locked, true);
|
||||
|
||||
getBusinessData(businessId).needsSaved = true;
|
||||
messagePlayerSuccess(client, `${getLockedUnlockedEmojiFromBool((getBusinessData(businessId).locked))} Business {businessBlue}${getBusinessData(businessId).name} {MAINCOLOUR}${getLockedUnlockedTextFromBool((getBusinessData(businessId).locked))}!`);
|
||||
messagePlayerSuccess(client, `${getLockedUnlockedEmojiFromBool((getBusinessData(businessId).locked))} Business {businessBlue}${getBusinessData(businessId).name} {MAINCOLOUR}${getLockedUnlockedFromBool((getBusinessData(businessId).locked))}!`);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -2126,3 +2126,20 @@ function deleteBusinessPickups(business) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getBusinessFromParams(params) {
|
||||
if(isNaN(params)) {
|
||||
for(let i in getServerData().businesses) {
|
||||
if(toLowerCase(getServerData().businesses[i].name).indexOf(toLowerCase(params)) != -1) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(typeof getServerData().businesses[params] != "undefined") {
|
||||
return toInteger(params);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
|
||||
@@ -1215,4 +1215,42 @@ function showClanFlagListCommand(command, params, client) {
|
||||
messagePlayerInfo(client, chunkedList[i].join(", "));
|
||||
}
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
||||
function getClanFromParams(params) {
|
||||
if(isNaN(params)) {
|
||||
for(let i in getServerData().clans) {
|
||||
if(toLowerCase(getServerData().clans[i].name).indexOf(toLowerCase(params)) != -1) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(typeof getServerData().clans[params] != "undefined") {
|
||||
return toInteger(params);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getClanRankFromParams(clanId, params) {
|
||||
if(isNaN(params)) {
|
||||
for(let i in getClanData(clanId).ranks) {
|
||||
if((toLowerCase(getClanData(clanId).ranks[i].name).indexOf(toLowerCase(params)) != -1)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for(let i in getClanData(clanId).ranks) {
|
||||
if(getClanData(clanId).ranks[i].level == toInteger(params)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -765,4 +765,46 @@ function getCommandAliasesNames(command) {
|
||||
return commandAliases;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function areParamsEmpty(params) {
|
||||
if(!params || params == "" || params.length == 0 || typeof params == "undefined") {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getParamsCount(params, delimiter = " ") {
|
||||
return params.split(delimiter).length;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function areThereEnoughParams(params, requiredAmount, delimiter = " ") {
|
||||
return (params.split(delimiter).length >= requiredAmount);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getParam(params, delimiter, index) {
|
||||
return params.split(delimiter)[index];
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getCommandFromParams(params) {
|
||||
for(let i in serverCommands) {
|
||||
for(let j in serverCommands[i]) {
|
||||
if(toLowerCase(serverCommands[i][j].command).indexOf(toLowerCase(params)) != -1) {
|
||||
return serverCommands[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -125,7 +125,7 @@ function lockUnlockHouseCommand(command, params, client) {
|
||||
setEntityData(getHouseData(houseId).entrancePickup, "vrr.label.locked", getHouseData(houseId).locked, true);
|
||||
getHouseData(houseId).needsSaved = true;
|
||||
|
||||
messagePlayerSuccess(client, `House {houseGreen}${getHouseData(houseId).description} {MAINCOLOUR}${getLockedUnlockedTextFromBool((getHouseData(houseId).locked))}!`);
|
||||
messagePlayerSuccess(client, `House {houseGreen}${getHouseData(houseId).description} {MAINCOLOUR}${getLockedUnlockedFromBool((getHouseData(houseId).locked))}!`);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -1380,4 +1380,21 @@ function canPlayerManageHouse(client, houseId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getHouseFromParams(params) {
|
||||
if(isNaN(params)) {
|
||||
for(let i in getServerData().houses) {
|
||||
if(toLowerCase(getServerData().houses[i].description).indexOf(toLowerCase(params)) != -1) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(typeof getServerData().houses[params] != "undefined") {
|
||||
return toInteger(params);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -2020,4 +2020,23 @@ function createGroundPlant(itemId) {
|
||||
groundPlantCache.push(itemId);
|
||||
groundItemCache.push(itemId);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getItemTypeFromParams(params) {
|
||||
if(isNaN(params)) {
|
||||
for(let i in getServerData().itemTypes) {
|
||||
if(toLowerCase(getServerData().itemTypes[i].name).indexOf(toLowerCase(params)) != -1) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(typeof getServerData().itemTypes[params] != "undefined") {
|
||||
return toInteger(params);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -2083,4 +2083,44 @@ function setAllJobIndexes() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getJobFromParams(params) {
|
||||
if(isNaN(params)) {
|
||||
for(let i in getServerData().jobs) {
|
||||
if(toLowerCase(getServerData().jobs[i].name).indexOf(toLowerCase(params)) != -1) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(typeof getServerData().jobs[params] != "undefined") {
|
||||
return params;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getClosestJobLocation(position) {
|
||||
let closestJobLocation = false;
|
||||
for(let i in getServerData().jobs) {
|
||||
for(let j in getServerData().jobs[i].locations) {
|
||||
if(!closestJobLocation || getServerData().jobs[i].locations[j].position.distance(position) < closestJobLocation.position.distance(position)) {
|
||||
closestJobLocation = getServerData().jobs[i].locations[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
return closestJobLocation;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getJobPointsInRange(position, distance) {
|
||||
return getServerData().jobs[getServerGame()].filter(x => x.position.distance(position) <= distance);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -68,4 +68,19 @@ function getLocaleStrings() {
|
||||
return getServerData().localeStrings;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getLocaleNameFromParams(params) {
|
||||
let locales = getLocales();
|
||||
if(isNaN(params)) {
|
||||
for(let i in locales) {
|
||||
if(toLowerCase(i).indexOf(toLowerCase(params)) != -1) {
|
||||
return locales[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -211,4 +211,32 @@ function messagePlayerTimedRandomTip(client, message) {
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function makeChatBoxSectionHeader(name) {
|
||||
let resultString = `== ${name} `;
|
||||
let endFiller = fillStringWithCharacter("=", getGlobalConfig().chatSectionHeaderLength-resultString.length);
|
||||
return `${resultString} ${endFiller}`;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function clearChatBox(client) {
|
||||
//game.messages.clear();
|
||||
for(let i = 0; i <= 20; i++) {
|
||||
messageClient(" ", client, COLOUR_WHITE);
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function replaceEmojiIntoString(message) {
|
||||
for(let i in emojiReplaceString) {
|
||||
while(message.indexOf(emojiReplaceString[i][0]) != -1) {
|
||||
message = message.replace(emojiReplaceString[i][0], emojiReplaceString[i][1]);
|
||||
}
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1496,4 +1496,10 @@ function getClosestTaxi(position) {
|
||||
.reduce((i, j) => ((i.position.distance(position) <= j.position.distance(position)) ? i : j));
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function getVehicleTrunkPosition(vehicle) {
|
||||
return getPosBehindPos(getVehiclePosition(vehicle), getVehicleHeading(vehicle), getGlobalConfig().vehicleTrunkRearDistance);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
Reference in New Issue
Block a user