Exports & events
Server exports
Getters:
Lua
exports['saf-weather']:GetTime() -- hour, minute, second
exports['saf-weather']:GetWeather() -- 'RAIN'
exports['saf-weather']:GetForecast() -- { { weather, minutes, at = unix time }, ... }
exports['saf-weather']:GetState() -- everything: clock, weather, forecast, wind, rain, blackout...
exports['saf-weather']:GetTemperature() -- value, unitSetters:
Lua
exports['saf-weather']:SetWeather('THUNDER', 60) -- weather, blend seconds (optional)
exports['saf-weather']:SetTime(21, 30) -- hour, minute, instant (optional, skips the ease)
exports['saf-weather']:FreezeTime(true)
exports['saf-weather']:SetBlackout(true)
exports['saf-weather']:SetDynamic(false)
exports['saf-weather']:SetSnow(true)
exports['saf-weather']:SetChristmas(true)
exports['saf-weather']:SetRain(0.8) -- 0 to 1, or -1 to follow the weather
exports['saf-weather']:SetWind(8.0, 270) -- m/s, degrees it blows from; or SetWind('auto')
exports['saf-weather']:SetTimeScale(2)
exports['saf-weather']:ApplyPreset('storm_night')The setters return ok, message and are logged under the calling resource's name.
Lua
local ok, msg = exports['saf-weather']:SetWeather('FOGGY', 120)
if not ok then print('weather not changed: ' .. msg) endClient exports
Lua
exports['saf-weather']:GetTime() -- hour, minute, second as the player sees it
exports['saf-weather']:GetWeather()
exports['saf-weather']:GetForecast() -- { { weather, minutes, inSec, gameMinutes, temp }, ... }
exports['saf-weather']:GetTemperature() -- value, unit
exports['saf-weather']:IsBlackout()
exports['saf-weather']:IsTimeFrozen()
exports['saf-weather']:PauseSync(true) -- stop applying weather and time on this clientPauseSync is for interiors, cutscenes and anything else that needs its own sky. Call PauseSync(false) to
pick the server's weather and time back up.
SetWeather, SetTime, FreezeTime and SetBlackout exist on the client too. They go through the server
and only work when the player is staff.
Events
Lua
-- client, every in-game minute (for a HUD clock)
AddEventHandler('saf-weather:client:minute', function(hour, minute) end)
-- client, when the weather changes
AddEventHandler('saf-weather:client:weatherChanged', function(weather, previous) end)
-- server, after every change
AddEventHandler('saf-weather:server:updated', function(state) end)State bag
GlobalState['saf-weather'] holds weather, blackout, frozen, snow, rain and dynamic, readable on
both sides.
Lua
local w = GlobalState['saf-weather']
if w and w.blackout then
-- turn off your own neon signs
endqb-weathersync compatibility
Scripts written for qb-weathersync keep working with Config.Sync.Compat = true (the default):
qb-weathersync:client:DisableSyncandEnableSync(housing, shells, interiors) pause the sync on that client and hold a clear 18:00 sky until it's turned back on.cd_easytime:PauseSyncdoes the same.- The
qb-weathersync:server:setWeather,setTime,toggleBlackout,toggleFreezeTime,toggleDynamicWeatherandRequestStateSyncevents drive SAF Weather, with the same staff check as the panel.