weather

Rain, thunderstorms, snow, fog and the cloud cover, with presets that fade the map's weather in and out (since API 4).

The weather of the hunt: rain (streaks around the hunter slanted by the wind, splashes, a darker and wetter light, its sound), thunderstorms (lightning that lights up the sky and the land, a bolt, thunder after a delay that grows with the distance), snow (Ice Age's snowfall, now in Dinosaur Hunter too), fog and a cloud cover that hides the sky. weather.set(preset, seconds) fades all of it, and the map's own world.weather fields (fog, sky, sun and shadow colours, clouds) with it, so a hunt can turn stormy over a minute and clear up again.

Presets are made from the map's own weather (a night map stays dark): map (the map's own, as loaded), clear (the same without rain or snow), overcast, fog, rain, storm, snow, blizzard. Everything is undone when your mod unloads, like world.weather; a new map starts with its own weather. The weather guide has the details and an example.

Functions

# weather.set(preset, seconds?)

hunt only since API 4

Fades the weather to a preset (or to the values of a table) over seconds. A table without preset changes only the values it names; with one, it is the preset with those values changed (current().preset is "custom" then). In a hunt: the weather belongs to the loaded map (outside a hunt it raises an error).

ParameterType
presetstring|tablea preset's name, or a table: preset (optional: the start) and any of fogStart, fogEnd (units), skyColor, sunColor, shadowColor, skyPlaneColor (Color), cloudsSpeed, cover (0-1), rain (0-1), snow (0-1), lightning (strikes per minute, 0-60)
seconds optionalnumberthe fade, 0-3600 (default 0: at once)
on("hunt_start", function()
  weather.set("overcast")             -- at once
  timer.after(30, function() weather.set("storm", 60) end)  -- the storm rolls in over a minute
end)

-- your own look: the rain preset with a green sky and less rain
weather.set({preset = "rain", rain = 0.4, skyColor = "#405848"}, 20)

# weather.current() → table|nil

since API 4

The weather now: the last preset set (map before any), the seconds left of the fade, every value as it is at this moment and target, where the fade goes. The colours are the weather's own; world.weather reads what is drawn (with the rain's light and the lightning's flash on top).

Returns
table|nil{preset, fade, fogStart, fogEnd, skyColor, sunColor, shadowColor, skyPlaneColor, cloudsSpeed, cover, rain, snow, lightning, target = {...}}; nil outside a hunt
local w = weather.current()
print(w.preset, w.rain, w.fade)  -- storm 0.62 31.5

# weather.presets() → table

since API 4

The presets: map, clear, overcast, fog, rain, storm, snow, blizzard.

Returns
tablethe preset names

# weather.reset(seconds?)

hunt only since API 4

Back to the map's own weather (the map preset), at once or in a fade. In a hunt: the weather belongs to the loaded map (outside a hunt it raises an error).

ParameterType
seconds optionalnumberthe fade (default 0)

# weather.rain(intensity?, seconds?) → number

hunt only since API 4

The rain: weather.rain() reads it, weather.rain(0.8, 20) fades it. Rain on a bright sky brings its own darker light and clouds; the presets rain and storm come with their own sky.

ParameterType
intensity optionalnumber0-1; nil: none (the map's)
seconds optionalnumberthe fade
Returns
numberthe rain now

# weather.snow(amount?, seconds?) → number

hunt only since API 4

The snowfall, in both games (Ice Age: the map's own snow; Dinosaur Hunter: the same snowfall made for it).

ParameterType
amount optionalnumber0-1 (1: 2048 flakes, as Ice Age's snow_density); nil: the map's
seconds optionalnumberthe fade
Returns
numberthe snow now

# weather.lightning(perMinute?, seconds?) → number

hunt only since API 4

Random lightning: strikes per minute (on average), each anywhere from about a hundred metres to three kilometres away. The lightning event comes before each.

ParameterType
perMinute optionalnumber0-60; nil: none
seconds optionalnumberthe fade
Returns
numberstrikes per minute now

# weather.cover(amount?, seconds?) → number

hunt only since API 4

The clouds that hide the sky, drawn in the sky colour (1: the sky is the fog's colour). Rain and snow bring some by themselves.

ParameterType
amount optionalnumber0-1; nil: none
seconds optionalnumberthe fade
Returns
numberthe cover now

# weather.strike(x?, z?) → table|nil

hunt only since API 4

A lightning strike now: the flash, the bolt from the clouds, and its thunder after distance / 128 / 343 seconds (sound at 343 m/s). Works in any weather. In a hunt: the weather belongs to the loaded map (outside a hunt it raises an error).

ParameterType
x optionalnumberwhere (default: a random place around the hunter)
z optionalnumber
Returns
table|nil{x, z, distance, delay}: distance in units, delay = seconds until the thunder; nil when a lightning handler cancelled it
local x, _, z = player.pos()
local fx, fz = player.forward()
weather.strike(x + fx * 60000, z + fz * 60000)   -- 470 m ahead: thunder 1.4 s later