fivemweathertime-syncatmosphereimmersion
Weather and Time Sync in FiveM — Create an Immersive Atmosphere
March 22, 2026
2 min read
5 views
Weather and Time Sync in FiveM
Weather and time synced across servers creates a shared experience and atmosphere that makes RP more interesting.
Basic Time Sync
-- server.lua
local serverTime = { hour = 12, minute = 0 }
local TIME_MULTIPLIER = 2 -- time is 2x faster than actual time
Citizen.CreateThread(function()
while true do
Citizen.Wait(30000) -- updated every 30 seconds realtime
serverTime.minute = serverTime.minute + (TIME_MULTIPLIER)
if serverTime.minute >= 60 then
serverTime.minute = serverTime.minute - 60
serverTime.hour = serverTime.hour + 1
end
if serverTime.hour >= 24 then
serverTime.hour = 0
end
-- Broadcast to everyone
TriggerClientEvent('weather:syncTime', -1, serverTime.hour, serverTime.minute)
end
end)
-- Send time to the player who just joined.
AddEventHandler('playerJoining', function()
Citizen.SetTimeout(3000, function()
TriggerClientEvent('weather:syncTime', source, serverTime.hour, serverTime.minute)
end)
end)
-- client.lua
RegisterNetEvent('weather:syncTime')
AddEventHandler('weather:syncTime', function(hour, minute)
NetworkOverrideClockTime(hour, minute, 0)
end)
Dynamic Weather System
-- server.lua
local weatherTypes = {
'EXTRASUNNY', 'CLEAR', 'CLOUDS', 'SMOG',
'FOGGY', 'OVERCAST', 'RAIN', 'THUNDER',
'CLEARING', 'NEUTRAL', 'SNOW', 'BLIZZARD'
}
local currentWeather = 'CLEAR'
local nextWeather = 'CLEAR'
local weatherTransition = false
-- Change weather randomly every 15-45 minutes.
local function ScheduleWeatherChange()
local delay = math.random(15, 45) * 60 * 1000
Citizen.SetTimeout(delay, function()
-- Select new weather (bias towards weather that makes sense)
local weights = {
EXTRASUNNY = 15, CLEAR = 25, CLOUDS = 20,
OVERCAST = 15, RAIN = 15, THUNDER = 5,
FOGGY = 5
}
local total = 0
for _, w in pairs(weights) do total = total + w end
local roll = math.random(total)
local cumulative = 0
for weather, weight in pairs(weights) do
cumulative = cumulative + weight
if roll <= cumulative then
nextWeather = weather
break
end
end
TriggerClientEvent('weather:change', -1, nextWeather)
currentWeather = nextWeather
ScheduleWeatherChange() -- schedule next time
end)
end
ScheduleWeatherChange() -- start loop
-- client.lua
local currentWeather = 'CLEAR'
RegisterNetEvent('weather:change')
AddEventHandler('weather:change', function(weather)
-- smooth transition
SetWeatherTypeOvertimePersist(weather, 30.0) -- Change in 30 seconds.
currentWeather = weather
-- Notify the player
local weatherLabels = {
CLEAR = 'clear sky',
RAIN = 'Rain',
THUNDER = 'thunderstorm',
SNOW = 'It's falling snow',
FOGGY = 'thick fog'
}
if weatherLabels[weather] then
exports['M2.Notify']:Notify('info', 'Weather: ' .. weatherLabels[weather], 4000)
end
end)
Season System
-- server.lua
local seasons = {
{ name = 'Summer', weatherWeights = { EXTRASUNNY = 40, CLEAR = 40, RAIN = 20 } },
{ name = 'rainy season', weatherWeights = { RAIN = 40, THUNDER = 20, OVERCAST = 40 } },
{ name = 'Winter', weatherWeights = { CLOUDS = 30, FOGGY = 30, CLEAR = 40 } }
}
local currentSeason = 1
-- Change season every 7 days real-time
local SEASON_DURATION = 7 * 24 * 60 * 60 * 1000
Citizen.SetTimeout(SEASON_DURATION, function()
currentSeason = (currentSeason % #seasons) + 1
TriggerClientEvent('weather:season', -1, seasons[currentSeason].name)
end)
Blackout System (Event)
-- Server: Turn on/off lights in the entire city.
RegisterCommand('blackout', function(source, args)
if not IsPlayerAceAllowed(tostring(source), 'admin') then return end
local state = args[1] == 'on'
TriggerClientEvent('weather:blackout', -1, state)
end, false)
-- Client
RegisterNetEvent('weather:blackout')
AddEventHandler('weather:blackout', function(state)
SetArtificialLightsState(state) -- Turn off/on street lights.
SetArtificialLightsStateAffectsVehicles(state)
end)
Summary
Good weather and time sync create a shared world where players can live together. Dynamic weather increases unpredictability. That makes every gameplay session different.
Related Articles
Breaking: GTA Online อัพเดท "Money Fronts" — FiveM Server Owners ต้องทำอะไร?
Rockstar ปล่อย GTA Online อัพเดท Money Fronts มีผลกระทบต่อ FiveM servers บางส่วน นี่คือสิ่งที่ต้องทำทันทีหลังอัพเดท
Community Spotlight: Script และ Projects ที่น่าสนใจจาก FiveM Community
รวม scripts, tools และ projects ที่โดดเด่นจาก FiveM community ในช่วงที่ผ่านมา ตั้งแต่ free resources ถึง open-source projects
txAdmin อัพเดทใหม่ — Dashboard, Diagnostics และ Ban System ที่ดีขึ้น
txAdmin ซึ่งตอนนี้เป็นส่วนหนึ่งของ Cfx.re อย่างเป็นทางการ ได้รับการอัพเดทครั้งใหญ่ มี features ใหม่ที่ทำให้ Server Management ง่ายขึ้นมาก