Files
GTA4RP/scripts/server/timers.js
Vortrex 9d8d5d1418 Bunch of changes (see description)
* New script files to organize GUI
* Added clientside pickup detection to reduce server load for enter/exit
* Added notips command for players to toggle random tips
* Select account last IP as part of wildcard (was separate due to old INT)
* Save account registration with datetime instead of unix timestamp
* Don't force mouse camera on moving anims in SA+
* Add IP ban to server runtime memory in subnet ban command
* Add non-roleplay character name account moderation flag
* Fix bizowner and bizclan commands
* Fix bug that allowed buying items without having the needed cash
* Fix set biz blip command
* Add dealership help label type command
* Added command to show all clan flag types
* Added discord config and load from database
* Fix angle for directional teleport and anim move directions
* Use new colour structure in preparation for locale translations
* Add on-foot only item usetype array to prevent using when in veh
* Fix wrong const value for exit pickup type
* Start using datetime in MySQL tables instead of unix timestamps
* Start adding webhooks for discord (unfinished)
* Added new discord URL to discord help category
* Added house reset pickups/blips utils
* Prevent using items when in skin selector
* Fix get player command
* Fix give player money command
* Add coffee shop and vehicle repair shop default biz item templates
* Remove old game fixes util (resource now in server config)
* Fix bug where characters in clans wouldn't be shown in char select
* Slimmed down the amount of timers
* Made some potentially large numbers more readable (commas)
* Remove colours in message for console output
2021-09-28 11:41:33 -05:00

198 lines
5.5 KiB
JavaScript

// ===========================================================================
// Vortrex's Roleplay Resource
// https://github.com/VortrexFTW/gtac_roleplay
// ===========================================================================
// FILE: timers.js
// DESC: Provides timer functions and features
// TYPE: Server (JavaScript)
// ===========================================================================
let serverTimers = {};
// ===========================================================================
function updateTimeRule() {
if(isTimeSupported()) {
server.setRule("Time", makeReadableTime(gta.time.hour, gta.time.minute));
}
}
// ===========================================================================
function saveAllServerDataToDatabase() {
if(getServerConfig().pauseSavingToDatabase) {
return false;
}
logToConsole(LOG_DEBUG, "[VRR.Utilities]: Saving all server data to database ...");
try {
saveAllClientsToDatabase();
} catch(error) {
logToConsole(LOG_ERROR, `Could not save clients to database: ${error}`);
}
try {
saveAllClansToDatabase();
} catch(error) {
logToConsole(LOG_ERROR, `Could not save clans to database: ${error}`);
}
try {
saveAllHousesToDatabase();
} catch(error) {
logToConsole(LOG_ERROR, `Could not save houses to database: ${error}`);
}
try {
saveAllBusinessesToDatabase();
} catch(error) {
logToConsole(LOG_ERROR, `Could not save businesses to database: ${error}`);
}
try {
saveServerConfigToDatabase(getServerConfig());
} catch(error) {
logToConsole(LOG_ERROR, `Could not save server config to database: ${error}`);
}
try {
saveAllVehiclesToDatabase();
} catch(error) {
logToConsole(LOG_ERROR, `Could not save vehicles to database: ${error}`);
}
try {
saveAllItemsToDatabase();
} catch(error) {
logToConsole(LOG_ERROR, `Could not save items to database: ${error}`);
}
try {
saveServerConfigToDatabase();
} catch(error) {
logToConsole(LOG_ERROR, `Could not save server config to database: ${error}`);
}
logToConsole(LOG_DEBUG, "[VRR.Utilities]: Saved all server data to database!");
}
// ===========================================================================
function initTimers() {
//if(!isDevelopmentServer()) {
serverTimers.updatePingsTimer = setInterval(updatePings, 5000);
serverTimers.oneMinuteTimer = setInterval(oneMinuteTimerFunction, 60000);
serverTimers.fifteenMinuteTimer = setInterval(tenMinuteTimerFunction, 600000);
serverTimers.thirtyMinuteTimer = setInterval(thirtyMinuteTimerFunction, 1800000);
//}
}
// ===========================================================================
function oneMinuteTimerFunction() {
checkServerGameTime();
vehicleRentCheck();
collectAllGarbage();
}
// ===========================================================================
function tenMinuteTimerFunction() {
showRandomTipToAllPlayers();
saveAllServerDataToDatabase();
}
// ===========================================================================
function thirtyMinuteTimerFunction() {
checkPayDays();
}
// ===========================================================================
function vehicleRentCheck() {
for(let i in getServerData().vehicles) {
if(getServerData().vehicles[i] != null) {
if(getServerData().vehicles[i].rentPrice > 0) {
if(getServerData().vehicles[i].rentedBy != false) {
let rentedBy = getServerData().vehicles[i].rentedBy;
if(getPlayerData(rentedBy) != false) {
if(getPlayerCurrentSubAccount(rentedBy).cash < getServerData().vehicles[i].rentPrice) {
messagePlayerAlert(rentedBy, `You do not have enough money to continue renting this vehicle!`);
stopRentingVehicle(rentedBy);
} else {
takePlayerCash(rentedBy, getServerData().vehicles[i].rentPrice);
}
}
}
}
}
}
}
// ===========================================================================
function updatePings() {
let clients = getClients();
for(let i in clients) {
if(!clients[i].console) {
updatePlayerPing(clients[i]);
if(isPlayerSpawned(clients[i])) {
updatePlayerCash(clients[i]);
}
}
}
}
// ===========================================================================
function checkServerGameTime() {
if(!getServerConfig().useRealTime) {
if(getServerConfig().minute >= 59) {
getServerConfig().minute = 0;
if(getServerConfig().hour >= 23) {
getServerConfig().hour = 0;
} else {
getServerConfig().hour = getServerConfig().hour + 1;
}
} else {
getServerConfig().minute = getServerConfig().minute + 1;
}
} else {
let dateTime = getCurrentTimeStampWithTimeZone(getServerConfig().realTimeZone);
getServerConfig().hour = dateTime.getHours();
getServerConfig().minute = dateTime.getMinutes();
}
updateTimeRule();
}
// ===========================================================================
function checkPayDays() {
let clients = getClients();
for(let i in clients) {
if(isPlayerLoggedIn(clients[i]) && isPlayerSpawned(clients[i])) {
//if(sdl.ticks-getPlayerData(clients[i]).payDayTickStart >= getGlobalConfig().payDayTickCount) {
getPlayerData(clients[i]).payDayStart = sdl.ticks;
playerPayDay(clients[i]);
//}
}
}
}
// ===========================================================================
function showRandomTipToAllPlayers() {
let tipId = getRandom(0, randomTips.length-1);
let clients = getClients();
for(let i in clients) {
if(isPlayerLoggedIn(clients[i]) && isPlayerSpawned(clients[i])) {
messagePlayerTimedRandomTip(clients[i], randomTips[tipId]);
}
}
}
// ===========================================================================