world#
world provides world-level queries and is the registration point for mission event
handlers, letting scripts react to in-game events such as unit spawns, deaths, and
shots fired.
Functions#
- world.addEventHandler(handler)#
Registers
handler(a table with anonEvent(self, event)function) to receive mission events, such asS_EVENT_BIRTH,S_EVENT_DEAD, andS_EVENT_SHOT.- Parameters:
handler (
table) – A table implementingonEvent(self, event).
- world.removeEventHandler(handler)#
Unregisters a previously registered event handler.
- Parameters:
handler (
table) – The handler previously passed toaddEventHandler().
- world.getPlayer()#
Returns the
Unitobject controlled by the local player, ornilif not applicable.- Returns:
The local player’s unit, or
nil.- Return type:
- world.getAirbases()#
Returns a table of all
Airbaseobjects on the current map.- Returns:
All airbases on the map.
- Return type:
table
- world.getMarkPanels()#
Returns a table describing all mark panels currently placed on the F10 map.
- Returns:
Mark panel descriptor tables.
- Return type:
table
- world.searchObjects(category, volume, handler)#
Searches for objects of the given category within a volume (e.g. a sphere or box), calling
handlerfor each match.- Parameters:
category (
number) – Object category to search for.volume (
table) – A volume descriptor table (e.g. sphere or box).handler (
function) – Called with each matching object.
- world.removeJunk(searchVolume)#
Searches
searchVolumeand removes craters, wreckage, and other debris found within it. Wreckage belonging to scenery objects is not removed.- Parameters:
searchVolume (
table) – A volume descriptor table (e.g. sphere or box).- Returns:
The number of objects removed.
- Return type:
number
Example:
local sphere = trigger.misc.getZone('trainingAirbase') sphere.point.y = land.getHeight({x = sphere.point.x, y = sphere.point.z}) local vol = { id = world.VolumeType.SPHERE, params = {point = sphere.point, radius = sphere.radius}, } world.removeJunk(vol)
Weather#
world.weather provides queries and mutators for the mission’s current fog
settings.
- world.weather.getFogThickness()#
Returns the current fog thickness, in meters, at sea level. Returns
0if no fog is present.- Returns:
Fog thickness, in meters.
- Return type:
number
- world.weather.setFogThickness(thickness)#
Sets the fog thickness, in meters, at sea level. Any active fog animation (see
setFogAnimation()) is discarded.- Parameters:
thickness (
number) – Desired fog thickness, in meters. Valid range:100to5000. Passing0removes the fog entirely.
- world.weather.getFogVisibilityDistance()#
Returns the current maximum fog visibility distance, in meters, at sea level. Returns
0if no fog is present.- Returns:
Fog visibility distance, in meters.
- Return type:
number
- world.weather.setFogVisibilityDistance(visibility)#
Sets the maximum fog visibility distance, in meters, at sea level.
- Parameters:
visibility (
number) – Desired visibility distance, in meters. Valid range:100to100000. Passing0removes the fog entirely.
- world.weather.setFogAnimation(keys)#
Gradually changes fog visibility and thickness over time, following a list of
{time, visibility, thickness}keys, instead of applying values abruptly.timeis in seconds, relative to when the function was called, and must strictly increase between successive keys. A key withtime = 0applies its visibility/thickness immediately; any key withtime > 0interpolates from the current fog values (or the previous key) to that key’s values.Passing an empty table (
{}) ornildiscards any active animation, leaving the current thickness and visibility unchanged.- Parameters:
keys (
table) – A list of{time, visibility, thickness}key tables, or{}/nilto discard the current animation.
Example:
-- Fade the fog out completely over 1 minute. world.weather.setFogAnimation({ {60, 0, 0} })
Implementation notes#
addEventHandler() and removeEventHandler() are backed by an
internal registry that tracks handlers keyed by the handler table itself, rather than
by name. Whenever an event occurs, every registered handler’s onEvent function is
invoked in turn.
Note
Because handlers are keyed by table identity rather than name, passing the same
handler table to addEventHandler() twice has no additional effect, and
removeEventHandler() must be given the exact same table reference used
to register it.
world also exposes an additional, undocumented persistence mechanism, allowing a
name/handler pair to be registered so that a value can be produced on demand (e.g.
for saving state) via a validated name and a corresponding retrieval function.
Warning
This persistence mechanism is not part of any officially documented API and its calling context/lifecycle is unverified. Treat it as unverified/experimental behavior; validate carefully before relying on it in a mission.
Footnotes#
Event handlers registered via
world.addEventHandlerare the primary mechanism for reacting to gameplay events in mission scripts.Event tables passed to
onEventinclude anidfield identifying the event type, along with event-specific fields such asinitiatororweapon.There is no
world.terraintable in the SSE. Terrain-related queries (elevation, surface type, line-of-sight, etc.) live under the separate land singleton instead.