Benutzer-Werkzeuge

Webseiten-Werkzeuge


utilscripts:wetterscript

Wetterscript

Mit diesem Script kann man das Wetter etwas zufälliger gestalten. Wer will kann es auch mal im MP ausprobieren und testen ob es DESYNCs gibt.

Anwendung

function InitWeather()
    -- Erstmal ganz normal das Wetter einstellen
    AddPeriodicSummer (300)
    AddPeriodicRain   ( 60)
 
    -- Jetzt die neuen Wetterperioden einstellen
    Weather.AddPeriodicSummer (240, 360) -- Minimum Dauer, Maximum Dauer
    Weather.AddPeriodicRain   ( 30,  90)
    Weather.AddPeriodicWinter (120, 240)
 
    -- Die Wetterlagen sollen nacheinander oder zufällig erscheinen? (WEATHER_PERIODIC oder WEATHER_RANDOM)
    Weather.SetOrder(WEATHER_PERIODIC)
 
    -- Starten!
    Weather.Init()
end

Benötigter Code

StartSummerOrig = StartSummer
function StartSummer(_seconds) if Weather.IsActive then Weather.Init(_seconds) end StartSummerOrig(_seconds) end
StartRainOrig = StartRain
function StartRain(_seconds) if Weather.IsActive then Weather.Init(_seconds) end StartRainOrig(_seconds) end
StartWinterOrig = StartWinter
function StartWinter(_seconds) if Weather.IsActive then Weather.Init(_seconds) end StartWinterOrig(_seconds) end
GUI.SetWeatherOrig = GUI.SetWeather
function GUI.SetWeather(_weathertype) if Weather.IsActive then Weather.Init(300) end GUI.SetWeatherOrig(_weathertype) end
Logic.GetNextWeatherStateOrig = Logic.GetNextWeatherState
function Logic.GetNextWeatherState() if Weather.IsActive then return Weather.Next.Type end return Logic.GetNextWeatherStateOrig() end
Logic.GetTimeToNextWeatherPeriodOrig = Logic.GetTimeToNextWeatherPeriod
function Logic.GetTimeToNextWeatherPeriod() if Weather.IsActive then return Weather.TimeToNextWeatherPeriod end return Logic.GetTimeToNextWeatherPeriodOrig() end
--++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
WEATHER_PERIODIC    = 1
WEATHER_RANDOM      = 2
Weather             = {Periods = {}, IsActive = false, Order = WEATHER_PERIODIC}
 
Weather.Init = function(_delay)
    Weather.Count = table.getn(Weather.Periods)
    if Weather.Count > 0 then
        if Weather.IsActive then Weather.Stop() end
 
        Weather.Tick        = 0
        Weather.Current     = {Duration = (_delay or 1), Index = 0}
        Weather.Next        = Weather.AddElement()
        Weather.Id          = StartSimpleJob("WeatherStart")
        Weather.IsActive    = true
    end
end
 
Weather.Start = function()
    Weather.Tick = Weather.Tick + 1
    Weather.TimeToNextWeatherPeriod = Weather.Current.Duration - Weather.Tick
 
    if Weather.Tick >= Weather.Current.Duration then
        Weather.Current = Weather.Next
        Weather.Periods[Weather.Current.Index][1](Weather.Current.Duration)
        Weather.Next = Weather.AddElement()
        Weather.Tick = 0
    end
end
WeatherStart = Weather.Start
 
Weather.AddElement = function()
    local Data = {}
 
    if Weather.Order == WEATHER_PERIODIC then
        if Weather.Current.Index == Weather.Count then Data.Index = 1
        else Data.Index = Weather.Current.Index + 1 end
    else
        Data.Index = GetRandom(Weather.Count)
    end 
 
    Data.Duration = GetRandom(Weather.Periods[Data.Index][2], Weather.Periods[Data.Index][3])
    Data.Type = Weather.Periods[Data.Index][4]
 
    return Data
end
 
Weather.Stop              = function() EndJob(Weather.Id); Weather.IsActive = false end
Weather.SetOrder          = function(_order) Weather.Order = _order end
Weather.AddPeriodicSummer = function(_min, _max) table.insert(Weather.Periods, {StartSummerOrig, _min, _max, 1}) end
Weather.AddPeriodicRain   = function(_min, _max) table.insert(Weather.Periods, {StartRainOrig,   _min, _max, 2}) end
Weather.AddPeriodicWinter = function(_min, _max) table.insert(Weather.Periods, {StartWinterOrig, _min, _max, 3}) end

Zusätzlicher Code

Mit diesem zusätzlichen optionalen Code werden bessere Zufallszahlen erzeugt.

Siehe: GetRandom()

utilscripts/wetterscript.txt · Zuletzt geändert: 2021/09/18 19:15 von 127.0.0.1