openOMSI GitHub Discord
Plugin API reference

Docs / Plugins / Plugin API reference

Events

7 min readEdit this pagedocs/PLUGIN_API.md

On this page
  1. Plugin lifecycle
  2. Vehicle
  3. Duty and stops
  4. Passengers and tickets
  5. Road and world
  6. Input, camera and game
  7. Panels and plugins
  8. LAN session
  9. Scenery object scripts

Register a handler with omsi.on(name, fn) or define a global function on_<name>. The handler gets the arguments listed after the name. Events that compare two frames (doors, gears, stops, the light ahead) are only worked out while some plugin listens.

Lua
function on_frame(dt) end            -- a global handler
omsi.on("door", function(door, open) -- or as many as you like
  print(door, open)
end)

Plugin lifecycle#

  • start(): Right after the plugin was loaded (also after a reload). Since 0.1.5.
  • stop(): The game ends, or the plugin is about to be loaded again. Since 0.1.5.
  • frame(dt): Every frame of the game, after the bus's own scripts; not while paused. dt is the frame's seconds of game time. Since 0.1.5.
  • pause(): The game was paused (the plugins stand still until resume; nothing else comes in between). Since 0.2.22.
  • resume(): The game goes on after a pause. Since 0.2.22.

Vehicle#

  • vehicle(name): The player got into a vehicle, changed it, or left it (nil). Since 0.1.5.
  • engine_start(): The player's bus's engine started running. Since 0.2.22.
  • engine_stop(): Its engine stopped. Since 0.2.22.
  • gear(new, old): The gear engaged changed (-1 reverse, 0 neutral), where the bus has a gearbox it shows. Since 0.2.22.
  • door(door, open): A door leaf of the player's bus opened (true) or closed: its number from 1, front to back. Since 0.2.22.
  • doors(open): The bus's doors opened (true: one or more open) or were all closed. Since 0.2.22.
  • indicator(new, old): The indicators changed: "off", "left", "right" or "hazard". Since 0.2.22.
  • headlights(new, old): The headlights changed: 0 off, 1 side lights, 2 dipped, 3 high beam. Since 0.2.22.
  • horn(down): The horn started (true) or stopped. Since 0.2.22.
  • handbrake(on): The parking brake was put on (true) or released. Since 0.2.22.
  • stop_request(on): A passenger asked to stop (true), or the request went out. Since 0.2.22.
  • destination(new, old): The destination the bus shows changed. Since 0.2.22.
  • coupled(parts, old): Something was coupled to or uncoupled from the bus: the parts behind it now. Since 0.2.22.
  • crash(energy_kj, speed_kmh): The player's bus crashed: every crash, also one the same as the last (the screen's "Crash: 136 kJ"); above 50 kJ it is a heavy one. Since 0.2.21.
  • pedestrian(count): The bus knocked people down. Since 0.2.21.
  • jolt(along, across, speed_kmh, passengers): The bus braked, sped up or cornered hard enough to cost driving rating (m/s², signed); at most one a second. Since 0.2.21.
  • service(kind, by, amount): The player's bus was serviced or moved. kind: "refuel" (amount: litres put in), "wash" (amount: the dirt left), "repair" (amount: the game minutes it took), "reset" or "teleport"; by: "player", "plugin", "host" or "game". Since 0.2.21.
  • ai_collision(id, energy_kj): The player's bus hit an AI vehicle (its id, as traffic.list gives it) with this energy. Since 0.2.22.

Duty and stops#

  • duty(line, tour): A line and tour were taken (or given up: nil). Since 0.1.10.
  • duty_start(line, tour): A duty was taken. Since 0.2.22.
  • duty_end(line, tour): The duty was given up (or another taken: duty_end of the old one comes first). Since 0.2.22.
  • trip_start(trip, name, terminus): The duty moved on to another trip: its number in the duty (from 1), the timetable's name of the trip and its terminus. Since 0.2.22.
  • trip_done(trip, how, driving, comfort, tickets): A trip of the duty ended, once: its number in the duty, "arrived", "skipped" or "given_up", then its ratings in per cent (driving, comfort, ticket selling). Since 0.2.21.
  • next_stop(new, old): The duty's next stop changed, also to one of the same name (omsi.info().next_stop_number tells them apart). Since 0.1.10.
  • stop_arrive(name, id, number, delay): The bus came to the duty's next stop (within 25 m of it): its name, map object id, number in the trip (from 1) and the delay in seconds (late positive). Since 0.2.22.
  • stop_depart(name, id, number, delay): The bus left the stop it stood at (more than 35 m from it, or the duty moved on): the same values, the delay as it left. Since 0.2.22.
  • stops_skipped(count, due_at, now_at): The duty jumped ahead: the bus passed stops of its trip without stopping (or was moved) and is now at a later one; the stops are numbered in the trip from 1. Since 0.2.21.

