> For the complete documentation index, see [llms.txt](https://sbscripts.gitbook.io/sb-scripts/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sbscripts.gitbook.io/sb-scripts/sb-weather/how-it-works.md).

# How It Works

* **Regions.** Each region has its own weather, temperature, wind and humidity. The client checks the player's GTA zone every 1.5 seconds and blends to the new region's weather when they cross over (`Config.Cycle.ZoneTransition`). Regions are defined in `shared/regions.lua`. Unlisted zones fall back to `Config.DefaultRegion`. Custom maps can use `areas` circles.
* **Cycle and forecast.** Each region moves through its enabled weathers in natural steps, for example sunny to clouds to overcast to rain, never sunny straight to storm. It keeps a queue of upcoming weathers, and that queue is the forecast shown in the tablet. In the tablet you choose which weathers each region cycles through, and the choice is saved.
* **Temperature.** Each weather has a °C range, and each region adds a climate offset. Sandy is hotter and Chiliad is colder. The temperature follows a daily curve, coolest at 05:00 and warmest at 15:00. The server, client and UI all use the same formula.
* **Saved state.** Region weather, the forecast queue, cycle settings, locks, blackouts, the clock, time speed, presets, widget settings and change history are all stored in MySQL and restored after a restart.
* **Sync.** All state goes out through three `GlobalState` keys, so nothing is sent every frame. Clients work out the clock locally from a base minute and the time speed. The server re-syncs it every 60 seconds.
* **Performance.** The client runs one 1 second clock loop and one 1.5 second region loop. The server runs one 5 second cycle check and one 60 second clock re-sync and save. The NUI only receives messages while a screen is open.
