Skip to main content

Weather (server)

On the server, the Weather table syncs the world's tornado and cloud settings to every player.

Available on: Server

See also: Weather (how weather sync works, sandstorms), Weather (client)

Functions​

Weather.SyncAct(act, ...)​

Performs a weather action for every player: spawn or despawn the world tornado. The arguments after act depend on the action:

actArgumentsWhat it does
WeatherAct.SpawnTornadoposition (vec3), formTime (number)(re)starts the tornado at position; it takes formTime to form
WeatherAct.DespawnTornadotime (number)makes the tornado dissipate over time

The times are passed to the game as they are; the default scripts use 5.0, which reads as seconds. Spawning a tornado while one exists restarts it at the new position.

Side: Server

Parameters

NameTypeDescription
actWeatherActthe action
...the action's arguments, see the table above

Returns: nothing

Notes: raises a Lua error for an act out of range, a missing argument, or a non-finite position or time.

Example

local function isAdmin(client)
return client:HasAcl(AclLevel.Admin) or client:HasAcl(AclLevel.Owner)
end

Net.AddEvent("SpawnTornado", function(position)
if isAdmin(Net.Sender()) then
Weather.SyncAct(WeatherAct.SpawnTornado, position, 5.0)
end
end)

Net.AddEvent("DespawnTornado", function()
if isAdmin(Net.Sender()) then
Weather.SyncAct(WeatherAct.DespawnTornado, 5.0)
end
end)

Weather.SyncProperty(property, value)​

Sets one weather property for every player. The value's type depends on the property:

PropertyValue
WeatherProperty.TornadoPositionvec3: moves the tornado to this position
WeatherProperty.TornadoStateTornadoState: Forming, Moving, Stopping, Stopped, Dissipating, Disappearing or WaitingBeforeResetting
WeatherProperty.CloudsAmbientSkylightColorvec3: the color of the light from the sky (x, y, z = red, green, blue)
WeatherProperty.CloudsDirectSunlightColorvec3: the color of the direct sunlight through the clouds
WeatherProperty.CloudsAmbientSaturationnumber
WeatherProperty.CloudsAmbientIntensitynumber
WeatherProperty.CloudsSunIntensitynumber
WeatherProperty.CloudsScatteringCoeffnumber: how much the clouds scatter light
WeatherProperty.CloudsExtinctionCoeffnumber: how much the clouds absorb light (denser, darker clouds)
WeatherProperty.CloudsForwardAnisoScatteringnumber
WeatherProperty.CloudsBackwardAnisoScatteringnumber
WeatherProperty.CloudsMaxLightConeDistancenumber
WeatherProperty.CloudsMaxPrecipitationDarkeningFactornumber: how much rain clouds darken
WeatherProperty.CloudsLayerHeightLownumber: the height of the cloud layer's bottom
WeatherProperty.CloudsLayerHeightHighnumber: the height of the cloud layer's top

The cloud values go straight into the game's cloud renderer; their useful ranges are the game's and are not documented here, so start from small changes. The tornado properties only do something while a tornado exists. See WeatherProperty for the full list.

Side: Server

Parameters

NameTypeDescription
propertyWeatherPropertywhich property to set
valuevec3, integer or numberthe new value, see the table above

Returns: nothing

Notes: called without a value it does nothing. Raises a Lua error for a property out of range, a value of the wrong type, a non-finite value, or a tornado state out of range.

Example

-- move the tornado to where an admin aims
Net.AddEvent("MoveTornado", function(position)
local client = Net.Sender()

if client:HasAcl(AclLevel.Admin) then
Weather.SyncProperty(WeatherProperty.TornadoPosition, position)
end
end)

-- a stormy sky for everyone, also for players who join later
Weather.SyncProperty(WeatherProperty.CloudsSunIntensity, 0.2)
Weather.SyncProperty(WeatherProperty.CloudsDirectSunlightColor, vec3(0.6, 0.6, 0.7))

-- stop the tornado where it is
Weather.SyncProperty(WeatherProperty.TornadoState, TornadoState.Stopped)