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.introMusicURL = dbAssoc["svr_intro_music"];
|
||||
|
||||
//this.useRealTime = intToBool(toInteger(dbAssoc["svr_real_time_enabled"]));
|
||||
//this.realTimeZone = dbAssoc["svr_real_time_timezone"];
|
||||
this.useRealTime = intToBool(toInteger(dbAssoc["svr_real_time_enabled"]));
|
||||
this.realTimeZone = dbAssoc["svr_real_time_timezone"];
|
||||
|
||||
this.discord = {
|
||||
sendEvents: intToBool(dbAssoc["svr_discord_send_events"]),
|
||||
@@ -377,10 +377,12 @@ function applyConfigToServer(tempServerConfig) {
|
||||
logToConsole(LOG_INFO, "[VRR.Config]: Applying server config ...");
|
||||
logToConsole(LOG_DEBUG, "[VRR.Config]: Server config applied successfully!");
|
||||
|
||||
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);
|
||||
}
|
||||
updateServerGameTime();
|
||||
|
||||
//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()) {
|
||||
logToConsole(LOG_DEBUG, `[VRR.Config]: Setting weather to ${tempServerConfig.weather}`);
|
||||
|
||||
@@ -52,9 +52,13 @@ function initServerScripts() {
|
||||
|
||||
addAllNetworkEventHandlers();
|
||||
|
||||
checkServerGameTime();
|
||||
|
||||
initAllClients();
|
||||
initTimers();
|
||||
|
||||
|
||||
|
||||
serverStartTime = getCurrentUnixTimestamp();
|
||||
}
|
||||
|
||||
|
||||
@@ -125,6 +125,34 @@ function tenMinuteTimerFunction() {
|
||||
//showRandomTipToAllPlayers();
|
||||
//saveServerDataToDatabase();
|
||||
//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() {
|
||||
if (isGameFeatureSupported("time")) {
|
||||
return false;
|
||||
//logToConsole(LOG_DEBUG | LOG_WARN, "[AGRP.Timers] Checking server game time");
|
||||
|
||||
//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 (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 (getGame() == AGRP_GAME_MAFIA_ONE) {
|
||||
if (isNightTime(getServerConfig().hour) && getGameConfig().mainWorldScene[getGame()] == "FREERIDE") {
|
||||
getGameConfig().mainWorldScene[getGame()] = "FREERIDENOC";
|
||||
game.changeMap(getGameConfig().mainWorldScene[getGame()]);
|
||||
} else if (!isNightTime(getServerConfig().hour) && getGameConfig().mainWorldScene[getGame()] == "FREERIDENOC") {
|
||||
getGameConfig().mainWorldScene[getGame()] = "FREERIDE";
|
||||
game.changeMap(getGameConfig().mainWorldScene[getGame()]);
|
||||
}
|
||||
}
|
||||
|
||||
if (isGameFeatureSupported("time")) {
|
||||
game.time.hour = getServerConfig().hour;
|
||||
game.time.minute = getServerConfig().minute;
|
||||
}
|
||||
|
||||
updateTimeRule();
|
||||
}
|
||||
|
||||
@@ -409,6 +409,14 @@ function updateTimeRule() {
|
||||
if (isTimeSupported()) {
|
||||
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");
|
||||
}
|
||||
|
||||
// ===========================================================================
|
||||
|
||||
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