Created
August 22, 2016 15:47
-
-
Save pauliusdotpro/eabfe4e1bdd1291a7b37da0675e35a3c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using serverMP; | |
using serverMP.APIScript; | |
using System.Timers; | |
namespace Gamemode | |
{ | |
class WeatherTime : ScriptAPI | |
{ | |
public string current_weather = "CLEAR"; | |
public float current_rain = 0; | |
public float current_wind_direction = 0; | |
public float current_wind_speed = 0; | |
private const int rainChance = 10; | |
string[] Weathers = { "CLEAR", "EXTRASUNNY", "CLOUDS", "OVERCAST", "RAIN", "CLEARING", "THUNDER", "SMOG", "FOGGY" }; | |
public void Start() | |
{ | |
Timer aTimer = new Timer(); //half hour in milliseconds | |
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); | |
aTimer.Interval = 1800000; | |
aTimer.Enabled = true; | |
} | |
private void OnTimedEvent(object source, ElapsedEventArgs e) | |
{ | |
string newWeather = randomWeather(); | |
float newRain = randomRain(); | |
foreach (PlayerInfo player in PlayerInfo.PlayersList) | |
{ | |
WorldInfo.SetWeatherTransition(player, current_weather, newWeather, 60); | |
WorldInfo.SetRainIntensity(player, current_rain); | |
WorldInfo.SetClockData(player, DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year); | |
WorldInfo.SetClockTime(player, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); | |
WorldInfo.SetWindDirection(player, current_wind_direction); | |
WorldInfo.SetWindSpeed(player, current_wind_speed); | |
} | |
utils.WriteLine("Weather changed to " + newWeather + " from " + current_weather); | |
current_rain = newRain; | |
current_weather = newWeather; | |
} | |
public void SyncWorld(PlayerInfo player) | |
{ | |
WorldInfo.SetWeatherNow(player, current_weather); | |
WorldInfo.SetClockData(player, DateTime.Now.Day, DateTime.Now.Month, DateTime.Now.Year); | |
WorldInfo.SetClockTime(player, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); | |
WorldInfo.SetRainIntensity(player, current_rain); | |
WorldInfo.SetWindDirection(player, current_wind_direction); | |
WorldInfo.SetWindSpeed(player, current_wind_speed); | |
} | |
private string randomWeather() | |
{ | |
Random randNum = new Random(); | |
string weather = current_weather; | |
while (weather == current_weather) | |
{ | |
weather = Weathers[randNum.Next(0, Weathers.Length)]; | |
} | |
return weather; | |
} | |
private float randomRain() | |
{ | |
Random randNum = new Random(); | |
if(randNum.Next(0,100) < rainChance) | |
{ | |
return 2; | |
} | |
else | |
{ | |
return 0; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment