Day/night cycle for Mafia
This commit is contained in:
@@ -126,8 +126,8 @@ class ServerConfigData {
|
|||||||
this.discordBotToken = intToBool(dbAssoc["svr_discord_bot_token"]);
|
this.discordBotToken = intToBool(dbAssoc["svr_discord_bot_token"]);
|
||||||
this.introMusicURL = dbAssoc["svr_intro_music"];
|
this.introMusicURL = dbAssoc["svr_intro_music"];
|
||||||
|
|
||||||
//this.useRealTime = intToBool(toInteger(dbAssoc["svr_real_time_enabled"]));
|
this.useRealTime = intToBool(toInteger(dbAssoc["svr_real_time_enabled"]));
|
||||||
//this.realTimeZone = dbAssoc["svr_real_time_timezone"];
|
this.realTimeZone = dbAssoc["svr_real_time_timezone"];
|
||||||
|
|
||||||
this.discord = {
|
this.discord = {
|
||||||
sendEvents: intToBool(dbAssoc["svr_discord_send_events"]),
|
sendEvents: intToBool(dbAssoc["svr_discord_send_events"]),
|
||||||
@@ -377,10 +377,12 @@ function applyConfigToServer(tempServerConfig) {
|
|||||||
logToConsole(LOG_INFO, "[VRR.Config]: Applying server config ...");
|
logToConsole(LOG_INFO, "[VRR.Config]: Applying server config ...");
|
||||||
logToConsole(LOG_DEBUG, "[VRR.Config]: Server config applied successfully!");
|
logToConsole(LOG_DEBUG, "[VRR.Config]: Server config applied successfully!");
|
||||||
|
|
||||||
if (isTimeSupported()) {
|
updateServerGameTime();
|
||||||
logToConsole(LOG_DEBUG, `[VRR.Config]: Setting time to to ${tempServerConfig.hour}:${tempServerConfig.minute} with minute duration of ${tempServerConfig.minuteDuration}`);
|
|
||||||
setGameTime(tempServerConfig.hour, tempServerConfig.minute, tempServerConfig.minuteDuration);
|
//if (isTimeSupported()) {
|
||||||
}
|
// logToConsole(LOG_DEBUG, `[VRR.Config]: Setting time to to ${tempServerConfig.hour}:${tempServerConfig.minute} with minute duration of ${tempServerConfig.minuteDuration}`);
|
||||||
|
// setGameTime(tempServerConfig.hour, tempServerConfig.minute, tempServerConfig.minuteDuration);
|
||||||
|
//}
|
||||||
|
|
||||||
if (isWeatherSupported()) {
|
if (isWeatherSupported()) {
|
||||||
logToConsole(LOG_DEBUG, `[VRR.Config]: Setting weather to ${tempServerConfig.weather}`);
|
logToConsole(LOG_DEBUG, `[VRR.Config]: Setting weather to ${tempServerConfig.weather}`);
|
||||||
|
|||||||
@@ -52,9 +52,13 @@ function initServerScripts() {
|
|||||||
|
|
||||||
addAllNetworkEventHandlers();
|
addAllNetworkEventHandlers();
|
||||||
|
|
||||||
|
checkServerGameTime();
|
||||||
|
|
||||||
initAllClients();
|
initAllClients();
|
||||||
initTimers();
|
initTimers();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
serverStartTime = getCurrentUnixTimestamp();
|
serverStartTime = getCurrentUnixTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -125,6 +125,34 @@ function tenMinuteTimerFunction() {
|
|||||||
//showRandomTipToAllPlayers();
|
//showRandomTipToAllPlayers();
|
||||||
//saveServerDataToDatabase();
|
//saveServerDataToDatabase();
|
||||||
//checkInactiveVehicleRespawns();
|
//checkInactiveVehicleRespawns();
|
||||||
|
|
||||||
|
if (getGame() == AGRP_GAME_MAFIA_ONE) {
|
||||||
|
if (server.mapName == "FREERIDE") {
|
||||||
|
if (isServerGoingToChangeMapsSoon(getServerConfig().hour, getServerConfig().minute)) {
|
||||||
|
sendMapChangeWarningToPlayer(null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isNightTime(getServerConfig().hour)) {
|
||||||
|
getGameConfig().mainWorldScene[getGame()] = "FREERIDENOC";
|
||||||
|
removeAllPlayersFromProperties();
|
||||||
|
saveServerDataToDatabase();
|
||||||
|
game.changeMap(getGameConfig().mainWorldScene[getGame()]);
|
||||||
|
updateTimeRule();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (isServerGoingToChangeMapsSoon()) {
|
||||||
|
sendMapChangeWarningToPlayer(null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isNightTime(getServerConfig().hour)) {
|
||||||
|
getGameConfig().mainWorldScene[getGame()] = "FREERIDE";
|
||||||
|
removeAllPlayersFromProperties();
|
||||||
|
saveServerDataToDatabase();
|
||||||
|
game.changeMap(getGameConfig().mainWorldScene[getGame()]);
|
||||||
|
updateTimeRule();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
@@ -202,26 +230,43 @@ function updatePings() {
|
|||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
|
|
||||||
function checkServerGameTime() {
|
function checkServerGameTime() {
|
||||||
if (isGameFeatureSupported("time")) {
|
//logToConsole(LOG_DEBUG | LOG_WARN, "[AGRP.Timers] Checking server game time");
|
||||||
return false;
|
|
||||||
|
//if (isGameFeatureSupported("time")) {
|
||||||
|
// return false;
|
||||||
|
//}
|
||||||
|
|
||||||
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
//if(!getServerConfig().useRealTime) {
|
if (getGame() == AGRP_GAME_MAFIA_ONE) {
|
||||||
//if (getServerConfig().minute >= 59) {
|
if (isNightTime(getServerConfig().hour) && getGameConfig().mainWorldScene[getGame()] == "FREERIDE") {
|
||||||
// getServerConfig().minute = 0;
|
getGameConfig().mainWorldScene[getGame()] = "FREERIDENOC";
|
||||||
// if (getServerConfig().hour >= 23) {
|
game.changeMap(getGameConfig().mainWorldScene[getGame()]);
|
||||||
// getServerConfig().hour = 0;
|
} else if (!isNightTime(getServerConfig().hour) && getGameConfig().mainWorldScene[getGame()] == "FREERIDENOC") {
|
||||||
// } else {
|
getGameConfig().mainWorldScene[getGame()] = "FREERIDE";
|
||||||
// getServerConfig().hour = getServerConfig().hour + 1;
|
game.changeMap(getGameConfig().mainWorldScene[getGame()]);
|
||||||
// }
|
}
|
||||||
//} else {
|
}
|
||||||
// getServerConfig().minute = getServerConfig().minute + 1;
|
|
||||||
//}
|
if (isGameFeatureSupported("time")) {
|
||||||
//} else {
|
game.time.hour = getServerConfig().hour;
|
||||||
// let dateTime = getCurrentTimeStampWithTimeZone(getServerConfig().realTimeZone);
|
game.time.minute = getServerConfig().minute;
|
||||||
// getServerConfig().hour = dateTime.getHours();
|
}
|
||||||
// getServerConfig().minute = dateTime.getMinutes();
|
|
||||||
//}
|
|
||||||
|
|
||||||
updateTimeRule();
|
updateTimeRule();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -409,6 +409,14 @@ function updateTimeRule() {
|
|||||||
if (isTimeSupported()) {
|
if (isTimeSupported()) {
|
||||||
server.setRule("Time", makeReadableTime(game.time.hour, game.time.minute));
|
server.setRule("Time", makeReadableTime(game.time.hour, game.time.minute));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (getGame() == AGRP_GAME_MAFIA_ONE) {
|
||||||
|
if (isNightTime(getServerConfig().hour)) {
|
||||||
|
server.setRule("Time", "Night");
|
||||||
|
} else {
|
||||||
|
server.setRule("Time", "Day");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
@@ -472,4 +480,11 @@ function updateAllPlayerWeaponDamageStates() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===========================================================================
|
||||||
|
|
||||||
|
function removeAllPlayersFromProperties() {
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
@@ -3188,4 +3188,30 @@ function isMainWorldScene(sceneName) {
|
|||||||
return (sceneName == "agrp.mainWorldScene");
|
return (sceneName == "agrp.mainWorldScene");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===========================================================================
|
||||||
|
|
||||||
|
function isNightTime(hour) {
|
||||||
|
if (hour >= 7 && hour <= 19) {
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===========================================================================
|
||||||
|
|
||||||
|
function isServerGoingToChangeMapsSoon(hour, minute) {
|
||||||
|
if (server.mapName == "FREERIDENOC") {
|
||||||
|
if (hour == 6 && minute >= 30) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else if (server.mapName == "FREERIDE") {
|
||||||
|
if (hour == 18 && minute >= 30) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
Reference in New Issue
Block a user