Passengers and tickets#

  • passengers(count, old): The number of passengers aboard the player's bus changed. Since 0.2.22.
  • passenger_board(count, stop_id): People got into the player's bus: how many, and the stop they waited at (its map object id, nil when none). Since 0.2.22.
  • passenger_alight(count): People got out of the player's bus. Since 0.2.22.
  • passenger_ticket(passenger): Somebody boarding the player's bus has decided about their ticket, on their way to the door - they wait in the doorway for this frame, so it can still change before they get in and ask for it at the cash desk: {id, age, kind, ticket, name, price, stop, stop_name, destination, stop_number, destination_number} - kind "none", "stamp" or "buy", ticket the ticket pack's (from 1; 0 none fits their age - the desk then asks for the pack's first) with the name and price they will ask for, stop the map object id they board at and stop_name its timetable name, destination the stop they ride to, and where both are in the duty's trip (from 1, nil where the trip does not have them). people.set_ticket(id, ...) changes it. Since 0.3.
  • ticket_sold(name, price): A ticket was sold at the cash desk: its name and price as the bus's ticket list has them. Since 0.2.21.

Road and world#

  • tile(x, y, old_x, old_y): The player's bus drove onto another tile of the map (numbered as global.cfg's [map] list). Since 0.2.22.
  • speed_limit(kmh, old): The speed limit of the lane the bus drives on changed. Since 0.2.22.
  • light_ahead(aspect, distance): The traffic light ahead of the bus (within 80 m) changed or a new one came: its aspect ("red", "red_yellow", "green", "green_yellow", "yellow", "dark", nil when none is ahead any more) and its distance in metres. Since 0.2.22.
  • red_light(speed_kmh): The bus drove past a traffic light showing red (or red and yellow) at more than 5 km/h. Since 0.2.22.
  • weather(name): The weather changed: another weather file, rain or snow beginning or ending, the snow cover, the clouds. Since 0.2.22.
  • minute(hour, minute): The game's clock reached a new minute (also when it was set). Since 0.2.22.
  • hour(hour): The game's clock reached a new hour. Since 0.2.22.
  • day(year, month, day): The game's date changed. Since 0.2.22.

Input, camera and game#

  • key(key, down, combo): A key went down (true) or came up: winit's name of it ("KeyH", "F5", "Numpad8"), and the combination it made with the modifiers held, spelled as input.hotkey takes them ("Ctrl+KeyH", "F5"). Since 0.1.10.
  • controller_button(device, button, down): A button of a steering wheel, joystick or gamepad went down (true) or up: the device's name and the button's number. Since 0.2.22.
  • view(new, old): The view changed ("driver", "pax", "outside", "free", "foot"). Since 0.1.10.
  • menu_open(): The game menu opened. Since 0.2.22.
  • menu_close(): The game menu closed. Since 0.2.22.
  • screenshot(file): A screenshot was taken: its file. Since 0.2.22.

Panels and plugins#

  • ui_click(panel, element): A button (or another clickable part) of one of the plugin's panels was clicked; element is nil for the panel itself. Enter in a text field is a click on it. Since 0.2.21.
  • ui_change(panel, element, value): A checkbox (true/false), slider (its number), text field (its text, at every key) or tabs element (the tab's number from 1) of the plugin's panels was changed by the player. Since 0.2.22.
  • ui_focus(focused): The panels got the mouse or gave it back (also by Esc, or a menu of the game opening). Since 0.2.21.
  • menu_item(id): The player chose one of the plugin's lines in the pause menu (ui.set_menu_item); the menu has closed. Since 0.3.36.
  • setting(key, value): The player changed one of the plugin's settings in its settings panel (plugin.settings). Since 0.2.22.
  • message(from, topic, data): Another plugin sent this one a message (plugin.send, plugin.broadcast): its name, the topic and the data (numbers, texts, tables). Since 0.2.22.

LAN session#

  • lan_join(id, name): A player joined the LAN session (or came back). Since 0.2.22.
  • lan_leave(id, name): A player left the LAN session. Since 0.2.22.
  • lan_message(from, data): The same plugin on another player's game sent this one a message (lan.send): the player's id and the text. Since 0.2.22.
  • lan_chat(name, text): A line was said in the LAN session's chat (by another player or this one). Since 0.2.22.
  • chat_command(text): The player typed a /-line into the chat ("/login name pass"): while a plugin hears this, such a line is not said to the session at all (a password never reaches the other players). Say something back with lan.chat. Since 0.2.22.

Scenery object scripts#

  • object_init(id, type, x, y, z, heading): A scenery object this script drives came within its range (once, again if it leaves and comes back): the map's id of the object, its type (the .sco file's name), where it stands and the way it faces. Only a script a .sco names with [lua_script] hears the object_* events. Since 0.2.22.
  • object_frame(id, dt): A frame of an object this script drives, while it is in range; dt is the game seconds since the last frame of that object (at the rate of the .sco's [lua_rate], else every game frame). Since 0.2.22.
  • object_gone(id): An object this script drives left its range or was unloaded with its tile; its state in the script can go. Since 0.2.22.
  • object_click(id, event): The player clicked the [mouseevent] of a mesh of an object this script drives. Since 0.2.22.

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

↑↓ to move↵ to open