OPX//77
opx_infinityweather

Server

Last updated on

The weather contract on the server — read and change the clock and the sky.

local weather = OPX.Api.Get('weather')

From server code inside opx_infinity. Nothing yields. Every change is published to all clients at once. reason is free text carried in the snapshot for diagnostics.

Ready

Whether the weather table has a usable row.

weather.Ready()

Returns

  • boolean

Status

The current clock and sky, as a plain table (not a Result).

weather.Status()

Returns

  • table
    • hour, minute, second: number
    • dayLengthMinutes: number
    • timeFrozen, weatherFrozen: boolean
    • weather: string
    • nextRollInSeconds: number? — nil while frozen
    • revision: number

StatusText

One-line summary, as the console sees it.

weather.StatusText()

Returns

  • string

Presets

The live weather table. Do not modify it.

weather.Presets()

Returns

  • table[] — { NAME, PRESET, WEIGHT, MIN_SECONDS, MAX_SECONDS, TRANSITION_SECONDS }

SetTime

Sets the clock.

weather.SetTime(seconds, reason)

Parameters

  • seconds: number
    • Seconds since midnight; wrapped into one day.
  • reason?: string

Returns

  • Result — error invalid_time when seconds is not a finite number
Example
weather.SetTime(22 * 3600, 'night event') -- 22:00

SetTimeFrozen

Holds or releases the clock.

weather.SetTimeFrozen(frozen, reason)

Parameters

  • frozen: boolean
  • reason?: string

SetDayLength

Changes how many real minutes a game day lasts.

weather.SetDayLength(minutes, reason)

Parameters

  • minutes: number
    • 1..10080; under 12 is refused.
  • reason?: string

Returns

  • Result — errors invalid_day_length, day_too_short

SetWeather

Crosses to a weather and reschedules the next roll.

weather.SetWeather(name, transitionSeconds, reason)

Parameters

  • name: string
    • A row's NAME or PRESET.
  • transitionSeconds?: number
    • 0..300. Default: the row's TRANSITION_SECONDS.
  • reason?: string

Returns

  • Result — errors no_presets, unknown_preset, invalid_transition
Example
local set = weather.SetWeather('rain', 30, 'storm event')
if not set.ok then print(set.error) end

SetWeatherFrozen

Holds or releases the roll schedule. Unfreezing schedules a new roll.

weather.SetWeatherFrozen(frozen, reason)

Parameters

  • frozen: boolean
  • reason?: string

Roll

Picks a different row by weight and applies it.

weather.Roll(reason)

Parameters

  • reason?: string

Returns

  • Result

On this page