os.time

From Wiki G1R-MP G1 Remake Multiplayer
Revision as of 20:40, 21 September 2026 by QCherry (talk | contribs) (Release 0.1.4 BUILD133 / Protocol 36 and document authenticated event origin)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Available since update 0.1.4, BUILD126. Available in both client and server resource scripts with the corresponding updated binary. The current public release is 0.1.4 / Protocol 36.

Returns the current host's wall-clock time as Unix seconds. This is a deliberately restricted function, not access to Lua's full operating-system library.

Syntax

local timestamp = os.time()

Parameters and return value

No parameters are accepted. Returns an integer-valued Lua number: seconds since the Unix epoch (1970-01-01 UTC). Passing any argument, including nil or a date table, raises a Lua error. Standard Lua's os.time(table) overload is not supported.

Example: ordinary random choices

Seed once when the resource starts, not before every random draw:

math.randomseed(os.time())
local roll = math.random(1, 100)
outputDebugString("Roll: " .. roll)

This is not cryptographically secure randomness. Resources seeded in the same second may produce the same sequence. Do not use it for passwords, authentication tokens or security-sensitive identifiers.

Sandbox and clock behaviour

  • The host creates a fresh resource-local os table containing only time; it never opens the native OS library.
  • os.execute, os.exit, os.getenv, os.remove, os.rename, os.tmpname, os.setlocale and all other OS-library functions remain unavailable.
  • Filesystem, process execution, native module loading and Lua bytecode restrictions remain in place. See Scripting limits.
  • This is not the in-game time. The client reads its own computer clock; the server reads its own host clock. Client timestamps are not authoritative or automatically synchronized.
  • Wall-clock adjustments can move this value forwards or backwards. Use getTickCount for elapsed-time measurement.
  • Public 0.1.3 and earlier development builds do not expose this function; an updated script alone does not enable it.