Docs / Plugins / Plugin API reference
The game
omsi.game.*, omsi.info and the log functions: the game's state, version, settings, commands and logging.
omsi.command#
omsi.command(name) → boolean
Does what a line of the game menu does: refuel, wash, repair, shot, save, load, weather, later, earlier, info, timetable, reset, couple, uncouple; true when the game knows it (it runs after the frame).
Parameters: name string.
Since 0.1.10. Permission: world_write.
omsi.debug#
omsi.debug([...]) → nil
A line of the log's debug level (shown with RUST_LOG=debug).
Parameters: ... any, optional.
Since 0.2.22.
omsi.error#
omsi.error([...]) → nil
The same as an error line (the plugin goes on).
Parameters: ... any, optional.
Since 0.2.22.
omsi.game.action#
omsi.game.action(name) → boolean
A game action of keyboard.cfg's [game] (sim_pause, view_set_map, view_toggle_informationdisplay, view_set_schedule, ...), as its key does; true when the game knows it.
Parameters: name string.
Since 0.2.22. Permission: world_write.
omsi.game.api#
omsi.game.api() → integer
The version of the plugin interface (api_abi of an .oop; raised only when something is taken away or changes).
Since 0.2.22.
omsi.game.fps#
omsi.game.fps() → number or nil
Frames a second now.
Since 0.2.22.
omsi.game.has#
omsi.game.has(name) → boolean
Whether this game has an API function ("weather.set"): for a plugin that should also run in an older openOMSI.
Parameters: name string.
Since 0.2.22.
if omsi.game.has("weather.set") then omsi.weather.set({ temperature = 20 }) endomsi.game.menu_open#
omsi.game.menu_open() → boolean
Whether the game menu is open.
Since 0.2.22.
omsi.game.notify#
omsi.game.notify(text, [kind], [seconds]) → boolean
A notification of the game's own (the cards the server's messages use): kind "info", "warning" or "alert".
Parameters: text string; kind string, optional; seconds number, optional.
Since 0.2.22. Permission: ui.
omsi.game.platform#
omsi.game.platform() → string
The system the game runs on: "windows", "macos", "linux", "android".
Since 0.2.22.
omsi.game.screenshot#
omsi.game.screenshot() → string or nil
Takes a screenshot with the next frame, as the camera key does; the file it goes to (the screenshot event says when it is there).
Since 0.2.22. Permission: ui.
omsi.game.settings#
omsi.game.settings() → table
The settings a plugin may read: graphics ("vanilla", "vanilla_plus", "enhanced"), language (the cockpit's, "ENG"), ui_language, ui_scale, volume, fov, render_scale, max_fps, fullscreen, vsync, msaa, shadows, time_speed, units ("metric": speeds are km/h everywhere), ...
Since 0.2.22.
omsi.game.stats#
omsi.game.stats() → table
This session's counts, as the personnel file has them: km, stops_served, stops_skipped, crashes, heavy_crashes, pedestrians, tickets, cash, passengers, ...
Since 0.2.22.
omsi.game.vehicles#
omsi.game.vehicles() → list of {file, name}
The vehicles installed, as the game's vehicle menu lists them (file for bus.change).
Since unreleased.
omsi.game.version#
omsi.game.version() → string
The game's version ("0.2.22").
Since 0.2.22.
omsi.info#
omsi.info() → table
What the game is doing: map, clock (seconds since midnight), day, year, view, paused, on_foot, multiplayer, traffic, speed, delay, map_path, version; with a bus also tile_x, tile_y, tile_pos_x, tile_pos_y, heading, vehicle_manufacturer, vehicle_model, destination, passengers; crashes, heavy_crashes, pedestrians_hit; situation;
on a duty also line, tour, trip, trips, trip_name, terminus, stops, trip_done, next_stop, next_stop_number, next_stop_arrival, next_stop_departure, next_stop_id, at_stop, previous_stop, previous_stop_id, next_stop_distance, next_stop_distance_nav, previous_stop_distance (see the plugin docs for each).
Since 0.1.10.
| Key | Value |
|---|---|
| map | the map's name |
| map_path | the map's global.cfg |
| clock | seconds since midnight |
| day, year | the game's date |
| view | the view (driver, pax, outside, free, foot) |
| paused, on_foot, multiplayer | booleans |
| traffic | number of AI vehicles |
| speed | km/h |
| delay | seconds, late positive |
| version | openOMSI's version |
| situation | the situation file the game started from; nil for a new game |
With a bus:
| Key | Value |
|---|---|
| tile_x, tile_y | its tile, numbered as global.cfg's [map] list |
| tile_pos_x, tile_pos_y | metres inside that tile (x east, y north) |
| heading | degrees clockwise from north |
| vehicle_manufacturer, vehicle_model | the parts of its name |
| destination | the terminus the bus shows |
| passengers | people aboard |
| crashes, heavy_crashes, pedestrians_hit | this session, as the personnel file counts them |
On a duty:
| Key | Value |
|---|---|
| line, tour | the duty |
| trip, trips | the trip's number in the duty, and how many there are |
| trip_name, terminus | the timetable's name of the trip, its terminus |
| stops | stops of the trip |
| trip_done | true once the trip is over (see below) |
| next_stop, next_stop_number | name, and number from 1 |
| next_stop_arrival, next_stop_departure | timetable times |
| next_stop_id | the stop's map object id |
| at_stop | true while the bus stands at the next stop |
| previous_stop, previous_stop_id | the last stop before the next one; none before the first |
| next_stop_distance, previous_stop_distance | straight-line metres, where the stop's place is known |
| next_stop_distance_nav | the navigator's route distance in metres |
trip_done is true once the bus has reached the trip's last stop, the stop was skipped, or a saved game was left there. The duty moves on to the next trip only a minute before it leaves.
A stop's name can stand for two stops; its id cannot.
next_stop_distance_nav is nil when both the navigator and the route arrows are off (the pause menu included). While the navigator says "Recalculating route", it keeps the last value.
local i = omsi.info()
print(i.map, i.line, i.next_stop, i.delay)omsi.info_value#
omsi.info_value(key) → any
One value of info() without building the whole table: cheaper for a plugin that reads one or two every frame.
Parameters: key string.
Since 0.2.22.
local delay = omsi.info_value("delay")omsi.log#
omsi.log([...]) → nil
A line in game.log, tagged [lua <name>] (print does the same).
Parameters: ... any, optional.
Since 0.1.5.
omsi.log("trip done", 136, 3)omsi.warn#
omsi.warn([...]) → nil
The same as a warning.
Parameters: ... any, optional.
Since 0.1.5.
Something wrong or missing? Fix it on GitHub or open an issue.