Add player blips
This commit is contained in:
@@ -40,10 +40,10 @@ let disconnectReasons = [
|
||||
// ===========================================================================
|
||||
|
||||
function getPlayerPosition(client) {
|
||||
if(!areServerElementsSupported()) {
|
||||
if (!areServerElementsSupported()) {
|
||||
return getPlayerData(client).syncPosition;
|
||||
} else {
|
||||
if(getPlayerPed(client) != null) {
|
||||
if (getPlayerPed(client) != null) {
|
||||
return getPlayerPed(client).position;
|
||||
}
|
||||
}
|
||||
@@ -59,10 +59,10 @@ function setPlayerPosition(client, position) {
|
||||
// ===========================================================================
|
||||
|
||||
function getPlayerHeading(client) {
|
||||
if(!areServerElementsSupported()) {
|
||||
if (!areServerElementsSupported()) {
|
||||
return getPlayerData(client).syncHeading;
|
||||
} else {
|
||||
if(getPlayerPed(client) != null) {
|
||||
if (getPlayerPed(client) != null) {
|
||||
return getPlayerPed(client).heading;
|
||||
}
|
||||
}
|
||||
@@ -78,10 +78,10 @@ function setPlayerHeading(client, heading) {
|
||||
// ===========================================================================
|
||||
|
||||
function getPlayerVehicle(client) {
|
||||
if(!areServerElementsSupported()) {
|
||||
if (!areServerElementsSupported()) {
|
||||
return getPlayerData().syncVehicle;
|
||||
} else {
|
||||
if(getPlayerPed(client).vehicle) {
|
||||
if (getPlayerPed(client).vehicle) {
|
||||
return getPlayerPed(client).vehicle;
|
||||
}
|
||||
}
|
||||
@@ -91,10 +91,10 @@ function getPlayerVehicle(client) {
|
||||
// ===========================================================================
|
||||
|
||||
function getPlayerDimension(client) {
|
||||
if(!areServerElementsSupported()) {
|
||||
if (!areServerElementsSupported()) {
|
||||
return getPlayerData(client).syncDimension;
|
||||
} else {
|
||||
if(getPlayerPed(client) != null) {
|
||||
if (getPlayerPed(client) != null) {
|
||||
return getPlayerPed(client).dimension;
|
||||
}
|
||||
}
|
||||
@@ -110,10 +110,10 @@ function getPlayerInterior(client) {
|
||||
|
||||
function setPlayerDimension(client, dimension) {
|
||||
logToConsole(LOG_VERBOSE, `Setting ${getPlayerDisplayForConsole(client)}'s dimension to ${dimension}`);
|
||||
if(!areServerElementsSupported()) {
|
||||
if (!areServerElementsSupported()) {
|
||||
getPlayerData(client).syncDimension = dimension;
|
||||
} else {
|
||||
if(getPlayerPed(client) != null) {
|
||||
if (getPlayerPed(client) != null) {
|
||||
getPlayerPed(client).dimension = dimension;
|
||||
}
|
||||
}
|
||||
@@ -124,7 +124,7 @@ function setPlayerDimension(client, dimension) {
|
||||
function setPlayerInterior(client, interior) {
|
||||
logToConsole(LOG_VERBOSE, `Setting ${getPlayerDisplayForConsole(client)}'s interior to ${interior}`);
|
||||
sendPlayerSetInterior(client, interior);
|
||||
if(isPlayerLoggedIn(client) && isPlayerSpawned(client)) {
|
||||
if (isPlayerLoggedIn(client) && isPlayerSpawned(client)) {
|
||||
getPlayerCurrentSubAccount(client).interior = interior;
|
||||
}
|
||||
}
|
||||
@@ -132,7 +132,7 @@ function setPlayerInterior(client, interior) {
|
||||
// ===========================================================================
|
||||
|
||||
function isPlayerInAnyVehicle(client) {
|
||||
if(!areServerElementsSupported()) {
|
||||
if (!areServerElementsSupported()) {
|
||||
return (getPlayerData().syncVehicle != null);
|
||||
} else {
|
||||
return (getPlayerPed(client).vehicle != null);
|
||||
@@ -142,15 +142,15 @@ function isPlayerInAnyVehicle(client) {
|
||||
// ===========================================================================
|
||||
|
||||
function getPlayerVehicleSeat(client) {
|
||||
if(!isPlayerInAnyVehicle(client)) {
|
||||
if (!isPlayerInAnyVehicle(client)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!areServerElementsSupported()) {
|
||||
if (!areServerElementsSupported()) {
|
||||
return getPlayerData().syncVehicleSeat;
|
||||
} else {
|
||||
for(let i = 0 ; i <= 8 ; i++) {
|
||||
if(getPlayerVehicle(client).getOccupant(i) == getPlayerPed(client)) {
|
||||
for (let i = 0; i <= 8; i++) {
|
||||
if (getPlayerVehicle(client).getOccupant(i) == getPlayerPed(client)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -180,7 +180,7 @@ function getVehicleHeading(vehicle) {
|
||||
// ===========================================================================
|
||||
|
||||
function setVehicleHeading(vehicle, heading) {
|
||||
if(getGame() == VRR_GAME_GTA_IV) {
|
||||
if (getGame() == VRR_GAME_GTA_IV) {
|
||||
return sendNetworkEventToPlayer("vrr.vehPosition", null, getVehicleForNetworkEvent(vehicle), heading);
|
||||
}
|
||||
return vehicle.heading = heading;
|
||||
@@ -189,20 +189,20 @@ function setVehicleHeading(vehicle, heading) {
|
||||
// ===========================================================================
|
||||
|
||||
function getElementTransient(element) {
|
||||
if(typeof element.transient != "undefined") {
|
||||
if (typeof element.transient != "undefined") {
|
||||
return element.transient;
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function setElementTransient(element, state) {
|
||||
if(typeof element.transient != "undefined") {
|
||||
if (typeof element.transient != "undefined") {
|
||||
element.transient = state;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -214,8 +214,8 @@ function getVehicleSyncer(vehicle) {
|
||||
// ===========================================================================
|
||||
|
||||
function getVehicleForNetworkEvent(vehicle) {
|
||||
if(getGame() == VRR_GAME_GTA_IV) {
|
||||
if(getVehicleData(vehicle).ivNetworkId != -1) {
|
||||
if (getGame() == VRR_GAME_GTA_IV) {
|
||||
if (getVehicleData(vehicle).ivNetworkId != -1) {
|
||||
return getVehicleData(vehicle).ivNetworkId;
|
||||
}
|
||||
return -1;
|
||||
@@ -227,11 +227,11 @@ function getVehicleForNetworkEvent(vehicle) {
|
||||
|
||||
function deleteGameElement(element) {
|
||||
try {
|
||||
if(element != null) {
|
||||
if (element != null) {
|
||||
destroyElement(element);
|
||||
return true;
|
||||
}
|
||||
} catch(error) {
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -254,7 +254,7 @@ function removePlayerFromVehicle(client) {
|
||||
|
||||
function setPlayerSkin(client, skinIndex) {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s skin to ${getGameConfig().skins[getGame()][skinIndex][0]} (Index: ${skinIndex}, Name: ${getGameConfig().skins[getGame()][skinIndex][1]})`);
|
||||
if(getGame() == VRR_GAME_GTA_IV) {
|
||||
if (getGame() == VRR_GAME_GTA_IV) {
|
||||
triggerNetworkEvent("vrr.localPlayerSkin", client, getGameConfig().skins[getGame()][skinIndex][0]);
|
||||
} else {
|
||||
getPlayerPed(client).modelIndex = getGameConfig().skins[getGame()][skinIndex][0];
|
||||
@@ -292,7 +292,7 @@ function setPlayerArmour(client, armour) {
|
||||
// ===========================================================================
|
||||
|
||||
function getPlayerArmour(client) {
|
||||
if(areServerElementsSupported(client)) {
|
||||
if (areServerElementsSupported(client)) {
|
||||
return getPlayerPed(client).armour;
|
||||
} else {
|
||||
return getPlayerData(client).syncArmour;
|
||||
@@ -302,11 +302,11 @@ function getPlayerArmour(client) {
|
||||
// ===========================================================================
|
||||
|
||||
function setPlayerCash(client, amount) {
|
||||
if(client == null) {
|
||||
if (client == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(isNaN(amount)) {
|
||||
if (isNaN(amount)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -317,11 +317,11 @@ function setPlayerCash(client, amount) {
|
||||
// ===========================================================================
|
||||
|
||||
function givePlayerCash(client, amount) {
|
||||
if(client == null) {
|
||||
if (client == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(isNaN(amount)) {
|
||||
if (isNaN(amount)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -332,11 +332,11 @@ function givePlayerCash(client, amount) {
|
||||
// ===========================================================================
|
||||
|
||||
function takePlayerCash(client, amount) {
|
||||
if(client == null) {
|
||||
if (client == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(isNaN(amount)) {
|
||||
if (isNaN(amount)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -368,7 +368,7 @@ function getPlayerWeaponAmmo(client) {
|
||||
|
||||
function setPlayerVelocity(client, velocity) {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s velocity to ${velocity.x}, ${velocity.y}, ${velocity.z}`);
|
||||
if(typeof getPlayerPed(client).velocity != "undefined") {
|
||||
if (typeof getPlayerPed(client).velocity != "undefined") {
|
||||
getPlayerPed(client).velocity = velocity;
|
||||
}
|
||||
}
|
||||
@@ -376,7 +376,7 @@ function setPlayerVelocity(client, velocity) {
|
||||
// ===========================================================================
|
||||
|
||||
function getPlayerVelocity(client) {
|
||||
if(typeof getPlayerPed(client).velocity != "undefined") {
|
||||
if (typeof getPlayerPed(client).velocity != "undefined") {
|
||||
return getPlayerPed(client).velocity;
|
||||
}
|
||||
return toVector3(0.0, 0.0, 0.0);
|
||||
@@ -385,7 +385,7 @@ function getPlayerVelocity(client) {
|
||||
// ===========================================================================
|
||||
|
||||
function getElementDimension(element) {
|
||||
if(typeof element.dimension != "undefined") {
|
||||
if (typeof element.dimension != "undefined") {
|
||||
return element.dimension;
|
||||
}
|
||||
return 0;
|
||||
@@ -394,18 +394,18 @@ function getElementDimension(element) {
|
||||
// ===========================================================================
|
||||
|
||||
function setElementDimension(element, dimension) {
|
||||
if(typeof element.dimension != "undefined") {
|
||||
if (typeof element.dimension != "undefined") {
|
||||
logToConsole(LOG_VERBOSE, `Setting element ${element} (${element.id}) dimension to ${dimension}`);
|
||||
element.dimension = dimension;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
element.dimension = dimension;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function setElementRotation(element, rotation) {
|
||||
if(typeof element.setRotation != "undefined") {
|
||||
if (typeof element.setRotation != "undefined") {
|
||||
element.setRotation(rotation);
|
||||
} else {
|
||||
return element.rotation = rotation;
|
||||
@@ -415,24 +415,24 @@ function setElementRotation(element, rotation) {
|
||||
// ===========================================================================
|
||||
|
||||
function givePlayerHealth(client, amount) {
|
||||
if(getPlayerHealth(client)+amount > 100) {
|
||||
if (getPlayerHealth(client) + amount > 100) {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s health to 100`);
|
||||
setPlayerHealth(client, 100);
|
||||
} else {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s health to ${getPlayerHealth(client)+amount}`);
|
||||
setPlayerHealth(client, getPlayerHealth(client)+amount);
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s health to ${getPlayerHealth(client) + amount}`);
|
||||
setPlayerHealth(client, getPlayerHealth(client) + amount);
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function givePlayerArmour(client, amount) {
|
||||
if(getPlayerArmour(client)+amount > 100) {
|
||||
if (getPlayerArmour(client) + amount > 100) {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s armour to 100`);
|
||||
setPlayerArmour(client, 100);
|
||||
} else {
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s armour to ${getPlayerArmour(client)+amount}`);
|
||||
setPlayerArmour(client, getPlayerArmour(client)+amount);
|
||||
logToConsole(LOG_DEBUG, `Setting ${getPlayerDisplayForConsole(client)}'s armour to ${getPlayerArmour(client) + amount}`);
|
||||
setPlayerArmour(client, getPlayerArmour(client) + amount);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -469,7 +469,7 @@ function getServerName() {
|
||||
// ===========================================================================
|
||||
|
||||
function createGamePickup(modelIndex, position, type) {
|
||||
if(!isGameFeatureSupported("pickups")) {
|
||||
if (!isGameFeatureSupported("pickups")) {
|
||||
return false;
|
||||
}
|
||||
return game.createPickup(modelIndex, position, type);
|
||||
@@ -478,7 +478,7 @@ function createGamePickup(modelIndex, position, type) {
|
||||
// ===========================================================================
|
||||
|
||||
function createGameBlip(position, type = 0, size = 1, colour = toColour(255, 255, 255, 255)) {
|
||||
if(!isGameFeatureSupported("blips")) {
|
||||
if (!isGameFeatureSupported("blips")) {
|
||||
return false;
|
||||
}
|
||||
return game.createBlip(type, position, size, colour);
|
||||
@@ -487,7 +487,7 @@ function createGameBlip(position, type = 0, size = 1, colour = toColour(255, 255
|
||||
// ===========================================================================
|
||||
|
||||
function createGameObject(modelIndex, position) {
|
||||
if(!isGameFeatureSupported("objects")) {
|
||||
if (!isGameFeatureSupported("objects")) {
|
||||
return false;
|
||||
}
|
||||
return game.createObject(getGameConfig().objects[getGame()][modelIndex][0], position);
|
||||
@@ -496,13 +496,13 @@ function createGameObject(modelIndex, position) {
|
||||
// ===========================================================================
|
||||
|
||||
function setElementOnAllDimensions(element, state) {
|
||||
if(!isNull(element) && element != false) {
|
||||
if(typeof element.netFlags != "undefined") {
|
||||
if(typeof element.netFlags.onAllDimensions != "undefined") {
|
||||
if (!isNull(element) && element != false) {
|
||||
if (typeof element.netFlags != "undefined") {
|
||||
if (typeof element.netFlags.onAllDimensions != "undefined") {
|
||||
element.netFlags.onAllDimensions = state;
|
||||
}
|
||||
} else {
|
||||
if(typeof element.onAllDimensions != "undefined") {
|
||||
if (typeof element.onAllDimensions != "undefined") {
|
||||
element.onAllDimensions = state;
|
||||
}
|
||||
}
|
||||
@@ -512,7 +512,7 @@ function setElementOnAllDimensions(element, state) {
|
||||
// ===========================================================================
|
||||
|
||||
function destroyGameElement(element) {
|
||||
if(!isNull(element) && element != false) {
|
||||
if (!isNull(element) && element != false) {
|
||||
destroyElement(element);
|
||||
}
|
||||
}
|
||||
@@ -532,7 +532,7 @@ function getPlayerLastVehicle(client) {
|
||||
// ===========================================================================
|
||||
|
||||
function isVehicleObject(vehicle) {
|
||||
if(vehicle == null || vehicle == undefined) {
|
||||
if (vehicle == null || vehicle == undefined) {
|
||||
return false;
|
||||
}
|
||||
return (vehicle.type == ELEMENT_VEHICLE);
|
||||
@@ -600,11 +600,11 @@ function setVehicleColours(vehicle, colour1, colour2, colour3 = -1, colour4 = -1
|
||||
vehicle.colour1 = colour1;
|
||||
vehicle.colour2 = colour2;
|
||||
|
||||
if(colour3 != -1) {
|
||||
if (colour3 != -1) {
|
||||
vehicle.colour3 = colour3;
|
||||
}
|
||||
|
||||
if(colour4 != -1) {
|
||||
if (colour4 != -1) {
|
||||
vehicle.colour4 = colour4;
|
||||
}
|
||||
}
|
||||
@@ -612,7 +612,7 @@ function setVehicleColours(vehicle, colour1, colour2, colour3 = -1, colour4 = -1
|
||||
// ===========================================================================
|
||||
|
||||
function createGameVehicle(modelIndex, position, heading, toClient = null) {
|
||||
if(areServerElementsSupported()) {
|
||||
if (areServerElementsSupported()) {
|
||||
return game.createVehicle(getGameConfig().vehicles[getGame()][modelIndex][0], position, heading);
|
||||
}
|
||||
}
|
||||
@@ -620,9 +620,9 @@ function createGameVehicle(modelIndex, position, heading, toClient = null) {
|
||||
// ===========================================================================
|
||||
|
||||
function createGamePed(modelIndex, position, heading, toClient = null) {
|
||||
if(areServerElementsSupported()) {
|
||||
if (areServerElementsSupported()) {
|
||||
let ped = game.createPed(getGameConfig().skins[getGame()][modelIndex][0], position);
|
||||
if(ped) {
|
||||
if (ped) {
|
||||
//ped.position = position;
|
||||
ped.heading = heading;
|
||||
return ped;
|
||||
@@ -635,10 +635,10 @@ function createGamePed(modelIndex, position, heading, toClient = null) {
|
||||
// ===========================================================================
|
||||
|
||||
function getIsland(position) {
|
||||
if(getGame() == VRR_GAME_GTA_III) {
|
||||
if(position.x > 616) {
|
||||
if (getGame() == VRR_GAME_GTA_III) {
|
||||
if (position.x > 616) {
|
||||
return VRR_ISLAND_PORTLAND;
|
||||
} else if(position.x < -283) {
|
||||
} else if (position.x < -283) {
|
||||
return VRR_ISLAND_SHORESIDEVALE;
|
||||
}
|
||||
return VRR_ISLAND_STAUNTON;
|
||||
@@ -652,7 +652,7 @@ function getIsland(position) {
|
||||
// ===========================================================================
|
||||
|
||||
function isValidVehicleModel(model) {
|
||||
if(getVehicleModelIndexFromModel(model) != false) {
|
||||
if (getVehicleModelIndexFromModel(model) != false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -662,7 +662,7 @@ function isValidVehicleModel(model) {
|
||||
// ===========================================================================
|
||||
|
||||
function setGameTime(hour, minute, minuteDuration = 1000) {
|
||||
if(isTimeSupported()) {
|
||||
if (isTimeSupported()) {
|
||||
game.time.hour = hour;
|
||||
game.time.minute = minute;
|
||||
game.time.minuteDuration = minuteDuration;
|
||||
@@ -672,7 +672,7 @@ function setGameTime(hour, minute, minuteDuration = 1000) {
|
||||
// ===========================================================================
|
||||
|
||||
function setGameWeather(weather) {
|
||||
if(isWeatherSupported()) {
|
||||
if (isWeatherSupported()) {
|
||||
mp.world.weather = weather;
|
||||
}
|
||||
}
|
||||
@@ -680,11 +680,11 @@ function setGameWeather(weather) {
|
||||
// ===========================================================================
|
||||
|
||||
function setPlayerFightStyle(client, fightStyleId) {
|
||||
if(!isPlayerSpawned(client)) {
|
||||
if (!isPlayerSpawned(client)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!areFightStylesSupported()) {
|
||||
if (!areFightStylesSupported()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -738,7 +738,7 @@ function setElementCollisionsEnabled(element, state) {
|
||||
// ===========================================================================
|
||||
|
||||
function isTaxiVehicle(vehicle) {
|
||||
if(taxiModels[getGame()].indexOf(vehicle.modelIndex) != -1) {
|
||||
if (taxiModels[getGame()].indexOf(vehicle.modelIndex) != -1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -755,11 +755,11 @@ function getVehicleName(vehicle) {
|
||||
// ===========================================================================
|
||||
|
||||
function getElementModel(element) {
|
||||
if(typeof element.modelIndex != "undefined") {
|
||||
if (typeof element.modelIndex != "undefined") {
|
||||
return element.modelIndex;
|
||||
}
|
||||
|
||||
if(typeof element.model != "undefined") {
|
||||
if (typeof element.model != "undefined") {
|
||||
return element.model;
|
||||
}
|
||||
}
|
||||
@@ -773,7 +773,7 @@ function givePlayerWeaponAmmo(client, ammo) {
|
||||
// ===========================================================================
|
||||
|
||||
function getPlayerWeapon(client) {
|
||||
if(areServerElementsSupported(client)) {
|
||||
if (areServerElementsSupported(client)) {
|
||||
return getPlayerPed(client).weapon;
|
||||
} else {
|
||||
return getPlayerData(client).syncWeapon;
|
||||
@@ -783,11 +783,11 @@ function getPlayerWeapon(client) {
|
||||
// ===========================================================================
|
||||
|
||||
function connectToDatabase() {
|
||||
if(getDatabaseConfig().usePersistentConnection) {
|
||||
if(persistentDatabaseConnection == null) {
|
||||
if (getDatabaseConfig().usePersistentConnection) {
|
||||
if (persistentDatabaseConnection == null) {
|
||||
logToConsole(LOG_DEBUG, `[VRR.Database] Initializing database connection ...`);
|
||||
persistentDatabaseConnection = module.mysql.connect(getDatabaseConfig().host, getDatabaseConfig().user, getDatabaseConfig().pass, getDatabaseConfig().name, getDatabaseConfig().port);
|
||||
if(persistentDatabaseConnection.error) {
|
||||
if (persistentDatabaseConnection.error) {
|
||||
logToConsole(LOG_ERROR, `[VRR.Database] Database connection error: ${persistentDatabaseConnection.error}`);
|
||||
persistentDatabaseConnection = null;
|
||||
return false;
|
||||
@@ -801,7 +801,7 @@ function connectToDatabase() {
|
||||
}
|
||||
} else {
|
||||
let databaseConnection = module.mysql.connect(getDatabaseConfig().host, getDatabaseConfig().user, getDatabaseConfig().pass, getDatabaseConfig().name, getDatabaseConfig().port);
|
||||
if(databaseConnection.error) {
|
||||
if (databaseConnection.error) {
|
||||
logToConsole(LOG_ERROR, `[VRR.Database] Database connection error: ${persistentDatabaseConnection.error}`);
|
||||
return false;
|
||||
} else {
|
||||
@@ -813,11 +813,11 @@ function connectToDatabase() {
|
||||
// ===========================================================================
|
||||
|
||||
function disconnectFromDatabase(dbConnection) {
|
||||
if(!getDatabaseConfig().usePersistentConnection) {
|
||||
if (!getDatabaseConfig().usePersistentConnection) {
|
||||
try {
|
||||
dbConnection.close();
|
||||
logToConsole(LOG_DEBUG, `[VRR.Database] Database connection closed successfully`);
|
||||
} catch(error) {
|
||||
} catch (error) {
|
||||
logToConsole(LOG_ERROR, `[VRR.Database] Database connection could not be closed! (Error: ${error})`);
|
||||
}
|
||||
}
|
||||
@@ -828,7 +828,7 @@ function disconnectFromDatabase(dbConnection) {
|
||||
|
||||
function queryDatabase(dbConnection, queryString, useThread = false) {
|
||||
logToConsole(LOG_DEBUG, `[VRR.Database] Query string: ${queryString}`);
|
||||
if(useThread == true) {
|
||||
if (useThread == true) {
|
||||
Promise.resolve().then(() => {
|
||||
let queryResult = dbConnection.query(queryString);
|
||||
return queryResult;
|
||||
@@ -841,11 +841,11 @@ function queryDatabase(dbConnection, queryString, useThread = false) {
|
||||
// ===========================================================================
|
||||
|
||||
function escapeDatabaseString(dbConnection, unsafeString = "") {
|
||||
if(!dbConnection) {
|
||||
if (!dbConnection) {
|
||||
dbConnection = connectToDatabase();
|
||||
}
|
||||
|
||||
if(typeof unsafeString == "string") {
|
||||
if (typeof unsafeString == "string") {
|
||||
return dbConnection.escapeString(unsafeString);
|
||||
}
|
||||
return unsafeString;
|
||||
@@ -872,7 +872,7 @@ function getDatabaseError(dbConnection) {
|
||||
// ===========================================================================
|
||||
|
||||
function freeDatabaseQuery(dbQuery) {
|
||||
if(dbQuery != null) {
|
||||
if (dbQuery != null) {
|
||||
dbQuery.free();
|
||||
}
|
||||
return;
|
||||
@@ -889,26 +889,26 @@ function fetchQueryAssoc(dbQuery) {
|
||||
function quickDatabaseQuery(queryString) {
|
||||
let dbConnection = connectToDatabase();
|
||||
let insertId = 0;
|
||||
if(dbConnection) {
|
||||
if (dbConnection) {
|
||||
//logToConsole(LOG_DEBUG, `[VRR.Database] Query string: ${queryString}`);
|
||||
let dbQuery = queryDatabase(dbConnection, queryString);
|
||||
if(getDatabaseInsertId(dbConnection)) {
|
||||
if (getDatabaseInsertId(dbConnection)) {
|
||||
insertId = getDatabaseInsertId(dbConnection);
|
||||
logToConsole(LOG_DEBUG, `[VRR.Database] Query returned insert id ${insertId}`);
|
||||
}
|
||||
|
||||
if(dbQuery) {
|
||||
if (dbQuery) {
|
||||
try {
|
||||
freeDatabaseQuery(dbQuery);
|
||||
logToConsole(LOG_DEBUG, `[VRR.Database] Query result free'd successfully`);
|
||||
} catch(error) {
|
||||
} catch (error) {
|
||||
logToConsole(LOG_ERROR, `[VRR.Database] Query result could not be free'd! (Error: ${error})`);
|
||||
}
|
||||
}
|
||||
|
||||
disconnectFromDatabase(dbConnection);
|
||||
|
||||
if(insertId != 0) {
|
||||
if (insertId != 0) {
|
||||
return insertId;
|
||||
}
|
||||
|
||||
@@ -920,26 +920,26 @@ function quickDatabaseQuery(queryString) {
|
||||
// ===========================================================================
|
||||
|
||||
function executeDatabaseQueryCommand(command, params, client) {
|
||||
if(areParamsEmpty(params)) {
|
||||
if (areParamsEmpty(params)) {
|
||||
messagePlayerSyntax(client, getCommandSyntaxText(command));
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!targetClient) {
|
||||
if (!targetClient) {
|
||||
messagePlayerError(client, "That player was not found!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(targetCode == "") {
|
||||
if (targetCode == "") {
|
||||
messagePlayerError(client, "You didn't enter any code!");
|
||||
return false;
|
||||
}
|
||||
|
||||
let success = quickDatabaseQuery(params);
|
||||
|
||||
if(!success) {
|
||||
if (!success) {
|
||||
messagePlayerAlert(client, `Database query failed to execute: {ALTCOLOUR}${query}`);
|
||||
} else if(typeof success != "boolean") {
|
||||
} else if (typeof success != "boolean") {
|
||||
messagePlayeSuccess(client, `Database query successful: {ALTCOLOUR}${query}`);
|
||||
messagePlayerInfo(client, `Returns: ${success}`);
|
||||
} else {
|
||||
@@ -953,9 +953,9 @@ function executeDatabaseQueryCommand(command, params, client) {
|
||||
function setConstantsAsGlobalVariablesInDatabase() {
|
||||
let dbConnection = connectToDatabase();
|
||||
let entries = Object.entries(global);
|
||||
for(let i in entries) {
|
||||
for (let i in entries) {
|
||||
logToConsole(LOG_DEBUG, `[VRR.Database] Checking entry ${i} (${entries[i]})`);
|
||||
if(toString(i).slice(0, 3).indexOf("VRR_") != -1) {
|
||||
if (toString(i).slice(0, 3).indexOf("VRR_") != -1) {
|
||||
logToConsole(LOG_DEBUG, `[VRR.Database] Adding ${i} (${entries[i]}) to database global variables`);
|
||||
}
|
||||
}
|
||||
@@ -967,13 +967,13 @@ function createDatabaseInsertQuery(tableName, data) {
|
||||
let fields = [];
|
||||
let values = [];
|
||||
|
||||
for(let i in data) {
|
||||
if(data[i][1] != "undefined" && data[i][1] != NaN && data[i][0] != 'NaN') {
|
||||
if(data[i][1] != "undefined" && data[i][1] != NaN && data[i][1] != 'NaN') {
|
||||
for (let i in data) {
|
||||
if (data[i][1] != "undefined" && data[i][1] != NaN && data[i][0] != 'NaN') {
|
||||
if (data[i][1] != "undefined" && data[i][1] != NaN && data[i][1] != 'NaN') {
|
||||
fields.push(data[i][0]);
|
||||
|
||||
if(typeof data[i][1] == "string") {
|
||||
if(data[i][1] == "{UNIXTIMESTAMP}") {
|
||||
if (typeof data[i][1] == "string") {
|
||||
if (data[i][1] == "{UNIXTIMESTAMP}") {
|
||||
values.push("UNIX_TIMESTAMP()");
|
||||
} else {
|
||||
values.push(`'${data[i][1]}'`);
|
||||
@@ -994,11 +994,11 @@ function createDatabaseInsertQuery(tableName, data) {
|
||||
function createDatabaseUpdateQuery(tableName, data, whereClause) {
|
||||
let values = [];
|
||||
|
||||
for(let i in data) {
|
||||
if(data[i][0] != "undefined" && data[i][0] != NaN && data[i][0] != 'NaN') {
|
||||
if(data[i][1] != "undefined" && data[i][1] != NaN && data[i][1] != 'NaN') {
|
||||
if(typeof data[i][1] == "string") {
|
||||
if(data[i][1] == "{UNIXTIMESTAMP}") {
|
||||
for (let i in data) {
|
||||
if (data[i][0] != "undefined" && data[i][0] != NaN && data[i][0] != 'NaN') {
|
||||
if (data[i][1] != "undefined" && data[i][1] != NaN && data[i][1] != 'NaN') {
|
||||
if (typeof data[i][1] == "string") {
|
||||
if (data[i][1] == "{UNIXTIMESTAMP}") {
|
||||
values.push(`${data[i][0]}=UNIX_TIMESTAMP()`);
|
||||
} else {
|
||||
values.push(`${data[i][0]}='${data[i][1]}'`);
|
||||
@@ -1038,8 +1038,8 @@ function getElementId(element) {
|
||||
|
||||
function getClientFromIndex(index) {
|
||||
let clients = getClients();
|
||||
for(let i in clients) {
|
||||
if(clients[i].index == index) {
|
||||
for (let i in clients) {
|
||||
if (clients[i].index == index) {
|
||||
return clients[i];
|
||||
}
|
||||
}
|
||||
@@ -1078,7 +1078,7 @@ function getClosestCivilian(position) {
|
||||
// ===========================================================================
|
||||
|
||||
function getVehiclesInRange(position, range) {
|
||||
if(getGame() == VRR_GAME_GTA_IV) {
|
||||
if (getGame() == VRR_GAME_GTA_IV) {
|
||||
return getServerData().vehicles.reduce((i, j) => (getDistance(position, i.syncPosition) <= getDistance(position, j.syncPosition)) ? i : j);
|
||||
}
|
||||
return getElementsByTypeInRange(ELEMENT_VEHICLE, position, range);
|
||||
@@ -1099,8 +1099,8 @@ function getClosestElementByType(elementType, position) {
|
||||
// ===========================================================================
|
||||
|
||||
function getVehicleFirstEmptySeat(vehicle) {
|
||||
for(let i = 0; i <= 4; i++) {
|
||||
if(vehicle.getOccupant(i) == null) {
|
||||
for (let i = 0; i <= 4; i++) {
|
||||
if (vehicle.getOccupant(i) == null) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@@ -1111,8 +1111,8 @@ function getVehicleFirstEmptySeat(vehicle) {
|
||||
// ===========================================================================
|
||||
|
||||
function isVehicleTrain(vehicle) {
|
||||
if(getGame() == VRR_GAME_GTA_III) {
|
||||
if(vehicle.modelIndex == 124) {
|
||||
if (getGame() == VRR_GAME_GTA_III) {
|
||||
if (vehicle.modelIndex == 124) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1155,9 +1155,9 @@ function setPlayerWantedLevel(client, wantedLevel) {
|
||||
// ===========================================================================
|
||||
|
||||
function setElementStreamInDistance(element, distance) {
|
||||
if(!isNull(element) && element != false) {
|
||||
if(typeof element == "Entity") {
|
||||
if(typeof element.streamInDistance != "undefined") {
|
||||
if (!isNull(element) && element != false) {
|
||||
if (typeof element == "Entity") {
|
||||
if (typeof element.streamInDistance != "undefined") {
|
||||
element.streamInDistance = distance;
|
||||
}
|
||||
}
|
||||
@@ -1167,9 +1167,9 @@ function setElementStreamInDistance(element, distance) {
|
||||
// ===========================================================================
|
||||
|
||||
function setElementStreamOutDistance(element, distance) {
|
||||
if(!isNull(element) && element != false) {
|
||||
if(typeof element == "Entity") {
|
||||
if(typeof element.streamOutDistance != "undefined") {
|
||||
if (!isNull(element) && element != false) {
|
||||
if (typeof element == "Entity") {
|
||||
if (typeof element.streamOutDistance != "undefined") {
|
||||
element.streamOutDistance = distance;
|
||||
}
|
||||
}
|
||||
@@ -1179,7 +1179,7 @@ function setElementStreamOutDistance(element, distance) {
|
||||
// ===========================================================================
|
||||
|
||||
function getPlayerPed(client) {
|
||||
if(getGame() == VRR_GAME_GTA_IV) {
|
||||
if (getGame() == VRR_GAME_GTA_IV) {
|
||||
return getPlayerData(client).ped;
|
||||
} else {
|
||||
return client.player;
|
||||
@@ -1189,8 +1189,8 @@ function getPlayerPed(client) {
|
||||
// ===========================================================================
|
||||
|
||||
function setEntityData(entity, dataName, dataValue, syncToClients = true) {
|
||||
if(entity != null) {
|
||||
if(areServerElementsSupported()) {
|
||||
if (entity != null) {
|
||||
if (areServerElementsSupported()) {
|
||||
return entity.setData(dataName, dataValue, syncToClients);
|
||||
}
|
||||
}
|
||||
@@ -1200,8 +1200,8 @@ function setEntityData(entity, dataName, dataValue, syncToClients = true) {
|
||||
// ===========================================================================
|
||||
|
||||
function removeEntityData(entity, dataName) {
|
||||
if(entity != null) {
|
||||
if(areServerElementsSupported()) {
|
||||
if (entity != null) {
|
||||
if (areServerElementsSupported()) {
|
||||
return entity.removeData(dataName);
|
||||
}
|
||||
}
|
||||
@@ -1211,8 +1211,8 @@ function removeEntityData(entity, dataName) {
|
||||
// ===========================================================================
|
||||
|
||||
function doesEntityDataExist(entity, dataName) {
|
||||
if(entity != null) {
|
||||
if(areServerElementsSupported()) {
|
||||
if (entity != null) {
|
||||
if (areServerElementsSupported()) {
|
||||
return (entity.getData(dataName) != null);
|
||||
} else {
|
||||
return false;
|
||||
@@ -1266,7 +1266,7 @@ function getGame() {
|
||||
// ===========================================================================
|
||||
|
||||
function getCountryNameFromIP(ip) {
|
||||
if(module.geoip.getCountryName(ip)) {
|
||||
if (module.geoip.getCountryName(ip)) {
|
||||
return module.geoip.getCountryName(ip);
|
||||
}
|
||||
return false;
|
||||
@@ -1331,9 +1331,9 @@ function addServerCommandHandler(command, handlerFunction) {
|
||||
// ===========================================================================
|
||||
|
||||
function addServerEventHandler(eventName, handlerFunction) {
|
||||
addEventHandler(eventName, function(event, ...args) {
|
||||
addEventHandler(eventName, function (event, ...args) {
|
||||
let result = handlerFunction.apply(this, args);
|
||||
if(result == false) {
|
||||
if (result == false) {
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
@@ -1342,9 +1342,9 @@ function addServerEventHandler(eventName, handlerFunction) {
|
||||
// ===========================================================================
|
||||
|
||||
function bindServerEventHandler(eventName, bindTo, handlerFunction) {
|
||||
addEventHandler(eventName, bindTo, function(event, ...args) {
|
||||
addEventHandler(eventName, bindTo, function (event, ...args) {
|
||||
let result = handlerFunction.apply(this, args);
|
||||
if(result == false) {
|
||||
if (result == false) {
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
@@ -1374,4 +1374,12 @@ function setElementShownByDefault(element, state) {
|
||||
element.netFlags.defaultExistance = state;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function createAttachedGameBlip(element, type, size, colour = toColour(255, 255, 255, 255)) {
|
||||
if (isGameFeatureSupported("attachedBlips")) {
|
||||
return game.createBlipAttachedTo(element, type, size, colour, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
Reference in New Issue
Block a user