openOMSI GitHub Discord
Plugin API reference

Docs / Plugins / Plugin API reference

Scenery objects

3 min readEdit this pagedocs/PLUGIN_API.md

On this page
  1. omsi.object.hide
  2. omsi.object.info
  3. omsi.object.list
  4. omsi.object.meshes
  5. omsi.object.place
  6. omsi.object.reset
  7. omsi.object.set_mesh
  8. omsi.object.set_str
  9. omsi.object.set_var
  10. omsi.object.set_vars
  11. omsi.object.set_visible
  12. omsi.object.str
  13. omsi.object.trigger
  14. omsi.object.var
  15. omsi.scene.objects

omsi.object.* is for scripts that a scenery object's .sco names with [lua_script] (see Scripts of map objects). They only work on objects that script drives; ids come from the object_* events or object.list().

omsi.object.hide#

omsi.object.hide(id, [hidden]) → boolean

Hides scenery object id (hidden false: shows it again): a tree that blocks a view, a wall to drive through. On this game only, for this run.

Parameters: id integer; hidden bool, optional.

Since unreleased. Permission: world_write.

omsi.object.info#

omsi.object.info(id) → table

{id, type, x, y, z, heading, active, distance} of an object: its type (the .sco file's name), where it stands (map coordinates), the way it faces (compass degrees), whether it is in the script's range and how far the listener is from it (m).

Parameters: id integer.

Since 0.2.22.

omsi.object.list#

omsi.object.list() → list of numbers

The ids of the objects this script drives that are loaded now (those within its range are active).

Since 0.2.22.

omsi.object.meshes#

omsi.object.meshes(id) → list of strings

The mesh files of an object, in the order the scripts number them from 1.

Parameters: id integer.

Since 0.2.22.

omsi.object.place#

omsi.object.place(id, at) → boolean

Moves scenery object id - any object a tile of the map places, as scene.objects lists them - to {x, y, z, heading} (each optional: a missing one stays), live: build a road block, open a gate, rearrange a square. On this game only, for this run (the object editor's Ctrl+S saves its own edits, not a plugin's).

Parameters: id integer; at table.

Since unreleased. Permission: world_write.

omsi.object.reset#

omsi.object.reset(id) → boolean

Scenery object id where and as the map has it again.

Parameters: id integer.

Since unreleased. Permission: world_write.

omsi.object.set_mesh#

omsi.object.set_mesh(id, mesh, [transform]) → boolean

Moves, turns and scales one mesh of an object over what its animations do.

mesh is its number from 1 or its file name; transform is {x, y, z, rx, ry, rz, sx, sy, sz, px, py, pz}: a move in metres, a turn about the x, y and z axes in degrees (z up, positive counter-clockwise seen from above), a scale, all about the point (px, py, pz) of the mesh, every key optional.

Without a table the mesh is as the model has it. Objects with a script are redrawn every frame; moving a mesh costs nothing more.

Parameters: id integer; mesh string; transform table, optional.

Since 0.2.22.

Lua
omsi.object.set_mesh(id, "barrier.o3d", { rz = 90, px = 0.1 })

omsi.object.set_str#

omsi.object.set_str(id, name, value) → boolean

Sets a string variable of an object (a display's text, a texture's name).

Parameters: id integer; name string; value string.

Since 0.2.22.

omsi.object.set_var#

omsi.object.set_var(id, name, value) → boolean

Sets a script variable of an object, which its [newanim] animations, [visible] conditions, materials, lamps and sounds read; false when it has none of that name.

Parameters: id integer; name string; value number.

Since 0.2.22.

Lua
omsi.on("object_init", function(id)
  omsi.object.set_var(id, "lamp_on", 1)
end)

omsi.object.set_vars#

omsi.object.set_vars(id, values) → integer

Sets many variables of an object at once (a table name -> number); how many it has.

Parameters: id integer; values table.

Since 0.2.22.

omsi.object.set_visible#

omsi.object.set_visible(id, mesh, [visible]) → boolean

Shows or hides one mesh of an object whatever its [visible] conditions say; without visible the conditions decide again.

Parameters: id integer; mesh string; visible bool, optional.

Since 0.2.22.

omsi.object.str#

omsi.object.str(id, name) → string or nil

A string variable of an object.

Parameters: id integer; name string.

Since 0.2.22.

omsi.object.trigger#

omsi.object.trigger(id, name) → boolean

Runs a {trigger:name} of the object's own .osc script; false when it has none.

Parameters: id integer; name string.

Since 0.2.22.

omsi.object.var#

omsi.object.var(id, name) → number or nil

A script variable of an object (those its [varnamelist] declares, and the builtin ones: Switch, InUse, NightlightA ...); nil when it has none of that name.

Parameters: id integer; name string.

Since 0.2.22.

omsi.scene.objects#

omsi.scene.objects(x, y, [radius]) → list of {id, file, x, y, z, heading, scripted}

Every scenery object placed within radius m (default 100, at most 2000) of x, y on the loaded tiles, with its .sco file where the game knows it.

A plugin that may change the world (world_write, not a vehicle's or an object's script) reaches each one with object.var, object.set_var, object.trigger, object.set_mesh and object.set_visible; scripted says whether it has variables and animations to change.

Parameters: x number; y number; radius number, optional.

Since unreleased.

Something wrong or missing? Fix it on GitHub or open an issue.

↑↓ to move↵ to open