local syncPaused = false local pauseHours = nil local function getProvider() local provider = Config and Config.WeatherResource if type(provider) ~= "string" or provider == "" or provider == "none" then return nil end return provider end local function resourceStarted(name) return GetResourceState(name) == "started" end local function easytimePaused() if not resourceStarted("cd_easytime") then return false end local ok, state = pcall(function() return exports["cd_easytime"]:GetPauseSyncState() end) return ok and state == true end function stopWeatherResource(opts) local provider = getProvider() if not provider then return false end if type(opts) == "number" then opts = { hours = opts } end opts = type(opts) == "table" and opts or {} if syncPaused then if provider == "cd_easytime" and opts.hours ~= nil and opts.hours ~= pauseHours then pauseHours = tonumber(opts.hours) or 20 TriggerEvent("cd_easytime:PauseSync", false) Wait(50) CreateThread(function() TriggerEvent("cd_easytime:PauseSync", true, pauseHours) end) Wait(100) end return true end if provider == "qb-weathersync" or provider == "qbx_weathersync" then if not resourceStarted(provider) and not resourceStarted("qb-weathersync") and not resourceStarted("qbx_weathersync") then debugPrint(("[WeatherSync] %s is not started"):format(provider)) return false end TriggerEvent("qb-weathersync:client:DisableSync") syncPaused = true debugPrint(("[WeatherSync] Disabled %s"):format(provider)) return true end if provider == "weathersync" then if not resourceStarted("weathersync") then debugPrint("[WeatherSync] weathersync is not started") return false end TriggerEvent("weathersync:toggleSync") syncPaused = true debugPrint("[WeatherSync] Toggled weathersync off") return true end if provider == "cd_easytime" then if not resourceStarted("cd_easytime") then debugPrint("[WeatherSync] cd_easytime is not started") return false end pauseHours = opts.hours ~= nil and (tonumber(opts.hours) or 20) or 20 CreateThread(function() TriggerEvent("cd_easytime:PauseSync", true, pauseHours) end) local deadline = GetGameTimer() + 1500 while GetGameTimer() < deadline do if easytimePaused() then break end Wait(50) end if not easytimePaused() then CreateThread(function() TriggerEvent("cd_easytime:PauseSync", true, pauseHours) end) Wait(100) end syncPaused = true local verified = easytimePaused() if not verified then debugPrint("^3[WeatherSync]^0 cd_easytime PauseSync did not verify — relying on local keep-alive") end debugPrint(("[WeatherSync] Paused cd_easytime sync (hours=%s, verified=%s)"):format( tostring(pauseHours), tostring(verified) )) return true end if provider == "Renewed-Weathersync" then if not resourceStarted("Renewed-Weathersync") then debugPrint("[WeatherSync] Renewed-Weathersync is not started") return false end -- Renewed listens to qb-weathersync + vSync + LocalPlayer.state.syncWeather TriggerEvent("qb-weathersync:client:DisableSync") TriggerEvent("vSync:toggle", false) LocalPlayer.state.syncWeather = false syncPaused = true debugPrint("[WeatherSync] Disabled Renewed-Weathersync") return true end if provider == "vSync" then if not resourceStarted(provider) then debugPrint(("[WeatherSync] %s is not started"):format(provider)) return false end TriggerEvent("vSync:toggle", false) syncPaused = true debugPrint(("[WeatherSync] Disabled %s"):format(provider)) return true end if provider == "av_weather" then if not resourceStarted("av_weather") then debugPrint("[WeatherSync] av_weather is not started") return false end -- Freeze the local player's time/weather so av_weather stops syncing them. -- Only pass hours/minutes if explicitly requested, otherwise the player's -- current time/weather is left untouched (just frozen in place). local hours = opts.hours ~= nil and tonumber(opts.hours) or nil local minutes = opts.minutes ~= nil and tonumber(opts.minutes) or nil TriggerEvent("av_weather:freeze", true, hours, minutes) syncPaused = true debugPrint(("[WeatherSync] Froze av_weather sync (hours=%s, minutes=%s)"):format( tostring(hours), tostring(minutes) )) return true end debugPrint(("^3[WeatherSync]^0 Unknown Config.WeatherResource: %s"):format(tostring(provider))) return false end function startWeatherResource() if not syncPaused then return end syncPaused = false pauseHours = nil local provider = getProvider() if not provider then return end if provider == "qb-weathersync" or provider == "qbx_weathersync" then TriggerEvent("qb-weathersync:client:EnableSync") debugPrint(("[WeatherSync] Re-enabled %s"):format(provider)) return end if provider == "weathersync" then TriggerEvent("weathersync:toggleSync") debugPrint("[WeatherSync] Toggled weathersync on") return end if provider == "cd_easytime" then TriggerEvent("cd_easytime:PauseSync", false) debugPrint("[WeatherSync] Resumed cd_easytime sync") return end if provider == "Renewed-Weathersync" then TriggerEvent("qb-weathersync:client:EnableSync") TriggerEvent("vSync:toggle", true) LocalPlayer.state.syncWeather = true debugPrint("[WeatherSync] Re-enabled Renewed-Weathersync") return end if provider == "vSync" then TriggerEvent("vSync:toggle", true) debugPrint(("[WeatherSync] Re-enabled %s"):format(provider)) return end if provider == "av_weather" then -- Unfreeze and resync the local player's time/weather with the server. TriggerEvent("av_weather:freeze", false) debugPrint("[WeatherSync] Unfroze av_weather sync") end end -- ============================================================ -- av_weather helper wrappers (client exports) -- https://docs.av-scripts.com/guides/weather-script/exports#client -- ============================================================ -- Returns the current zone the player is standing in, or nil if -- av_weather isn't the active provider / isn't started. function getWeatherZone() if getProvider() ~= "av_weather" or not resourceStarted("av_weather") then return nil end local ok, zone = pcall(function() return exports["av_weather"]:getZone() end) if not ok then debugPrint("^3[WeatherSync]^0 getWeatherZone failed to call av_weather:getZone") return nil end return zone end -- Returns the current local blackout state, or nil if unavailable. function getWeatherBlackout() if getProvider() ~= "av_weather" or not resourceStarted("av_weather") then return nil end local ok, state = pcall(function() return exports["av_weather"]:getBlackout() end) if not ok then debugPrint("^3[WeatherSync]^0 getWeatherBlackout failed to call av_weather:getBlackout") return nil end return state end -- Enables/disables rain effects on the local player (useful for interiors/YMAPs -- where rain leaks through the roof). function setWeatherRain(state) if getProvider() ~= "av_weather" or not resourceStarted("av_weather") then return false end local ok = pcall(function() exports["av_weather"]:setRain(state and true or false) end) if not ok then debugPrint("^3[WeatherSync]^0 setWeatherRain failed to call av_weather:setRain") return false end return true end -- Triggers a local (client-only) blackout for the player. function setLocalWeatherBlackout(state) if getProvider() ~= "av_weather" or not resourceStarted("av_weather") then return false end local ok = pcall(function() exports["av_weather"]:localBlackout(state and true or false) end) if not ok then debugPrint("^3[WeatherSync]^0 setLocalWeatherBlackout failed to call av_weather:localBlackout") return false end return true end