Docs / Plugins / Plugin API reference
Reading this reference
On this page
Each function shows its call, what it returns, what it does, its parameters, the openOMSI version that added it, and the permission it needs (if any). [name] is an optional argument.
local x, y, z, heading = omsi.position() -- several results are several values
local ok, why = omsi.weather.set({ temperature = -5 }) -- a change that can failThese rules hold for every function:
- No data means
nil. With no bus, on foot, without a duty, or when a bus lacks a variable, readings arenil(or nothing), lists are empty, and changes returnfalse. A plugin works on every map and with every bus. - Several results come as several values. When there is nothing, none come back:
if omsi.position() then ... end. - Changes that can fail return
true, orfalseand the reason. - A wrong argument is an error that names the function and the argument:
omsi.var: argument 1 (name) must be a string, not table. Catch it withpcallwhere it can happen. - Units: metres; map coordinates x east, y north, z up; headings in degrees clockwise from north; speeds in km/h; times in seconds (clock times: seconds since midnight).
- Lists start at 1, except the arguments and
indexfields of the game data getters and the HOF, which keep OMSI's zero-based numbering. - Newer functions come with newer openOMSI versions.
omsi.game.has("weather.set")tells whether the running game has one.
Permissions#
A plain .lua plugin has every permission but native. Starting a native helper (process) also always needs the player's approval, and native (full access to the computer) only the player gives, in the game's own window or on the launcher's Plugins page, for one build of the plugin's code.
A compiled .oop plugin has only the permissions it declares; calling a function that needs another one raises an error the plugin can catch. Reading the game needs no permission. See Permissions and sandbox.
| Permission | Allows |
|---|---|
ui |
panels, messages, notifications, cables, screenshots |
storage |
omsi.storage and omsi.files |
vehicle_write |
driving the player's bus: variables, triggers, doors, IBIS |
traffic_write |
changing AI traffic, people and other vehicles |
world_write |
time, weather, duty, teleport, game commands |
camera |
moving the camera |
audio |
playing sounds |
network_local |
omsi.send (UDP to this computer) |
network_remote |
omsi.ws (read-only feeds to hosts the player allows) |
lan |
sending in a LAN session, reading the host's session details |
process |
starting native helper programs |
native |
full access to the computer: any file, network address and program, the whole Lua library, native plugins. The plugin asks; only the player gives it, for one build of its code |
Lua-only parts#
These are part of the Lua binding, not of the registry:
| Name | What it is |
|---|---|
omsi.data |
a table saved between sessions (see Saved data) |
omsi.save() |
writes omsi.data now |
omsi.version |
the game's version string |
omsi.name |
the plugin's name |
omsi.ui.version |
the panel feature level, currently 8 |
print(...) |
the same as omsi.log(...) |
function on_<event>(...) |
a global function is a handler of that event |
Other languages#
A WebAssembly plugin calls the same functions by the same names, without omsi.: openomsi.call("ui.set", ...) with the arguments and the result as JSON. The Rust SDK of the openOMSI Development Tools wraps every function in a typed call. Events, timers and watches work the same way.
Something wrong or missing? Fix it on GitHub or open an issue.