Custom weather array

This commit is contained in:
Vortrex
2022-10-29 10:06:57 -05:00
parent 455e87bd87
commit a817db618b
4 changed files with 118 additions and 79 deletions

View File

@@ -387,7 +387,7 @@ function applyConfigToServer(tempServerConfig) {
if (isWeatherSupported()) {
logToConsole(LOG_DEBUG, `[AGRP.Config]: Setting weather to ${tempServerConfig.weather}`);
game.forceWeather(tempServerConfig.weather);
game.forceWeather(getWeatherData(tempServerConfig.weather).weatherId);
}
updateServerRules();
@@ -583,19 +583,19 @@ function setWeatherCommand(command, params, client) {
return false;
}
let weatherId = getWeatherFromParams(getParam(params, " ", 1));
let weatherIndex = getWeatherFromParams(getParam(params, " ", 1));
if (!weatherId) {
if (!getWeatherData(weatherIndex)) {
messagePlayerError(client, `That weather ID or name is invalid!`);
return false;
}
game.forceWeather(toInteger(weatherId));
getServerConfig().weather = weatherId;
game.forceWeather(getWeatherData(weatherIndex).weatherId);
getServerConfig().weather = weatherIndex;
getServerConfig().needsSaved = true;
announceAdminAction("ServerWeatherSet", getPlayerName(client), getGameConfig().weatherNames[getGame()][toInteger(weatherId)]);
announceAdminAction("ServerWeatherSet", getPlayerName(client), getWeatherData(weatherIndex).name);
updateServerRules();
return true;
}

View File

@@ -134,11 +134,18 @@ function thirtyMinuteTimerFunction() {
checkPayDays();
}
checkInactiveVehicleRespawns();
if (isGameFeatureSupported("snow")) {
checkSnowChance();
setSnowWithChance();
}
checkInactiveVehicleRespawns();
if (isGameFeatureSupported("weather")) {
setRandomWeather();
}
updateServerRules();
saveServerDataToDatabase();
}
@@ -330,7 +337,7 @@ function checkInactiveVehicleRespawns() {
if (getVehicleData(vehicles[i]).lastActiveTime != false) {
if (getCurrentUnixTimestamp() - getVehicleData(vehicles[i]).lastActiveTime >= getGlobalConfig().vehicleInactiveRespawnDelay) {
respawnVehicle(vehicles[i]);
getVehicleData(vehicles[i]).lastActiveTime = false;
//getVehicleData(vehicles[i]).lastActiveTime = false;
}
}
} else {
@@ -342,13 +349,31 @@ function checkInactiveVehicleRespawns() {
// ===========================================================================
function checkSnowChance() {
function setSnowWithChance() {
let date = new Date();
let shouldBeSnowing = getRandomBoolWithProbability(getGlobalConfig().monthlyChanceOfSnow[date.getMonths()]);
let shouldBeSnowing = getRandomBoolWithProbability(getGlobalConfig().monthlyChanceOfSnow[date.getMonth()]);
getServerConfig().groundSnow = shouldBeSnowing;
getServerConfig().fallingSnow = shouldBeSnowing;
updatePlayerSnowState(null);
}
// ===========================================================================
function setRandomWeather() {
let randomWeatherIndex = getRandom(0, getGameConfig().weather[getGame()].length - 1);
if (getServerConfig().fallingSnow == true) {
while (getWeatherData(randomWeatherIndex).allowWithSnow == false) {
randomWeatherIndex = getRandom(0, getGameConfig().weather[getGame()].length - 1);
}
}
game.forceWeather(getWeatherData(weatherIndex).weatherId);
getServerConfig().weather = weatherIndex;
getServerConfig().needsSaved = true;
}
// ===========================================================================

View File

@@ -101,8 +101,8 @@ function updateServerRules() {
if (isWeatherSupported()) {
if (getServerConfig() != false) {
if (typeof getGameConfig().weatherNames[getGame()] != "undefined") {
let tempText = getGameConfig().weatherNames[getGame()][getServerConfig().weather];
if (getWeatherData(getServerConfig().weather) != false) {
let tempText = getWeatherData(getServerConfig().weather).name;
timeWeatherRule.push(tempText);
}
}
@@ -124,14 +124,16 @@ function updateServerRules() {
function getWeatherFromParams(params) {
if (isNaN(params)) {
for (let i in getGameConfig().weatherNames[getGame()]) {
if (toLowerCase(getGameConfig().weatherNames[getGame()][i]).indexOf(toLowerCase(params)) != -1) {
for (let i in getGameConfig().weather[getGame()]) {
if (toLowerCase(getGameConfig().weather[getGame()][i].name).indexOf(toLowerCase(params)) != -1) {
return i;
}
}
} else {
if (typeof getGameConfig().weatherNames[getGame()][params] != "undefined") {
return toInteger(params);
for (let i in getGameConfig().weather[getGame()]) {
if (typeof getGameConfig().weather[getGame()][i].weatherId != "undefined") {
return toInteger(i);
}
}
}