Bunch of stuff
This commit is contained in:
@@ -72,6 +72,7 @@ let globalConfig = {
|
||||
vehicleInactiveRespawnDelay: 1800000, // 20 minutes
|
||||
chatSectionHeaderLength: 96,
|
||||
useServerSideVehiclePurchaseCheck: true,
|
||||
useServerSideVehicleBurnCheck: false,
|
||||
businessPickupStreamInDistance: 100,
|
||||
businessPickupStreamOutDistance: 120,
|
||||
housePickupStreamInDistance: 100,
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
let scriptVersion = "1.1";
|
||||
let serverStartTime = 0;
|
||||
let logLevel = LOG_INFO|LOG_ERROR|LOG_WARN|LOG_DEBUG;
|
||||
let logLevel = LOG_INFO|LOG_ERROR|LOG_WARN;
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
@@ -20,8 +20,6 @@ let logLevel = LOG_INFO|LOG_ERROR|LOG_WARN|LOG_DEBUG;
|
||||
* @property {Array.<BusinessData>} businesses
|
||||
* @property {Array.<HouseData>} houses
|
||||
* @property {Array.<HouseData>} commands
|
||||
* @property {Array} groundItemCache
|
||||
* @property {Array} groundPlantCache
|
||||
* @property {Array.<ItemData>} items
|
||||
* @property {Array.<ItemTypeData>} itemTypes
|
||||
* @property {Array.<ClanData>} clans
|
||||
@@ -30,6 +28,10 @@ let logLevel = LOG_INFO|LOG_ERROR|LOG_WARN|LOG_DEBUG;
|
||||
* @property {Array.<RaceData>} races
|
||||
* @property {Array.<JobData>} jobs
|
||||
* @property {Array.<Gates>} gates
|
||||
* @property {Array} groundItemCache
|
||||
* @property {Array} groundPlantCache
|
||||
* @property {Array} purchasingVehicleCache
|
||||
* @property {Array} rentingVehicleCache
|
||||
*/
|
||||
let serverData = {
|
||||
vehicles: [],
|
||||
@@ -37,8 +39,6 @@ let serverData = {
|
||||
businesses: [],
|
||||
houses: [],
|
||||
commands: {},
|
||||
groundItemCache: [],
|
||||
groundPlantCache: [],
|
||||
items: [],
|
||||
itemTypes: [],
|
||||
clans: [],
|
||||
@@ -50,6 +50,10 @@ let serverData = {
|
||||
races: [],
|
||||
jobs: [],
|
||||
gates: [],
|
||||
groundItemCache: [],
|
||||
groundPlantCache: [],
|
||||
purchasingVehicleCache: [],
|
||||
rentingVehicleCache: [],
|
||||
};
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
@@ -1297,7 +1297,7 @@ function getClosestItemOnGround(position) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function setItemDataIndexes() {
|
||||
function setAllItemDataIndexes() {
|
||||
for(let i in getServerData().items) {
|
||||
if(getServerData().items[i]) {
|
||||
getServerData().items[i].index = i;
|
||||
@@ -1308,7 +1308,7 @@ function setItemDataIndexes() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function setItemTypeDataIndexes() {
|
||||
function setAllItemTypeDataIndexes() {
|
||||
for(let i in getServerData().itemTypes) {
|
||||
if(getServerData().itemTypes[i]) {
|
||||
getServerData().itemTypes[i].index = i;
|
||||
@@ -1460,7 +1460,7 @@ function deleteItem(itemId) {
|
||||
quickDatabaseQuery(`DELETE FROM item_main WHERE item_id = ${getItemData(itemId).databaseId}`);
|
||||
}
|
||||
getServerData().items[itemId] = false;
|
||||
setItemDataIndexes();
|
||||
setAllItemDataIndexes();
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
@@ -926,17 +926,15 @@ function takeJob(client, jobId) {
|
||||
function reloadAllJobsCommand(command, params, client) {
|
||||
forceAllPlayersToStopWorking();
|
||||
|
||||
deleteAllJobBlips();
|
||||
deleteAllJobPickups();
|
||||
clearArray(getServerData().jobs);
|
||||
getServerData().jobs = loadJobsFromDatabase();
|
||||
|
||||
for(let i in getServerData().jobs) {
|
||||
for(let j in getServerData().jobs[i].locations) {
|
||||
deleteJobLocationPickup(i, j);
|
||||
deleteJobLocationBlip(i, j);
|
||||
createJobLocationPickup(i, j);
|
||||
createJobLocationBlip(i, j);
|
||||
}
|
||||
}
|
||||
Promise.resolve().then(() => {
|
||||
getServerData().jobs = loadJobsFromDatabase();
|
||||
createJobLocationPickup(i, j);
|
||||
createJobLocationBlip(i, j);
|
||||
});
|
||||
|
||||
announceAdminAction("AllJobsReloaded");
|
||||
}
|
||||
|
||||
@@ -799,9 +799,16 @@ function disconnectFromDatabase(dbConnection) {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function queryDatabase(dbConnection, queryString) {
|
||||
function queryDatabase(dbConnection, queryString, useThread = false) {
|
||||
logToConsole(LOG_DEBUG, `[VRR.Database] Query string: ${queryString}`);
|
||||
return dbConnection.query(queryString);
|
||||
if(useThread == true) {
|
||||
Promise.resolve().then(() => {
|
||||
let queryResult = dbConnection.query(queryString);
|
||||
return queryResult;
|
||||
});
|
||||
} else {
|
||||
return dbConnection.query(queryString);
|
||||
}
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
@@ -47,8 +47,6 @@ function initServerScripts() {
|
||||
|
||||
// Load all the server data
|
||||
loadServerDataFromDatabase();
|
||||
|
||||
// Set indexes and cache necessary data
|
||||
setAllServerDataIndexes();
|
||||
createAllServerElements();
|
||||
|
||||
@@ -122,7 +120,6 @@ function loadServerDataFromDatabase() {
|
||||
getServerData().localeStrings = loadAllLocaleStrings();
|
||||
getServerData().allowedSkins = getAllowedSkins(getGame());
|
||||
|
||||
|
||||
// Translation Cache
|
||||
getServerData().cachedTranslations = new Array(getGlobalConfig().locale.locales.length);
|
||||
getServerData().cachedTranslationFrom = new Array(getGlobalConfig().locale.locales.length);
|
||||
@@ -150,8 +147,8 @@ function loadServerDataFromDatabase() {
|
||||
// ===========================================================================
|
||||
|
||||
function setAllServerDataIndexes() {
|
||||
setItemTypeDataIndexes();
|
||||
setItemDataIndexes();
|
||||
setAllItemTypeDataIndexes();
|
||||
setAllItemDataIndexes();
|
||||
setBusinessDataIndexes();
|
||||
setHouseDataIndexes();
|
||||
setAllClanDataIndexes();
|
||||
|
||||
@@ -105,7 +105,7 @@ function oneMinuteTimerFunction() {
|
||||
checkServerGameTime();
|
||||
|
||||
logToConsole(LOG_DEBUG, `[VRR.Event] Checking rentable vehicles`);
|
||||
vehicleRentCheck();
|
||||
checkVehicleRenting();
|
||||
|
||||
logToConsole(LOG_DEBUG, `[VRR.Event] Updating all player name tags`);
|
||||
updateAllPlayerNameTags();
|
||||
@@ -130,19 +130,18 @@ function thirtyMinuteTimerFunction() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function vehicleRentCheck() {
|
||||
// Loop through players, not vehicles. Much more efficient (and doesn't consume resources when no players are connected)
|
||||
let clients = getClients();
|
||||
for(let i in clients) {
|
||||
if(isClientInitialized(clients[i])) {
|
||||
if(getPlayerData(clients[i]) != false) {
|
||||
if(isPlayerLoggedIn(clients[i] && isPlayerSpawned(clients[i]))) {
|
||||
if(getPlayerData(clients[i]).rentingVehicle != false) {
|
||||
if(getPlayerCurrentSubAccount(clients[i]).cash < getServerData().vehicles[getPlayerData(clients[i]).rentingVehicle].rentPrice) {
|
||||
messagePlayerAlert(clients[i], `You do not have enough money to continue renting this vehicle!`);
|
||||
stopRentingVehicle(clients[i]);
|
||||
function checkVehicleRenting() {
|
||||
let renting = getServerData().rentingVehicleCache;
|
||||
for(let i in renting) {
|
||||
if(isClientInitialized(renting[i])) {
|
||||
if(getPlayerData(renting[i]) != false) {
|
||||
if(isPlayerLoggedIn(renting[i] && isPlayerSpawned(renting[i]))) {
|
||||
if(getPlayerData(renting[i]).rentingVehicle != false) {
|
||||
if(getPlayerCurrentSubAccount(renting[i]).cash < getServerData().vehicles[getPlayerData(renting[i]).rentingVehicle].rentPrice) {
|
||||
messagePlayerAlert(renting[i], `You do not have enough money to continue renting this vehicle!`);
|
||||
stopRentingVehicle(renting[i]);
|
||||
} else {
|
||||
takePlayerCash(clients[i], getServerData().vehicles[getPlayerData(clients[i]).rentingVehicle].rentPrice);
|
||||
takePlayerCash(renting[i], getServerData().vehicles[getPlayerData(renting[i]).rentingVehicle].rentPrice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ function saveVehicleToDatabase(vehicleDataId) {
|
||||
getServerData().vehicles[vehicleDataId].needsSaved = false;
|
||||
} else {
|
||||
let queryString = createDatabaseUpdateQuery("veh_main", data, `veh_id=${tempVehicleData.databaseId}`);
|
||||
dbQuery = queryDatabase(dbConnection, queryString);
|
||||
dbQuery = queryDatabase(dbConnection, queryString, true);
|
||||
getServerData().vehicles[vehicleDataId].needsSaved = false;
|
||||
}
|
||||
|
||||
@@ -547,6 +547,7 @@ function buyVehicleCommand(command, params, client) {
|
||||
setPlayerBuyingVehicleState(client, VRR_VEHBUYSTATE_TESTDRIVE, vehicle.id, getVehiclePosition(vehicle));
|
||||
meActionToNearbyPlayers(client, `receives a set of keys to test drive the ${getVehicleName(vehicle)} and starts the engine`);
|
||||
messagePlayerInfo(client, getLocaleString(client, "DealershipPurchaseTestDrive"));
|
||||
getServerData().purchasingVehicleCache.push(client);
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
@@ -593,7 +594,7 @@ function rentVehicleCommand(command, params, client) {
|
||||
getVehicleData(vehicle).rentedBy = client;
|
||||
getPlayerData(client).rentingVehicle = vehicle;
|
||||
getVehicleData(vehicle).rentStart = getCurrentUnixTimestamp();
|
||||
|
||||
getServerData().rentingVehicleCache.push(client);
|
||||
getVehicleData(vehicle).needsSaved = true;
|
||||
|
||||
meActionToNearbyPlayers(client, `rents the ${getVehicleName(vehicle)} and receives a set of vehicle keys!`);
|
||||
@@ -1232,6 +1233,7 @@ function respawnBusinessVehiclesCommand(command, params, client) {
|
||||
// ===========================================================================
|
||||
|
||||
function stopRentingVehicle(client) {
|
||||
getServerData().rentingVehicleCache.splice(getServerData().rentingVehicleCache.indexOf(client), 1);
|
||||
let vehicle = getPlayerData(client).rentingVehicle;
|
||||
getPlayerData(client).rentingVehicle = false;
|
||||
getVehicleData(vehicle).rentedBy = false;
|
||||
@@ -1465,9 +1467,9 @@ function processVehiclePurchasing() {
|
||||
return false;
|
||||
}
|
||||
|
||||
let clients = getClients();
|
||||
for(let i in clients) {
|
||||
checkVehicleBuying(clients[i]);
|
||||
let purchasingVehicles = getServerData().purchasingVehicleCache;
|
||||
for(let i in purchasingVehicles) {
|
||||
checkVehiclePurchasing(purchasingVehicles[i]);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -1475,7 +1477,7 @@ function processVehiclePurchasing() {
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
function checkVehicleBuying(client) {
|
||||
function checkVehiclePurchasing(client) {
|
||||
if(!isPlayerLoggedIn(client)) {
|
||||
setPlayerBuyingVehicleState(client, VRR_VEHBUYSTATE_NONE, null, null);
|
||||
return false;
|
||||
@@ -1498,6 +1500,7 @@ function checkVehicleBuying(client) {
|
||||
|
||||
if(!isPlayerInAnyVehicle(client)) {
|
||||
if(getPlayerData(client).buyingVehicle != false) {
|
||||
getServerData().purchasingVehicleCache.splice(getServerData().purchasingVehicleCache.indexOf(client), 1);
|
||||
messagePlayerError(client, getLocaleString(client, "DealershipPurchaseExitedVehicle"));
|
||||
respawnVehicle(getPlayerData(client).buyingVehicle);
|
||||
getPlayerData(client).buyingVehicle = false;
|
||||
@@ -1508,6 +1511,7 @@ function checkVehicleBuying(client) {
|
||||
|
||||
if(getDistance(getVehiclePosition(getPlayerData(client).buyingVehicle), getVehicleData(getPlayerData(client).buyingVehicle).spawnPosition) > getGlobalConfig().buyVehicleDriveAwayDistance) {
|
||||
if(getPlayerCurrentSubAccount(client).cash < getVehicleData(getPlayerData(client).buyingVehicle).buyPrice) {
|
||||
getServerData().purchasingVehicleCache.splice(getServerData().purchasingVehicleCache.indexOf(client), 1);
|
||||
messagePlayerError(client, getLocaleString(client, "VehiclePurchaseNotEnoughMoney"));
|
||||
respawnVehicle(getPlayerData(client).buyingVehicle);
|
||||
getPlayerData(client).buyingVehicle = false;
|
||||
@@ -1515,6 +1519,7 @@ function checkVehicleBuying(client) {
|
||||
return false;
|
||||
}
|
||||
|
||||
getServerData().purchasingVehicleCache.splice(getServerData().purchasingVehicleCache.indexOf(client), 1);
|
||||
createNewDealershipVehicle(getVehicleData(getPlayerData(client).buyingVehicle).model, getVehicleData(getPlayerData(client).buyingVehicle).spawnPosition, getVehicleData(getPlayerData(client).buyingVehicle).spawnRotation, getVehicleData(getPlayerData(client).buyingVehicle).buyPrice, getVehicleData(getPlayerData(client).buyingVehicle).ownerId);
|
||||
takePlayerCash(client, getVehicleData(getPlayerData(client).buyingVehicle).buyPrice);
|
||||
updatePlayerCash(client);
|
||||
@@ -1533,10 +1538,16 @@ function checkVehicleBuying(client) {
|
||||
// ===========================================================================
|
||||
|
||||
function processVehicleBurning() {
|
||||
if(!getGlobalConfig().useServerSideVehicleBurnCheck) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let vehicles = getElementsByType(ELEMENT_VEHICLE);
|
||||
for(let i in vehicles) {
|
||||
if(vehicles[i].health <= 250) {
|
||||
return false;
|
||||
if(vehicles[i].syncer == null) {
|
||||
if(vehicles[i].health <= 250) {
|
||||
vehicles[i].health = 250;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user