Merge branch 'nightly' into ragemp
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,7 @@
|
||||
// ===========================================================================
|
||||
// Vortrex's Roleplay Resource
|
||||
// https://github.com/VortrexFTW/gtac_roleplay
|
||||
// Asshat Gaming Roleplay
|
||||
// https://github.com/VortrexFTW/agrp_main
|
||||
// (c) 2022 Asshat Gaming
|
||||
// ===========================================================================
|
||||
// FILE: connected.js
|
||||
// DESC: Provides wrapped natives for GTA Connected and Mafia Connected mods
|
||||
@@ -22,28 +23,11 @@ let builtInCommands = [
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
let disconnectReasons = [
|
||||
"Lost Connection",
|
||||
"Disconnected",
|
||||
"Unsupported Client",
|
||||
"Wrong Game",
|
||||
"Incorrect Password",
|
||||
"Unsupported Executable",
|
||||
"Disconnected",
|
||||
"Banned",
|
||||
"Failed",
|
||||
"Invalid Name",
|
||||
"Crashed",
|
||||
"Modified Game"
|
||||
];
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
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 +43,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 +62,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 +75,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 +94,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 +108,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 +116,7 @@ function setPlayerInterior(client, interior) {
|
||||
// ===========================================================================
|
||||
|
||||
function isPlayerInAnyVehicle(client) {
|
||||
if(!areServerElementsSupported()) {
|
||||
if (!areServerElementsSupported()) {
|
||||
return (getPlayerData().syncVehicle != null);
|
||||
} else {
|
||||
return (getPlayerPed(client).vehicle != null);
|
||||
@@ -142,15 +126,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,8 +164,8 @@ function getVehicleHeading(vehicle) {
|
||||
// ===========================================================================
|
||||
|
||||
function setVehicleHeading(vehicle, heading) {
|
||||
if(getGame() == VRR_GAME_GTA_IV) {
|
||||
return sendNetworkEventToPlayer("vrr.vehPosition", null, getVehicleForNetworkEvent(vehicle), heading);
|
||||
if (getGame() == AGRP_GAME_GTA_IV) {
|
||||
return sendNetworkEventToPlayer("agrp.vehPosition", null, getVehicleForNetworkEvent(vehicle), heading);
|
||||
}
|
||||
return vehicle.heading = heading;
|
||||
}
|
||||
@@ -189,20 +173,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 +198,8 @@ function getVehicleSyncer(vehicle) {
|
||||
// ===========================================================================
|
||||
|
||||
function getVehicleForNetworkEvent(vehicle) {
|
||||
if(getGame() == VRR_GAME_GTA_IV) {
|
||||
if(getVehicleData(vehicle).ivNetworkId != -1) {
|
||||
if (getGame() == AGRP_GAME_GTA_IV) {
|
||||
if (getVehicleData(vehicle).ivNetworkId != -1) {
|
||||
return getVehicleData(vehicle).ivNetworkId;
|
||||
}
|
||||
return -1;
|
||||
@@ -227,11 +211,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,8 +238,8 @@ 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) {
|
||||
triggerNetworkEvent("vrr.localPlayerSkin", client, getGameConfig().skins[getGame()][skinIndex][0]);
|
||||
if (getGame() == AGRP_GAME_GTA_IV) {
|
||||
triggerNetworkEvent("agrp.localPlayerSkin", client, getGameConfig().skins[getGame()][skinIndex][0]);
|
||||
} else {
|
||||
getPlayerPed(client).modelIndex = getGameConfig().skins[getGame()][skinIndex][0];
|
||||
}
|
||||
@@ -264,7 +248,7 @@ function setPlayerSkin(client, skinIndex) {
|
||||
// ===========================================================================
|
||||
|
||||
function getPlayerSkin(client) {
|
||||
return getSkinIndexFromModel(client.player.modelIndex);
|
||||
return getPlayerCurrentSubAccount(client).skin; //getSkinIndexFromModel(client.player.modelIndex);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -292,7 +276,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 +286,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 +301,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 +316,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 +352,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 +360,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 +369,7 @@ function getPlayerVelocity(client) {
|
||||
// ===========================================================================
|
||||
|
||||
function getElementDimension(element) {
|
||||
if(typeof element.dimension != "undefined") {
|
||||
if (typeof element.dimension != "undefined") {
|
||||
return element.dimension;
|
||||
}
|
||||
return 0;
|
||||
@@ -394,18 +378,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 +399,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 +453,7 @@ function getServerName() {
|
||||
// ===========================================================================
|
||||
|
||||
function createGamePickup(modelIndex, position, type) {
|
||||
if(!isGameFeatureSupported("pickups")) {
|
||||
if (!isGameFeatureSupported("pickup")) {
|
||||
return false;
|
||||
}
|
||||
return game.createPickup(modelIndex, position, type);
|
||||
@@ -478,7 +462,7 @@ function createGamePickup(modelIndex, position, type) {
|
||||
// ===========================================================================
|
||||
|
||||
function createGameBlip(position, type = 0, colour = toColour(255, 255, 255, 255)) {
|
||||
if(!isGameFeatureSupported("blips")) {
|
||||
if (!isGameFeatureSupported("blip")) {
|
||||
return false;
|
||||
}
|
||||
return game.createBlip(type, position, 1, colour);
|
||||
@@ -487,7 +471,7 @@ function createGameBlip(position, type = 0, colour = toColour(255, 255, 255, 255
|
||||
// ===========================================================================
|
||||
|
||||
function createGameObject(modelIndex, position) {
|
||||
if(!isGameFeatureSupported("objects")) {
|
||||
if (!isGameFeatureSupported("object")) {
|
||||
return false;
|
||||
}
|
||||
return game.createObject(getGameConfig().objects[getGame()][modelIndex][0], position);
|
||||
@@ -496,13 +480,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 +496,7 @@ function setElementOnAllDimensions(element, state) {
|
||||
// ===========================================================================
|
||||
|
||||
function destroyGameElement(element) {
|
||||
if(!isNull(element) && element != false) {
|
||||
if (!isNull(element) && element != false) {
|
||||
destroyElement(element);
|
||||
}
|
||||
}
|
||||
@@ -532,7 +516,7 @@ function getPlayerLastVehicle(client) {
|
||||
// ===========================================================================
|
||||
|
||||
function isVehicleObject(vehicle) {
|
||||
if(vehicle == null || vehicle == undefined) {
|
||||
if (vehicle == null || vehicle == undefined) {
|
||||
return false;
|
||||
}
|
||||
return (vehicle.type == ELEMENT_VEHICLE);
|
||||
@@ -547,15 +531,15 @@ function repairVehicle(vehicle) {
|
||||
// ===========================================================================
|
||||
|
||||
function setVehicleLights(vehicle, lights) {
|
||||
setEntityData(vehicle, "vrr.lights", lights, true);
|
||||
sendNetworkEventToPlayer("vrr.veh.lights", null, vehicle.id, lights);
|
||||
setEntityData(vehicle, "agrp.lights", lights, true);
|
||||
sendNetworkEventToPlayer("agrp.veh.lights", null, vehicle.id, lights);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function setVehicleEngine(vehicle, engine) {
|
||||
vehicle.engine = engine;
|
||||
setEntityData(vehicle, "vrr.engine", engine, true);
|
||||
setEntityData(vehicle, "agrp.engine", engine, true);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -600,11 +584,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 +596,7 @@ function setVehicleColours(vehicle, colour1, colour2, colour3 = -1, colour4 = -1
|
||||
// ===========================================================================
|
||||
|
||||
function createGameVehicle(modelIndex, position, heading) {
|
||||
if(areServerElementsSupported()) {
|
||||
if (areServerElementsSupported()) {
|
||||
return mp.vehicles.new(getGameConfig().vehicles[getGame()][modelIndex][0], position, {
|
||||
heading: heading,
|
||||
numberPlate: "",
|
||||
@@ -628,7 +612,7 @@ function createGameVehicle(modelIndex, position, heading) {
|
||||
// ===========================================================================
|
||||
|
||||
function createGameCivilian(modelIndex, position, heading) {
|
||||
if(areServerElementsSupported()) {
|
||||
if (areServerElementsSupported()) {
|
||||
return mp.peds.new(getGameConfig().skins[getGame()][modelIndex][1], position, heading, 0);
|
||||
}
|
||||
|
||||
@@ -644,7 +628,7 @@ function getIsland(position) {
|
||||
// ===========================================================================
|
||||
|
||||
function isValidVehicleModel(model) {
|
||||
if(getVehicleModelIndexFromModel(model) != false) {
|
||||
if (getVehicleModelIndexFromModel(model) != false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -654,7 +638,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;
|
||||
@@ -664,7 +648,7 @@ function setGameTime(hour, minute, minuteDuration = 1000) {
|
||||
// ===========================================================================
|
||||
|
||||
function setGameWeather(weather) {
|
||||
if(isWeatherSupported()) {
|
||||
if (isWeatherSupported()) {
|
||||
mp.world.weather = weather;
|
||||
}
|
||||
}
|
||||
@@ -690,7 +674,7 @@ function getPlayerElement(client) {
|
||||
// ===========================================================================
|
||||
|
||||
function setElementPosition(element, position) {
|
||||
sendNetworkEventToPlayer("vrr.elementPosition", null, element.id, position);
|
||||
sendNetworkEventToPlayer("agrp.elementPosition", null, element.id, position);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -714,13 +698,13 @@ function setElementInterior(element, interior) {
|
||||
// ===========================================================================
|
||||
|
||||
function setElementCollisionsEnabled(element, state) {
|
||||
//sendNetworkEventToPlayer("vrr.elementCollisions", null, element.id, state);
|
||||
//sendNetworkEventToPlayer("agrp.elementCollisions", null, element.id, state);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function isTaxiVehicle(vehicle) {
|
||||
if(getGameConfig().taxiModels[getGame()].indexOf(vehicle.modelIndex) != -1) {
|
||||
if (getGameConfig().taxiModels[getGame()].indexOf(vehicle.modelIndex) != -1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -737,7 +721,7 @@ function getVehicleName(vehicle) {
|
||||
// ===========================================================================
|
||||
|
||||
function getElementModel(element) {
|
||||
if(typeof element.model != "undefined") {
|
||||
if (typeof element.model != "undefined") {
|
||||
return element.model;
|
||||
}
|
||||
}
|
||||
@@ -757,26 +741,26 @@ function getPlayerWeapon(client) {
|
||||
// ===========================================================================
|
||||
|
||||
function connectToDatabase() {
|
||||
if(getDatabaseConfig().usePersistentConnection) {
|
||||
if(persistentDatabaseConnection == null) {
|
||||
logToConsole(LOG_DEBUG, `[VRR.Database] Initializing database connection ...`);
|
||||
if (getDatabaseConfig().usePersistentConnection) {
|
||||
if (persistentDatabaseConnection == null) {
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Database] Initializing database connection ...`);
|
||||
persistentDatabaseConnection = module.mysql.connect(getDatabaseConfig().host, getDatabaseConfig().user, getDatabaseConfig().pass, getDatabaseConfig().name, getDatabaseConfig().port);
|
||||
if(persistentDatabaseConnection.error) {
|
||||
logToConsole(LOG_ERROR, `[VRR.Database] Database connection error: ${persistentDatabaseConnection.error}`);
|
||||
if (persistentDatabaseConnection.error) {
|
||||
logToConsole(LOG_ERROR, `[AGRP.Database] Database connection error: ${persistentDatabaseConnection.error}`);
|
||||
persistentDatabaseConnection = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
logToConsole(LOG_DEBUG, `[VRR.Database] Database connection successful!`);
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Database] Database connection successful!`);
|
||||
return persistentDatabaseConnection;
|
||||
} else {
|
||||
logToConsole(LOG_DEBUG, `[VRR.Database] Using existing database connection.`);
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Database] Using existing database connection.`);
|
||||
return persistentDatabaseConnection;
|
||||
}
|
||||
} else {
|
||||
let databaseConnection = module.mysql.connect(getDatabaseConfig().host, getDatabaseConfig().user, getDatabaseConfig().pass, getDatabaseConfig().name, getDatabaseConfig().port);
|
||||
if(databaseConnection.error) {
|
||||
logToConsole(LOG_ERROR, `[VRR.Database] Database connection error: ${persistentDatabaseConnection.error}`);
|
||||
if (databaseConnection.error) {
|
||||
logToConsole(LOG_ERROR, `[AGRP.Database] Database connection error: ${persistentDatabaseConnection.error}`);
|
||||
return false;
|
||||
} else {
|
||||
return databaseConnection;
|
||||
@@ -787,12 +771,12 @@ 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) {
|
||||
logToConsole(LOG_ERROR, `[VRR.Database] Database connection could not be closed! (Error: ${error})`);
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Database] Database connection closed successfully`);
|
||||
} catch (error) {
|
||||
logToConsole(LOG_ERROR, `[AGRP.Database] Database connection could not be closed! (Error: ${error})`);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@@ -801,8 +785,8 @@ function disconnectFromDatabase(dbConnection) {
|
||||
// ===========================================================================
|
||||
|
||||
function queryDatabase(dbConnection, queryString, useThread = false) {
|
||||
logToConsole(LOG_DEBUG, `[VRR.Database] Query string: ${queryString}`);
|
||||
if(useThread == true) {
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Database] Query string: ${queryString}`);
|
||||
if (useThread == true) {
|
||||
Promise.resolve().then(() => {
|
||||
let queryResult = dbConnection.query(queryString);
|
||||
return queryResult;
|
||||
@@ -815,11 +799,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;
|
||||
@@ -846,7 +830,7 @@ function getDatabaseError(dbConnection) {
|
||||
// ===========================================================================
|
||||
|
||||
function freeDatabaseQuery(dbQuery) {
|
||||
if(dbQuery != null) {
|
||||
if (dbQuery != null) {
|
||||
dbQuery.free();
|
||||
}
|
||||
return;
|
||||
@@ -863,26 +847,26 @@ function fetchQueryAssoc(dbQuery) {
|
||||
function quickDatabaseQuery(queryString) {
|
||||
let dbConnection = connectToDatabase();
|
||||
let insertId = 0;
|
||||
if(dbConnection) {
|
||||
//logToConsole(LOG_DEBUG, `[VRR.Database] Query string: ${queryString}`);
|
||||
if (dbConnection) {
|
||||
//logToConsole(LOG_DEBUG, `[AGRP.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}`);
|
||||
logToConsole(LOG_DEBUG, `[AGRP.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) {
|
||||
logToConsole(LOG_ERROR, `[VRR.Database] Query result could not be free'd! (Error: ${error})`);
|
||||
logToConsole(LOG_DEBUG, `[AGRP.Database] Query result free'd successfully`);
|
||||
} catch (error) {
|
||||
logToConsole(LOG_ERROR, `[AGRP.Database] Query result could not be free'd! (Error: ${error})`);
|
||||
}
|
||||
}
|
||||
|
||||
disconnectFromDatabase(dbConnection);
|
||||
|
||||
if(insertId != 0) {
|
||||
if (insertId != 0) {
|
||||
return insertId;
|
||||
}
|
||||
|
||||
@@ -915,8 +899,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];
|
||||
}
|
||||
}
|
||||
@@ -955,7 +939,7 @@ function getClosestCivilian(position) {
|
||||
// ===========================================================================
|
||||
|
||||
function getVehiclesInRange(position, range) {
|
||||
if(getGame() == VRR_GAME_GTA_IV) {
|
||||
if (getGame() == AGRP_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);
|
||||
@@ -976,8 +960,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;
|
||||
}
|
||||
}
|
||||
@@ -1013,15 +997,15 @@ function setVehicleHealth(vehicle, health) {
|
||||
// ===========================================================================
|
||||
|
||||
function givePlayerWeapon(client, weaponId, ammo, active = true) {
|
||||
//logToConsole(LOG_DEBUG, `[VRR.Client] Sending signal to ${getPlayerDisplayForConsole(client)} to give weapon (Weapon: ${weaponId}, Ammo: ${ammo})`);
|
||||
//sendNetworkEventToPlayer("vrr.giveWeapon", client, weaponId, ammo, active);
|
||||
//logToConsole(LOG_DEBUG, `[AGRP.Client] Sending signal to ${getPlayerDisplayForConsole(client)} to give weapon (Weapon: ${weaponId}, Ammo: ${ammo})`);
|
||||
//sendNetworkEventToPlayer("agrp.giveWeapon", client, weaponId, ammo, active);
|
||||
client.giveWeapon(weaponId, ammo);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function setPlayerWantedLevel(client, wantedLevel) {
|
||||
//sendNetworkEventToPlayer("vrr.wantedLevel", client, wantedLevel);
|
||||
//sendNetworkEventToPlayer("agrp.wantedLevel", client, wantedLevel);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1046,9 +1030,9 @@ function getPlayerPed(client) {
|
||||
// ===========================================================================
|
||||
|
||||
function setEntityData(entity, dataName, dataValue, syncToClients = true) {
|
||||
if(entity != null) {
|
||||
if(areServerElementsSupported()) {
|
||||
if(syncToClients) {
|
||||
if (entity != null) {
|
||||
if (areServerElementsSupported()) {
|
||||
if (syncToClients) {
|
||||
return entity.setVariable(dataName, dataValue);
|
||||
} else {
|
||||
return entity.setOwnVariable(dataName, dataValue);
|
||||
@@ -1061,8 +1045,8 @@ function setEntityData(entity, dataName, dataValue, syncToClients = true) {
|
||||
// ===========================================================================
|
||||
|
||||
function removeEntityData(entity, dataName) {
|
||||
if(entity != null) {
|
||||
if(areServerElementsSupported()) {
|
||||
if (entity != null) {
|
||||
if (areServerElementsSupported()) {
|
||||
return entity.setVariable(dataName, null);
|
||||
}
|
||||
}
|
||||
@@ -1072,8 +1056,8 @@ function removeEntityData(entity, dataName) {
|
||||
// ===========================================================================
|
||||
|
||||
function doesEntityDataExist(entity, dataName) {
|
||||
if(entity != null) {
|
||||
if(areServerElementsSupported()) {
|
||||
if (entity != null) {
|
||||
if (areServerElementsSupported()) {
|
||||
return (entity.getVariable(dataName) != null);
|
||||
} else {
|
||||
return false;
|
||||
@@ -1124,7 +1108,7 @@ function despawnPlayer(client) {
|
||||
// ===========================================================================
|
||||
|
||||
function getGame() {
|
||||
return VRR_GAME_GTA_V;
|
||||
return AGRP_GAME_GTA_V;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -1169,7 +1153,7 @@ function serverBanIP(ip) {
|
||||
// ===========================================================================
|
||||
|
||||
function setVehicleTrunkState(vehicle, trunkState) {
|
||||
//sendNetworkEventToPlayer("vrr.veh.trunk", null, getVehicleForNetworkEvent(vehicle), trunkState);
|
||||
//sendNetworkEventToPlayer("agrp.veh.trunk", null, getVehicleForNetworkEvent(vehicle), trunkState);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -1201,7 +1185,7 @@ function addAllEventHandlers() {
|
||||
// ===========================================================================
|
||||
|
||||
function addServerCommandHandler(command, handlerFunction) {
|
||||
mp.events.addCommand(command, function(client, ...args) {
|
||||
mp.events.addCommand(command, function (client, ...args) {
|
||||
handlerFunction.call(command, args.join(" "), client);
|
||||
});
|
||||
}
|
||||
@@ -1209,7 +1193,7 @@ function addServerCommandHandler(command, handlerFunction) {
|
||||
// ===========================================================================
|
||||
|
||||
function addServerEventHandler(eventName, handlerFunction) {
|
||||
mp.events.add(eventName, function(event, ...args) {
|
||||
mp.events.add(eventName, function (event, ...args) {
|
||||
let result = handlerFunction.apply(this, args);
|
||||
});
|
||||
}
|
||||
@@ -1217,7 +1201,7 @@ function addServerEventHandler(eventName, handlerFunction) {
|
||||
// ===========================================================================
|
||||
|
||||
function bindServerEventHandler(eventName, bindTo, handlerFunction) {
|
||||
mp.events.add(eventName, function(event, ...args) {
|
||||
mp.events.add(eventName, function (event, ...args) {
|
||||
let result = handlerFunction.apply(this, args);
|
||||
});
|
||||
}
|
||||
@@ -1243,7 +1227,44 @@ function showElementForPlayer(element, client) {
|
||||
// ===========================================================================
|
||||
|
||||
function setElementShownByDefault(element, state) {
|
||||
element.netFlags.defaultExistance(state);
|
||||
element.netFlags.defaultExistance = state;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function createAttachedGameBlip(element, type, size, colour = toColour(255, 255, 255, 255)) {
|
||||
if (isGameFeatureSupported("attachedBlip")) {
|
||||
return game.createBlipAttachedTo(element, type, size, colour, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function deletePlayerPed(client) {
|
||||
if (areServerElementsSupported()) {
|
||||
destroyElement(client.player);
|
||||
} else {
|
||||
sendNetworkEventToPlayer("agrp.deleteLocalPlayerPed", client);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function isPlayerOnBoat(client) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function setServerName(name) {
|
||||
server.name = name;
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function setServerPassword(password) {
|
||||
server.setPassword(password);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
Reference in New Issue
Block a user