62 lines
2.4 KiB
Lua
62 lines
2.4 KiB
Lua
local Config = {
|
|
DefaultWeather = "extrasunny",
|
|
AutoWeather = false,
|
|
AutoWeatherInterval = 120,
|
|
AutoWeatherPool = { "extrasunny", "clear", "clouds", "overcast", "rain", "thunder" },
|
|
WeatherBlacklist = { "xmas", "snow", "blizzard" },
|
|
|
|
-- Schlechtes Wetter läuft nur kurz, dann zurück zu gutem Wetter
|
|
BadWeather = { "rain", "thunder", "foggy", "smog" },
|
|
BadWeatherDuration = 10, -- Minuten bis es wieder aufklart
|
|
AfterBadWeather = "clearing" -- Wetter danach
|
|
}
|
|
|
|
local currentWeather = Config.DefaultWeather
|
|
local manualWeather = false
|
|
|
|
local function isBadWeather(weather)
|
|
for _, w in ipairs(Config.BadWeather) do
|
|
if w == weather then return true end
|
|
end
|
|
return false
|
|
end
|
|
|
|
CreateThread(function()
|
|
while true do
|
|
Wait(Config.AutoWeatherInterval * 60000)
|
|
if Config.AutoWeather and not manualWeather then
|
|
local pool = Config.AutoWeatherPool
|
|
local newWeather = pool[math.random(#pool)]
|
|
currentWeather = newWeather
|
|
TriggerClientEvent('mercyv-weather:syncWeather', -1, newWeather)
|
|
print("[mercyv-weather] Wetter gewechselt zu: " .. newWeather)
|
|
|
|
-- Wenn schlechtes Wetter, nach X Minuten wieder aufklaren
|
|
if isBadWeather(newWeather) then
|
|
CreateThread(function()
|
|
Wait(Config.BadWeatherDuration * 60000)
|
|
if currentWeather == newWeather and not manualWeather then
|
|
currentWeather = Config.AfterBadWeather
|
|
TriggerClientEvent('mercyv-weather:syncWeather', -1, Config.AfterBadWeather)
|
|
print("[mercyv-weather] Schlechtes Wetter vorbei, wechsle zu: " .. Config.AfterBadWeather)
|
|
end
|
|
end)
|
|
end
|
|
end
|
|
end
|
|
end)
|
|
|
|
RegisterNetEvent('mercyv-weather:setWeather', function(weather)
|
|
for _, w in ipairs(Config.WeatherBlacklist) do
|
|
if w == weather then return end
|
|
end
|
|
currentWeather = weather
|
|
manualWeather = true
|
|
TriggerClientEvent('mercyv-weather:syncWeather', -1, weather)
|
|
end)
|
|
|
|
-- Client fragt aktiv nach dem Wetter wenn er bereit ist
|
|
RegisterNetEvent('mercyv-weather:requestSync', function()
|
|
local src = source
|
|
TriggerClientEvent('mercyv-weather:syncWeather', src, currentWeather)
|
|
end) |