Docs / Plugins / Lua plugins
Reference
On this page
- The player's bus
- Game data getters
- The loaded HOF depot file
- Duty and timetable
- The map
- Scenery objects (for scripts a .sco names)
- AI traffic
- People
- Time
- Weather
- Camera
- Input
- Sound
- On screen
- Cables in the world
- Events, timers and watches
- The plugin itself
- Storage and files
- External programs
- Programs on this computer
- LAN games
- The game
- Helpers
- Events
Every function and event, as the game's API registry describes them (also as JSON in
plugin-api.json, for tools and other plugin languages). [x] is an
optional argument; a permission is what a plugin packed with a list of permissions must have
declared to call the function (a plain .lua file has all except native process access, which always requires player opt-in).
The player's bus#
| Function | Returns | What it does | Since |
|---|---|---|---|
omsi.body_frame([section]) |
x, y, z, rx, ry, rz, fx, fy, fz, ux, uy, uz | The bus's body now, as the last simulation step left it: its origin (map metres) and its model's axes in the world - right, forward and up, each a unit vector - with the heading, the climb and the lean on the springs in them. A point of the model at (mx, my, mz) is at origin + mx·right + my·forward + mz·up. section 1, 2, ... is a section coupled behind (an articulated bus's rear one). Nothing on foot. |
0.2.22 |
omsi.bus.acceleration() |
across, along, up | Its acceleration in its own frame, m/s² without gravity: to the right, forwards, up. | 0.2.22 |
omsi.bus.action(name, [down]) |
boolean | A key action of the vehicles ([vehicles] of keyboard.cfg: horn, parking_brake_toggle, kw_scheinwerfer_toggle, blinker_left_set, ticket_give, ...): pressed and let go, or held (down true) and let go (false). true when the bus knows it. Permission: vehicle_write. |
0.2.22 |
omsi.bus.controls() |
throttle, brake, clutch, steering | What the bus drives with now: the pedals (0 to 1) and the steering (-1 left to 1 right), from the keys, the mouse or a controller. | 0.2.22 |
omsi.bus.damage() |
table or nil | {crashes, last_impact_kj, repair_minutes}: the bus's crashes, the energy of the last one and how long a repair would take (nil: nothing to repair). |
0.2.22 |
omsi.bus.destination() |
name, index | The destination the bus shows and its index in destinations (nothing when none). |
0.2.22 |
omsi.bus.destinations() |
list of tables | The destinations of the bus's depot file: {index, code, name, all_exit} (index from 1, for set_destination). |
0.2.22 |
omsi.bus.dirt() |
number or nil | How dirty the bus is, 0 (clean) to 1. | 0.2.22 |
omsi.bus.door(n) |
boolean or nil | Whether door leaf n (from 1) is open. |
0.2.22 |
omsi.bus.door_count() |
integer | The doorways the door keys work, front to back. | 0.2.22 |
omsi.bus.doors() |
list of numbers | Each door leaf's position, front to back: 0 shut, 1 open (the scripts' door_0, door_1, ...). |
0.2.22 |
omsi.bus.doors_open() |
boolean or nil | Whether any door is open (by the passengers' door flags where the bus has them). | 0.2.22 |
omsi.bus.electrics() |
boolean or nil | Whether the bus's electrics are on (the main switch). | 0.2.22 |
omsi.bus.engine() |
running, rpm, electrics | The engine: whether it runs, its rpm (where the bus shows one) and whether the electrics are on. | 0.2.22 |
omsi.bus.engine_running() |
boolean or nil | Whether the engine runs. | 0.2.22 |
omsi.bus.file() |
string or nil | The bus's .bus file, relative to the game folder. |
0.2.22 |
omsi.bus.fuel() |
number or nil | The fuel in the tank, litres (the scripts' engine_tank_content). |
0.2.22 |
omsi.bus.gear() |
integer or nil | The gear engaged (-1 reverse, 0 neutral), where the bus shows one. | 0.2.22 |
omsi.bus.get_strings([names]) |
table | The same for string variables. | 0.2.22 |
omsi.bus.get_vars([names]) |
table | Many script variables at once: a table name -> value of the names given, or of every variable of the bus without a list. | 0.2.22 |
omsi.bus.handbrake() |
boolean or nil | Whether the parking brake is on. | 0.2.22 |
omsi.bus.headlights() |
integer or nil | The headlights: 0 off, 1 side lights, 2 dipped, 3 high beam. | 0.2.22 |
omsi.bus.horn() |
boolean or nil | Whether the horn sounds. | 0.2.22 |
omsi.bus.indicator() |
string or nil | The indicators: "off", "left", "right" or "hazard". |
0.2.22 |
omsi.bus.interior_light() |
number or nil | The passenger room's light, 0 (off) to 1. | 0.2.22 |
omsi.bus.km_today() |
number or nil | Kilometres driven this session (as the personnel file counts them). | 0.2.22 |
omsi.bus.kneeling() |
boolean or nil | Whether the bus kneels. | 0.2.22 |
omsi.bus.mass() |
number or nil | The bus's mass in kg. | 0.2.22 |
omsi.bus.number() |
string or nil | The bus's fleet number. | 0.2.22 |
omsi.bus.odometer() |
number or nil | The bus's odometer in km. | 0.2.22 |
omsi.bus.orientation() |
heading, pitch, bank | Heading (degrees clockwise from north), pitch (nose up positive) and bank (right side down positive). | 0.2.22 |
omsi.bus.passengers() |
total, seated, standing | The people aboard the bus: all, sitting, standing. | 0.2.22 |
omsi.bus.play_sound(event) |
boolean | Plays the bus's own sound of this event (a trigger name of its sound files, ev_...). Permission: vehicle_write. |
0.2.22 |
omsi.bus.retarder() |
number or nil | The retarder's step, where the bus has one. | 0.2.22 |
omsi.bus.rpm() |
number or nil | The engine's revolutions per minute. | 0.2.22 |
omsi.bus.sales() |
tickets, money | Tickets sold this session and the money taken (the game knows no currency). | 0.2.22 |
omsi.bus.set_destination(index) |
boolean | Shows destination index (from 1, as destinations lists them). Permission: vehicle_write. |
0.2.22 |
omsi.bus.set_indicator(state) |
boolean | Sets the indicators: "off", "left", "right" or "hazard". Permission: vehicle_write. |
0.2.22 |
omsi.bus.set_interior_light(on) |
boolean | Switches the passenger room's light on or off. Permission: vehicle_write. |
0.2.22 |
omsi.bus.set_line(line) |
boolean | Types a line (route) into the bus's IBIS, as the player would. Permission: vehicle_write. |
0.2.22 |
omsi.bus.set_vars(values) |
integer | Sets many script variables at once (a table name -> number); how many the bus has. Permission: vehicle_write. |
0.2.22 |
omsi.bus.shift(gear) |
boolean | Puts a manual gearbox's lever in a gear (-1 reverse, 0 neutral). Permission: vehicle_write. |
0.2.22 |
omsi.bus.sound_horn(down) |
boolean | Holds the horn (true) or lets it go. Permission: vehicle_write. |
0.2.22 |
omsi.bus.start_up() |
string or nil | Starts the bus up the way Shift+U does (the battery, the electrics, the engine) - or shuts a running bus down; what the game says it does. Permission: vehicle_write. |
0.2.22 |
omsi.bus.state() |
table or nil | Everything a dashboard shows, in one table: speed (km/h, signed), gear, engine (running), rpm, electrics, doors_open, indicator, headlights, dirt, passengers, odometer, km_today, throttle, brake, clutch, steering, fuel, handbrake, horn, stop_request (a key is nil where the bus does not have it). |
0.2.22 |
omsi.bus.steering_angle() |
angle, max | The front wheels' angle and the most they turn, degrees (right positive). | 0.2.22 |
omsi.bus.stop_brake() |
boolean or nil | Whether the stop brake (the door brake) holds the bus. | 0.2.22 |
omsi.bus.stop_requested() |
boolean or nil | Whether a passenger has asked to stop. | 0.2.22 |
omsi.bus.ticket_request() |
name, price | The ticket the passenger at the cash desk asks for (nothing when nobody asks). | 0.2.22 |
omsi.bus.tickets() |
list of tables | The tickets the map sells: {name, price, day_ticket}. |
0.2.22 |
omsi.bus.toggle_door([n]) |
boolean | Presses the key of doorway n (from 1; 0 or none: all doors), as the player would. Permission: vehicle_write. |
0.2.22 |
omsi.bus.toggle_handbrake() |
boolean | Puts the parking brake on or off, as its key does. Permission: vehicle_write. |
0.2.22 |
omsi.bus.track() |
table or nil | Where the player's rail vehicle (tram, metro, train) is on its track, as distances along it rather than x and y: {lane, s, lane_length, forward, travelled} - the track (an index into the map's lanes), the metres from its start and its length, whether the vehicle faces the track's direction, and the net metres it has moved along the tracks since it was put on them (they go down, below zero too, while it backs up). nil for a road vehicle. A plugin can work out block sections, distances to a signal or a stop, or a train protection system from it. |
0.3.55 |
omsi.bus.trailers() |
integer or nil | Parts coupled behind the bus (an articulated bus's rear counts). | 0.2.22 |
omsi.bus.triggers() |
list of strings | The names of the bus's script triggers (for trigger, press). |
0.2.22 |
omsi.bus.velocity() |
number or nil | The bus's speed in km/h, negative backwards. | 0.2.22 |
omsi.bus.velocity_vector() |
x, y, z | Its velocity in the world, m/s (x east, y north, z up). | 0.2.22 |
omsi.bus.wheels() |
list of tables | Each wheel: {axle, side, rpm, radius, suspension, driven} (side 0 left, 1 right; suspension the spring's travel). |
0.2.22 |
omsi.distance(x, y) |
number or nil | Metres from the bus to a map point, or nil on foot. |
0.1.10 |
omsi.has_vehicle() |
boolean | true while the player drives a vehicle. |
0.1.5 |
omsi.mesh_point(mesh, x, y, z, [section]) |
x, y, z | Where a point of one of the bus's meshes is now, in map metres: mesh names the mesh's file ("sht_bashmak.o3d", or a part of its path), x, y, z is the point in the model's frame (x right, y forward, z up) as the mesh stands at rest; its animations and the body's lean move it. section (0, the default) looks in a section coupled behind instead (1, 2, ...: an articulated bus's rear part), its point in that section's model frame. For a plugin that lines a part of the bus up with something outside it. Nothing when the bus or the section has no such mesh, or mesh is empty. |
0.2.22 |
omsi.position() |
x, y, z, heading | Where the bus is: map metres (x east, y north, z up) and its heading in degrees clockwise from north; nothing on foot. | 0.1.10 |
omsi.press(name) |
nil | Holds a key of the bus down: fires the trigger name (let it go with release). Permission: vehicle_write. |
0.1.5 |
omsi.release(name) |
nil | Lets a key go: fires <name>_off. Permission: vehicle_write. |
0.1.5 |
omsi.set_str(name, text) |
boolean | Sets a string variable; true when the bus has it. Permission: vehicle_write. |
0.1.5 |
omsi.set_var(name, value) |
boolean | Sets a script variable; true when the bus has that variable. Permission: vehicle_write. |
0.1.5 |
omsi.speed() |
number | The bus's speed in km/h, forwards or backwards (0 on foot). | 0.1.10 |
omsi.str(name) |
string or nil | A string variable of the bus's scripts (IBIS_terminus_name). |
0.1.5 |
omsi.sys(name) |
number or nil | A system variable of the scripts: Time, Day, Weather_Temperature, SunAlt, ... (read only). |
0.1.5 |
omsi.trigger(name) |
nil | A key press of the bus: fires the trigger, then <name>_off. Permission: vehicle_write. |
0.1.5 |
omsi.var(name) |
number or nil | A script variable of the bus (Velocity, elec_busbar_main, the names the .osc files and .opl lists use); nil without a bus or for a name it does not have. |
0.1.5 |
omsi.vars([kind]) |
list of strings | The names of every variable of the bus's scripts, or of every string variable with "str". |
0.1.10 |
omsi.vehicle() |
string or nil | The vehicle's name (manufacturer and type), or nil on foot. |
0.1.5 |
omsi.vehicle_manufacturer() |
string or nil | The manufacturer part of the vehicle's name, as its [friendlyname] has it ("Solaris III Gen"). |
0.2.21 |
omsi.vehicle_model() |
string or nil | The model part of the vehicle's name ("Urbino 10 / 2D"). |
0.2.21 |
Game data getters#
| Function | Returns | What it does | Since |
|---|---|---|---|
omsi.game.queries() |
list of tables | Read-only game data getters: {name, args = {{name, type}, ...}, result}. Names and zero-based indices follow the M.V. getter names, but plugins read the game data directly without executing scripts. rgba means four results in the range 0–255. |
0.3.40 |
omsi.game.query(name, [args], [object]) |
value(s), or nil and reason | Read a getter listed by game.queries from the player's vehicle's HOF, timetable, passengers, tickets, radio, fonts or textures. Arguments are an ordered list (empty by default). No script callback is invoked. STReadPixel returns RGBA without changing the bus's drawing colour. Supply a loaded scripted map object's id as object to read its data, including GetArrBus* on departure boards, without needing a player vehicle. Object ids can be found through map.objects_near. Without object, reads use the player's vehicle. Unknown names, mutating operations and invalid arguments raise an error; no vehicle returns nil and a reason. |
0.3.40 |
The loaded HOF depot file#
| Function | Returns | What it does | Since |
|---|---|---|---|
omsi.hof.busstop(identifier) |
table or nil | The first bus stop whose identifier exactly matches the supplied HOF stop identifier. Returns {index, identifier, strings}; index is zero-based for GetBusstopString and strings[1] is getter field 0. Returns nil without a vehicle, HOF or match. |
0.3.40 |
omsi.hof.get() |
table or nil | A snapshot of every parsed field of the player's loaded HOF: path, name, service_trip, global_strings, string_count_terminus, string_count_busstop, termini, bus_stops, info_trips, info_busstop_lists, info_busstops. Records include their zero-based index; Lua arrays (including strings) start at 1. Returns nil without a vehicle or HOF. No filesystem access or scripts are involved; retain the snapshot until the vehicle or HOF changes. |
0.3.40 |
omsi.hof.terminus(identifier) |
table or nil | The first terminus whose internal identifier exactly matches the supplied timetable terminus, using the same case-sensitive comparison as GetTTTerminusIndex. Returns {index, code, identifier, terminus_stop, all_exit, strings}; index is zero-based for GetTerminusString, strings[1] is getter field 0, and terminus_stop is nil when absent. Returns nil without a vehicle, HOF or match; does not change the duty or destination. |
0.3.40 |
Duty and timetable#
| Function | Returns | What it does | Since |
|---|---|---|---|
omsi.duty.active() |
boolean | Whether the player drives a duty (a line and tour of the timetable). | 0.2.22 |
omsi.duty.at_stop() |
boolean | Whether the bus stands at the next stop (within 25 m of it). | 0.2.22 |
omsi.duty.delay() |
number or nil | Seconds the bus is late (early negative), worked out between the stops as the game's timetable does. | 0.2.22 |
omsi.duty.finish() |
boolean | Gives the duty up (the bus drives on without a timetable); true when there was one. Permission: world_write. |
0.2.22 |
omsi.duty.get() |
table or nil | The duty now: line, tour, trip (its number in the duty, from 1), trips, trip_name, terminus, departure, arrival, stops, next_stop and previous_stop (each a stop: {number, name, id, arrival, departure, stops, x, y, z}), at_stop, trip_done, delay (seconds, late positive). |
0.2.22 |
omsi.duty.next_stop() |
table or nil | The next stop of the trip (as duty.stops gives them). |
0.2.22 |
omsi.duty.set_auto_ibis(on) |
boolean | Whether the game types the duty into the bus's IBIS by itself - line, route, destination and the stop, at Shift+U and --autostart and again as each trip begins (on as a bus is taken). Off, the driver types them, or the plugin with duty.type_ibis. For the bus the player drives now, and while the plugin runs: when it stops or is switched off the game types the IBIS again, unless another plugin still leaves it to the driver. Off lasts for that bus only: after a change of vehicle (the vehicle event) the game types the new one's IBIS again, so a plugin that leaves it to the driver calls duty.set_auto_ibis(false) again there. true when there is a bus. Permission: vehicle_write. |
0.3.41 |
omsi.duty.set_closed_stops(stops, [via]) |
boolean | Closes stops of the duty's route for today - a diversion, roadworks: a list of their names (on every trip of the duty), and the way round them (via). The navigator strikes them through and shows via for the next one; the bus does not call there, and the duty goes on past them without counting them missed (no stops_skipped). Each call replaces the list (64 names at most), an empty one opens them all again; a duty taken anew (duty.start) starts with none. duty.stops marks them closed. true when there is a duty. Permission: world_write. |
0.3.36 |
omsi.duty.skip_stop() |
string or nil | Skips the next stop (the duty goes on to the one after); the name of the stop skipped. Permission: world_write. |
0.2.22 |
omsi.duty.skip_to(stop) |
boolean | Makes stop stop (from 1) of the trip the next one, forwards or back. Permission: world_write. |
0.2.22 |
omsi.duty.start(line, tour, [trip], [stop]) |
true, or false and the reason | Takes a duty, as the game menu's "Line and tour" does: a line and tour of timetable.lines, its trip (from 1 in the order they leave; default the first) and the stop to start at (from 1 among those the trip calls at; default the first). The bus stays where it is. Permission: world_write. |
0.2.22 |
omsi.duty.stops() |
list of tables | The stops of the trip now: {number, name, id, arrival, departure, stops, closed, passed, x, y, z} (stops false: the bus passes it; closed: closed today, duty.set_closed_stops; x, y, z where the stop's place is known; id the map's object id). |
0.2.22 |
omsi.duty.tour() |
table or nil | The complete source tour of the selected duty, even when only one trip was selected. Same structure as timetable.tour; times align with the active duty's service day, with time_offset seconds applied to all trips and stops. |
0.3.40 |
omsi.duty.trip_stops(trip) |
list of tables or nil | The stops of a trip of the duty (from 1), as duty.stops gives them. |
0.2.22 |
omsi.duty.trips() |
list of tables | The trips of the duty: {number, name, line, terminus, departure, arrival, stops}. |
0.2.22 |
omsi.duty.type_ibis() |
boolean | Types the trip under way into the bus's IBIS now - line, route, destination and the stop the bus is at - as Shift+U does (bus.set_line types the line only); with duty.set_auto_ibis on, the next trips follow by themselves. true when there is a duty and a bus. Permission: vehicle_write. |
0.3.41 |
omsi.timetable.buses() |
list of tables | The timetable buses of the AI on the road: {id, line, tour, trip, terminus, departure, next_stop_id, at_stop, trip_done, delay, x, y, number}. |
0.2.22 |
omsi.timetable.lines() |
list of tables | The map's lines: {name, user_allowed, tours}, each tour {number, today, trips} (today: it runs on the game's date). |
0.2.22 |
omsi.timetable.stop_names() |
list of tables | The stops the timetable knows: {id, name} (id the map's object id). |
0.2.22 |
omsi.timetable.stops(line, tour, [trip]) |
list of tables | The stops of a tour's trips (or of its trip trip, from 1 in the order they leave) that the bus calls at: {trip, station, name, departure}. |
0.2.22 |
omsi.timetable.tour(line, tour) |
table, or nil and reason | Read a full tour without taking it: {line, number, ai_group, extra, today, time_offset, trips}. Each trip has number, source_number (both from 1), name, line, terminus, track, reverse, profile_index (from 0), profile (name, factor), departure, arrival, and all stops (id, name, arrival, departure, stops, optional x,y,z). Times are seconds from service-day midnight and can exceed 86400; passing stops are retained. Unknown trip references are skipped, retaining their source numbers. No AI vehicle is reserved. |
0.3.40 |
The map#
| Function | Returns | What it does | Since |
|---|---|---|---|
omsi.map.entrypoints() |
list of tables | The map's start points: {index, name, x, y, z, heading} (index from 1; the place where the game has read its tile). |
0.2.22 |
omsi.map.ground(x, y) |
number or nil | The height of the ground (the road where there is one, else the terrain) at a map point, where its tile is loaded. | 0.2.22 |
omsi.map.info() |
table or nil | {name, friendly_name, path, left_hand_traffic, tile_size}: the map's names, its global.cfg and the side it drives on. |
0.2.22 |
omsi.map.lane(x, y) |
table or nil | The traffic lane nearest to a map point: {index, distance, speed_limit, name, traffic_light}. |
0.2.22 |
omsi.map.name() |
string or nil | The map's name (its folder's). | 0.2.22 |
omsi.map.object(id) |
x, y, z, heading | Where a map object is, by its id (a stop's id of the timetable, say); nothing when the game has not read its tile. | 0.2.22 |
omsi.map.objects_near(x, y, [radius]) |
list of tables | The map objects within radius m (default 50, at most 2000 of them, nearest first): {id, x, y, z, heading, distance}. |
0.2.22 |
omsi.map.place_on_road(x, y) |
boolean | Puts the player's bus on the street nearest to a map point (within 300 m), along it. Permission: world_write. |
0.2.22 |
omsi.map.speed_limit() |
number or nil | The speed limit (km/h) of the lane the player's bus drives on (nil off the lanes). |
0.2.22 |
omsi.map.stops() |
list of tables | The bus stops of the tiles loaded (around the camera): {id, name, x, y, z, heading}. |
0.2.22 |
omsi.map.teleport(x, y, [z], [heading]) |
boolean | Moves the player's bus to a map point (z none: onto the highest ground there) facing heading (default north), as the game menu's move does; the service event says teleport. Permission: world_write. |
0.2.22 |
omsi.map.teleport_to(index) |
boolean | Moves the player's bus to start point index (from 1, as map.entrypoints lists them). Permission: world_write. |
0.2.22 |
omsi.map.terrain(x, y) |
number or nil | The terrain's height alone at a map point. | 0.2.22 |
omsi.map.tile() |
tile_x, tile_y | The tile the player's bus is on (nothing on foot). | 0.2.22 |
omsi.map.tile_at(x, y) |
tile_x, tile_y, local_x, local_y | The tile of a map point and the metres in it (x east, y north). | 0.2.22 |
omsi.map.tiles() |
list of tables | The map's tiles: {x, y, file, loaded} (numbered as global.cfg's [map] list). |
0.2.22 |
omsi.map.to_world(tile_x, tile_y, local_x, local_y) |
x, y | A place given by its tile and the metres in it, in map coordinates. | 0.2.22 |
Scenery objects (for scripts a .sco names)#
| Function | Returns | What it does | Since |
|---|---|---|---|
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). |
0.2.22 |
omsi.object.list() |
list of numbers | The ids of the objects this script drives that are loaded now (those within its range are active). | 0.2.22 |
omsi.object.meshes(id) |
list of strings | The mesh files of an object, in the order the scripts number them from 1. | 0.2.22 |
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. |
0.2.22 |
omsi.object.set_str(id, name, value) |
boolean | Sets a string variable of an object (a display's text, a texture's name). | 0.2.22 |
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. |
0.2.22 |
omsi.object.set_vars(id, values) |
integer | Sets many variables of an object at once (a table name -> number); how many it has. | 0.2.22 |
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. |
0.2.22 |
omsi.object.str(id, name) |
string or nil | A string variable of an object. | 0.2.22 |
omsi.object.trigger(id, name) |
boolean | Runs a {trigger:name} of the object's own .osc script; false when it has none. |
0.2.22 |
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. |
0.2.22 |
AI traffic#
| Function | Returns | What it does | Since |
|---|---|---|---|
omsi.other_body_frame(id, [section]) |
x, y, z, rx, ry, rz, fx, fy, fz, ux, uy, uz | body_frame of one of others: its body now, origin and axes. |
0.2.22 |
omsi.other_mesh_point(id, mesh, x, y, z, [section]) |
x, y, z | mesh_point of one of others: where a point of one of its meshes (or, with section, of one of its coupled sections') is now. |
0.2.22 |
omsi.other_var(id, name) |
number or nil | A script variable of one of others, or nil. |
0.2.21 |
omsi.others([radius]) |
list of tables | The other vehicles within radius m of the bus (default 300): each {id, kind, name, x, y, z, heading}, kind being "ai" (the traffic) or "player" (another player's bus in a LAN game); empty on foot. |
0.2.21 |
omsi.set_other_var(id, name, value) |
boolean | Sets a script variable of one of others; true when that vehicle has it. An AI vehicle keeps it until its scripts write it again; another player's bus takes its values from the network again. Permission: traffic_write. |
0.2.21 |
omsi.traffic.ahead([reach]) |
table or nil | The AI vehicle ahead of the player's bus within reach m (default 100) and 20° of its heading, with its distance: for a distance warning or a cruise control. |
0.2.22 |
omsi.traffic.clear() |
integer or nil | Takes every car not running to a timetable off the road; how many went. Permission: traffic_write. |
0.2.22 |
omsi.traffic.counts() |
driving, buses, asleep, parked | The AI vehicles: driving, timetable buses among them, asleep out of range, parked. | 0.2.22 |
omsi.traffic.density() |
cars, share | How many cars the traffic keeps around the camera, and the share of them that do not run to a timetable (0 to 1). | 0.2.22 |
omsi.traffic.get(id) |
table or nil | One AI vehicle by its id, as traffic.list gives them. |
0.2.22 |
omsi.traffic.light_ahead([reach]) |
table or nil | The traffic light the player's bus comes to within reach m (default 80): {aspect, change_in, distance} - aspect "red", "red_yellow", "green", "green_yellow", "yellow" or "dark", change_in the seconds to its next change. |
0.2.22 |
omsi.traffic.list([radius]) |
list of tables | The AI vehicles (within radius m of the player's bus, when given): {id, kind, name, x, y, z, heading, speed, max_speed, waiting_for, standing, braking, blinker, line, bounding_box, distance}. kind: "car", "taxi", "bus", "truck", "timetable_bus", "tram", "bicycle"; waiting_for why it waits or slows ("lead", "light", "yield", "people", ...); standing the seconds it has stood; bounding_box the body's [boundingbox] as {width, length, height, cx, cy, cz, heading, default} (metres, the .bus/.ovh order; cx/cy/cz the box centre's offset from the vehicle's x, y, z along the body's right, forward and up, which follow heading; default when the file gives no box and the collision code's 2.5 x 12 x 3 m is used). |
0.2.22 |
omsi.traffic.nearest([kind]) |
table or nil | The AI vehicle nearest to the player's bus (of that kind, when given), with its distance. |
0.2.22 |
omsi.traffic.remove(id) |
boolean | Takes an AI vehicle off the road (a timetable bus too: its timetable forgets it); its passengers get out. Permission: traffic_write. |
0.2.22 |
omsi.traffic.set_density(cars, [share]) |
boolean | Changes the traffic's amount (as the game menu's slider: 0 to 500 cars) and, when given, the share not running to a timetable; it fills up or thins out over the next seconds. Permission: traffic_write. |
0.2.22 |
People#
| Function | Returns | What it does | Since |
|---|---|---|---|
omsi.people.counts() |
walking, waiting, riding | The people of the map near the camera: walking, waiting at stops, riding a bus. | 0.2.22 |
omsi.people.density() |
number or nil | The people setting: 0 to 3, 1 the map's own amount. | 0.2.22 |
omsi.people.get(id) |
table or nil | One person by id, as people.list gives them, and more: stop_name (the timetable's name of the stop they wait or waited at), ticket (the name of the ticket they ask for), ticket_kind ("none", "stamp", "buy"), ticket_index (the ticket pack's, from 1; 0 none), ticket_price, ticket_voice, ticket_by (the plugin that changed it), ticket_asked (asked for at the cash desk already), tag (people.set_ticket's), age, model (the .hum file), voice (its voice folder). people.list gives the same fields. |
0.3 |
omsi.people.list([radius]) |
list of tables | The people (within radius m of the player's bus, when given): {id, x, y, z, state, aboard, ai_bus, stop, destination, ticket, complaint}. state: "strolling", "idle", "standing", "waiting", "to_bus", "boarding", "riding", "seated", "leaving", "to_stop"; aboard in the player's bus; complaint 0 to 3 (3: they leave); and the fields people.get describes. |
0.2.22 |
omsi.people.set_density(value) |
boolean | Changes the people setting (0 to 3). Permission: traffic_write. |
0.2.22 |
omsi.people.set_ticket(id, ticket) |
true, or false and the reason | Changes the ticket of a passenger boarding the player's bus (the passenger_ticket event names them): {kind, ticket, name, price, payment, voice, tag}, each optional. kind ("none": a pass, "stamp", "buy") can only be changed until they are in the bus; ticket selects another ticket from the pack (starting at 1, with its name and price; a buyer must have a ticket: 0 is refused, and a buyer created without ticket gets the pack's ticket for their age). name and price set the ticket name and ticket price, respectively, until the passenger has asked at the cash desk. payment specifies the amount of money handed over for a ticket purchase; it does not change the ticket price and is raised to at least the ticket price. It must be set before the passenger reaches the cash desk. If the currency's denominations cannot represent the requested amount exactly, the amount handed over may be higher. voice selects a line from the passenger's voice folder to use instead of Ticket_<n>_<k> ("Zone_4" selects Zone_4.wav; if the file is missing, the usual line is used; "" also falls back to the usual line), until the passenger has asked at the cash desk. tag is plugin-defined text kept with the person (people.get), and can be set at any time. Returns false and the reason when nothing changed. Permission: traffic_write. |
0.3 |
omsi.people.stops() |
list of tables | The stops near the camera where people wait: {id, name, x, y, z, waiting}. |
0.2.22 |
omsi.people.waiting(stop) |
integer | How many people wait at a stop (its map object id). | 0.2.22 |
Time#
| Function | Returns | What it does | Since |
|---|---|---|---|
omsi.clock() |
string | The game's time of day as "HH:MM:SS". |
0.1.10 |
omsi.world.date() |
table or nil | The game's date: {year, month, day, weekday, day_of_year} (weekday 1 Monday to 7 Sunday). |
0.2.22 |
omsi.world.pause() |
boolean | Pauses the game, as P does (not in a LAN game). The plugins stand still with it: the player resumes it. Permission: world_write. |
0.2.22 |
omsi.world.paused() |
boolean | Whether the game stands still (a plugin hears pause and runs no more until resume). |
0.2.22 |
omsi.world.play_time() |
number or nil | Seconds played this session (game time, never wraps). | 0.2.22 |
omsi.world.season() |
folder, snow | The season's texture folder (nil: the base textures) and whether snow lies. |
0.2.22 |
omsi.world.set_date(year, month, day) |
boolean | Sets the game's date (the season's textures follow). Permission: world_write. |
0.2.22 |
omsi.world.set_time(time) |
boolean | Sets the time of day: seconds since midnight or "HH:MM" / "HH:MM:SS", as the game menu's clock does (the timetable starts again after a jump of minutes). Not in a LAN game as a client, nor while the clock follows the computer's. Permission: world_write. |
0.2.22 |
omsi.world.set_time_speed(factor) |
boolean | Sets how much faster the clock runs (1 to 30; not in a LAN game). Permission: world_write. |
0.2.22 |
omsi.world.sun_altitude() |
number or nil | The sun's height over the horizon, degrees. | 0.2.22 |
omsi.world.time() |
number or nil | The game's time of day, seconds since midnight. | 0.2.22 |
omsi.world.time_speed() |
number or nil | How much faster than real time the game's clock runs (1 to 30). | 0.2.22 |
Weather#
| Function | Returns | What it does | Since |
|---|---|---|---|
omsi.weather.get() |
table or nil | The weather now: {name, visibility (m), wind_direction (°), wind_speed (m/s), temperature (°C), humidity (%), absolute_humidity (g/m³), pressure (hPa), clouds, cloud_base (m), precipitation ("none", "rain", "snow"), precipitation_rate (0..1), snow_cover, snow_on_road, wetness (the roads, 0..1), changing, locked} (locked: it follows a real weather station and cannot be set). |
0.2.22 |
omsi.weather.precipitation() |
kind, rate | "none", "rain" or "snow", and how hard (0 to 1). |
0.2.22 |
omsi.weather.preset(file, [seconds]) |
true, or false and the reason | Changes to a weather file (as weather.presets names it; "": the map's own, changing with the day) over seconds (default 1). Permission: world_write. |
0.2.22 |
omsi.weather.presets() |
list of tables | The weather files installed: {file, name}. |
0.2.22 |
omsi.weather.set(values) |
true, or false and the reason | Changes the weather as the game menu's sliders do; any of visibility, wind_direction, wind_speed, temperature, pressure, clouds ("-1" none, "Cumulus 1".."3", "Overcast 1"), cloud_base, precipitation ("none", "rain", "snow"), precipitation_rate (0..1), snow_cover, snow_on_road, wetness; the rest stays. Held to the game's ranges; refused in a LAN game as a client or while the weather follows a station. Permission: world_write. |
0.2.22 |
omsi.weather.temperature() |
number or nil | The air temperature, °C. | 0.2.22 |
omsi.weather.visibility() |
number or nil | How far one sees, metres. | 0.2.22 |
omsi.weather.wetness() |
number or nil | How wet the roads are, 0 (dry) to 1. | 0.2.22 |
omsi.weather.wind() |
direction, speed | The wind: where it comes from (degrees) and its speed (m/s). | 0.2.22 |
Camera#
| Function | Returns | What it does | Since |
|---|---|---|---|
omsi.camera.fov() |
number or nil | Its vertical field of view, degrees. | 0.2.22 |
omsi.camera.get() |
table or nil | The camera: {view, x, y, z, yaw, pitch, roll, fov, in_cab, zoom, look_yaw, look_pitch, width, height} - map metres, degrees (yaw clockwise from north, pitch up positive), the vertical field of view, the picture's pixels. |
0.2.22 |
omsi.camera.in_cab() |
boolean | Whether the camera is in the player's own bus (driver or passenger view). | 0.2.22 |
omsi.camera.look(yaw, pitch) |
boolean | Turns the head (driver, passenger view) or swings the outside camera round the bus: degrees from straight ahead. Permission: camera. |
0.2.22 |
omsi.camera.orientation() |
yaw, pitch, roll | Where it looks, degrees. | 0.2.22 |
omsi.camera.position() |
x, y, z | Where the camera is (map metres). | 0.2.22 |
omsi.camera.project(x, y, z) |
screen_x, screen_y | Where a map point is seen on the screen, in the panels' pixels (as ui.screen measures them); nothing when it is behind the camera. For labels over buses, stops, people. |
0.2.22 |
omsi.camera.set_free(x, y, z, [yaw], [pitch]) |
boolean | Puts the free camera at a map point looking along yaw and pitch (degrees); the view becomes "free" (the player moves it on from there). Permission: camera. |
0.2.22 |
omsi.camera.set_view(view) |
boolean | Switches the view: "driver", "pax", "outside", "map" (the free camera above the bus), "ego" (walking), or a view_* action of keyboard.cfg. Permission: camera. |
0.2.22 |
omsi.camera.set_zoom(zoom) |
boolean | The zoom of the view now (its field of view times this, 0.2 to 3). Permission: camera. |
0.2.22 |
omsi.camera.view() |
string or nil | The view: "driver", "pax", "outside", "free" or "foot". |
0.2.22 |
Input#
| Function | Returns | What it does | Since |
|---|---|---|---|
omsi.input.bindings([vehicles]) |
list of tables | The key bindings: {action, key} of the game's keys, or the vehicles' with true (key as the game writes it: "Ctrl+D"). |
0.2.22 |
omsi.input.controllers() |
list of tables | The steering wheels, pedals, joysticks and gamepads: {name, gamepad, axes, buttons} (axes each axis's value; buttons how many it has - the controller_button event tells presses). |
0.2.22 |
omsi.input.hotkey(keys, fn) |
integer id | Runs fn(key) when a key combination is pressed: "F10", "Ctrl+KeyH", "Shift+Alt+Digit1" (modifiers exact: "KeyH" is not Ctrl+KeyH). The keys still reach the bus. cancel(id) removes it. |
0.2.22 |
omsi.input.key_down(key) |
boolean | Whether a key is held now (winit's names, as the key event: "KeyW", "ShiftLeft", "F5"). |
0.2.22 |
omsi.input.keys_down() |
list of strings | Every key held now. | 0.2.22 |
omsi.input.mouse() |
x, y, left, right, middle | The mouse: where it is in the panels' pixels and its buttons held. | 0.2.22 |
Sound#
| Function | Returns | What it does | Since |
|---|---|---|---|
omsi.audio.play(file, [opts]) |
integer id or nil, reason | Plays a WAV file of the plugin's folder. opts: volume (1), pitch (1), loop, range (metres heard at full volume, 5), and either x, y, z (a sound at a map point) or on_bus = true (it moves with the player's bus); none: heard alike everywhere. The game's volume setting applies. A plugin plays 32 at most. Permission: audio. |
0.2.22 |
omsi.audio.playing(id) |
boolean | Whether a sound of the plugin's still plays. | 0.2.22 |
omsi.audio.set(id, opts) |
boolean | Changes a sound of the plugin's: volume, pitch, range, x, y, z / on_bus. Permission: audio. |
0.2.22 |
omsi.audio.stop(id) |
boolean | Stops a sound of the plugin's. Permission: audio. |
0.2.22 |
omsi.audio.stop_all() |
nil | Stops every sound of the plugin's. Permission: audio. |
0.2.22 |
omsi.audio.volume() |
number or nil | The game's volume setting, 0 to 1. | 0.2.22 |
On screen#
| Function | Returns | What it does | Since |
|---|---|---|---|
omsi.message(text, [seconds]) |
nil | A line of text on the screen (5 seconds when not given). Permission: ui. |
0.1.5 |
omsi.ui.clear() |
nil | Removes every panel of the plugin. Permission: ui. |
0.2.21 |
omsi.ui.dock() |
width, room, height, mine, frame | The navigator's board, where a panel with anchor = "navigator" goes, in that panel's pixels: its width, the most height there is room for, the height the panel there came to (0 before it is laid out; more than room: it is cut off at the bottom), whether that panel is this plugin's (the first one asked for has the board, another waits), and whether it fills the navigator's whole frame (frame = true, ui version 6; false under the map, and nothing in an older game). Nothing while the navigator shows no board: it is off, or Shift+N put its lower part away. |
0.3.36 |
omsi.ui.focus(on) |
boolean | true: the panels get the mouse (the cursor shows, a click goes to the panel under it and none to the bus); false, Esc or a menu of the game gives it back. Returns the new state. Permission: ui. |
0.2.21 |
omsi.ui.focused() |
boolean | Whether the panels have the mouse. | 0.2.21 |
omsi.ui.moved(panel) |
dx, dy | How far the player dragged a panel from where its table puts it (pixels). | 0.2.22 |
omsi.ui.panels() |
list of strings | The ids of the plugin's panels. | 0.2.22 |
omsi.ui.remove(id) |
boolean | Removes a panel; true when there was one. Permission: ui. |
0.2.21 |
omsi.ui.remove_menu_item(id) |
boolean | Takes the plugin's line id out of the pause menu; true when there was one. Permission: ui. |
0.3.36 |
omsi.ui.screen() |
width, height, scale | The screen in the panels' pixels, and how many of the screen's own pixels one of them is. | 0.2.21 |
omsi.ui.set(id, panel) |
true, or false and the reason | Creates the panel id or replaces it; a table that is not right gives false and where ("children[2].size: a number is expected"). The same table again changes nothing. Permission: ui. |
0.2.21 |
omsi.ui.set_menu_item(id, label, [icon]) |
true, or false and the reason | Puts a line in the game's pause menu, or changes the plugin's line id: its label (40 characters at most, shown as it is) and a Material Symbols icon of the game's ("departure_board"; the plugins' own icon without one). Choosing it closes the menu and sends menu_item with id - to open the plugin's panel, say. A plugin has 3 lines at most; they go when it stops. Permission: ui. |
0.3.36 |
omsi.ui.set_theme(id) |
true, or false and the reason | Switches the game's interface to theme id ("" or "openomsi": openOMSI's own look), as if the player chose it in Options › Interface: it is kept for the next start. Ask the player first; they can switch back there. Permission: ui. |
0.3.42 |
omsi.ui.show(panel, [on]) |
boolean | Shows a panel (or hides it with false; it is kept); false when there is none. Permission: ui. |
0.2.22 |
omsi.ui.theme() |
string | The id of the interface theme in use ("": openOMSI's own look). |
0.3.42 |
omsi.ui.themes() |
list of tables | The game's interface themes: each { id, name }, openOMSI's own look first (its id ""). A theme is a folder with a theme.json (Themes/<id>/, or a plugin's own folder: see docs/THEMES.md). |
0.3.42 |
omsi.ui.toast(text, [opts]) |
true, or false and the reason | A notification card at the top right, newest at the top; it goes after opts.seconds (1 to 60, default 5). opts: title, icon, color. A plugin shows 8 at most: a ninth makes its oldest go. Permission: ui. |
0.2.21 |
omsi.ui.toggle(panel) |
boolean | Shows a hidden panel or hides a shown one; whether it shows now. Permission: ui. |
0.2.22 |
omsi.ui.typing() |
boolean | Whether the player types into a text field of a plugin now (the keys then go to the field, not to the bus). | 0.2.22 |
omsi.ui.update(panel, element, values) |
true, or false and the reason | Changes one element of a panel in place, by its id: text, color, value (a bar, a slider), segments (a bar), checked, selected, name (an icon), values (a chart), rows and aligns (a table), stops (a stop list), src (an image) - cheaper than setting the whole panel again. Permission: ui. |
0.2.22 |
omsi.ui.value(panel, element) |
any | The value of a checkbox, slider, text field or tabs element now (as ui_change gives it). Permission: ui. |
0.2.22 |
Cables in the world#
| Function | Returns | What it does | Since |
|---|---|---|---|
omsi.cable.clear() |
integer | Takes every cable of the plugin away; how many went. They go by themselves when the plugin stops. Permission: ui. |
0.2.22 |
omsi.cable.remove(id) |
boolean | Takes the cable id away; true when there was one. Permission: ui. |
0.2.22 |
omsi.cable.set(id, points, [options]) |
boolean | Lays the cable id or moves it: a thin round tube through points (a flat list {x1, y1, z1, x2, ...} or a list of {x, y, z}, metres), lit and shaded as the scene. options: radius (m, default 0.006), color ({r, g, b} or {r, g, b, a}, 0 to 1, default dark grey) and frame: "world" (the map's coordinates, z up; the default) or "bus" (the player's bus's model frame: x right, y forward, z up, so a rope tied to the bus moves with it as drawn). Set it again whenever it moves; false (and the cable stays as it was) when the plugin would have more than 4096 cables, or more than 65536 points in all its cables together. Permission: ui. |
0.2.22 |
Events, timers and watches#
| Function | Returns | What it does | Since |
|---|---|---|---|
omsi.after(seconds, fn) |
integer id | Runs fn once, seconds of game time later. |
0.1.5 |
omsi.cancel(id) |
boolean | Stops a timer, a watch or a hotkey; true when there was one. |
0.1.5 |
omsi.emit(event, [...]) |
nil | Sends an event to this plugin's own handlers at once (handy between the modules of a bigger plugin); an error of a handler is this call's. | 0.1.5 |
omsi.every(seconds, fn) |
integer id | Runs fn every seconds of game time. |
0.1.5 |
omsi.off(event, fn) |
nil | Removes a handler added with on. |
0.1.5 |
omsi.on(event, fn) |
the function | Adds a handler of an event (see the events); several may hear one event, in the order they were added. | 0.1.5 |
omsi.time() |
number | Seconds of game time since the plugin started (stands still while paused). | 0.1.5 |
omsi.watch(kind, name, [fn]) |
integer id | Runs fn(new, old) whenever a value changes: watch(name, fn) a variable of the bus, watch(kind, name, fn) of kind "var", "str", "sys" or "info" (a key of info()). |
0.1.5 |
The plugin itself#
| Function | Returns | What it does | Since |
|---|---|---|---|
omsi.plugin.broadcast(topic, [data]) |
nil | Sends a message to every other plugin loaded. | 0.2.22 |
omsi.plugin.disable([reason]) |
nil | Switches the plugin off until its file changes or the game starts again (its stop comes). |
0.2.22 |
omsi.plugin.errors() |
integer | How many errors the plugin had (at 10 it is switched off). | 0.2.22 |
omsi.plugin.files([dir]) |
list of tables | The files of the plugin's own folder (or a folder in it): {name, dir, size}. |
0.2.22 |
omsi.plugin.list() |
list of strings | The names of the plugins loaded, this one too. | 0.2.22 |
omsi.plugin.name() |
string | The plugin's name: its file's, or its folder's for a main.lua. |
0.2.22 |
omsi.plugin.permissions() |
list of strings | The permissions the plugin has (native process access additionally requires player opt-in). | 0.2.22 |
omsi.plugin.read(path) |
text, or nil and the reason | A file of the plugin's own folder (a table of stops, a translation): read only, relative to the folder. | 0.2.22 |
omsi.plugin.send(to, topic, [data]) |
nil | Sends a message to another plugin (by its name): it hears message(from, topic, data) in its next frame. The data is numbers, texts, booleans or tables of them. |
0.2.22 |
omsi.plugin.set_setting(key, value) |
boolean | Changes a setting (held to its range; saved); true when it took the value. |
0.2.22 |
omsi.plugin.setting(key) |
any | A setting's value (nil: no such setting). |
0.2.22 |
omsi.plugin.settings(settings, [title]) |
table | Declares the plugin's settings: a list of {key, type, label, default} with type "bool", "number" (min, max, step), "text" or "choice" (choices, a list of texts). The values the player chose before come back (as a table key -> value); the game makes a settings panel of them (plugin.show_settings), saves them in the data folder and sends setting(key, value) when one changes. |
0.2.22 |
omsi.plugin.show_settings([on]) |
boolean | Shows the plugin's settings panel (or hides it with false); it can be dragged and closed while the panels have the mouse (ui.focus). false when the plugin declared no settings. Permission: ui. |
0.2.22 |
Storage and files#
| Function | Returns | What it does | Since |
|---|---|---|---|
omsi.files.append(path, data) |
true, or false and the reason | Adds to the end of a file of the data folder (a log, a CSV of trips). Permission: storage. |
0.2.22 |
omsi.files.delete(path) |
boolean | Removes a file or an empty folder of the data folder. Permission: storage. |
0.2.22 |
omsi.files.dir() |
string | Where the data folder is on this computer (to tell the player; the plugin reaches it with relative paths only). Permission: storage. |
0.2.22 |
omsi.files.exists(path) |
boolean | Whether the data folder has this file or folder. Permission: storage. |
0.2.22 |
omsi.files.list([dir]) |
list of tables, or nil and the reason | The entries of the data folder (or a folder in it): {name, dir, size}. Permission: storage. |
0.2.22 |
omsi.files.mkdir(path) |
boolean | Makes a folder (and those above it) in the data folder. Permission: storage. |
0.2.22 |
omsi.files.read(path) |
text, or nil and the reason | A file of the plugin's data folder (path relative to it; .. and absolute paths are refused). Permission: storage. |
0.2.22 |
omsi.files.write(path, data) |
true, or false and the reason | Writes a file of the data folder (its folders are made); at most 16 MB at once and 256 MB in all. Permission: storage. |
0.2.22 |
omsi.storage.all() |
table | Everything stored, as one table. Permission: storage. |
0.2.22 |
omsi.storage.clear() |
nil | Removes every key. Permission: storage. |
0.2.22 |
omsi.storage.delete(key) |
boolean | Removes a key; true when it was there. Permission: storage. |
0.2.22 |
omsi.storage.get(key) |
any | A value the plugin stored, or nil. The storage is the plugin's own and survives the session (kept as storage.json in its data folder). Permission: storage. |
0.2.22 |
omsi.storage.keys() |
list of strings | The keys stored, in the order they were first set. Permission: storage. |
0.2.22 |
omsi.storage.save() |
nil | Writes the storage now (it is written by itself when the game ends). Permission: storage. |
0.2.22 |
omsi.storage.set(key, value) |
nil | Stores a value under a key: a number, text, boolean or a table of them (nil removes it). It is written when the game ends, the plugin is loaded again, or storage.save() is called. Permission: storage. |
0.2.22 |
External programs#
| Function | Returns | What it does | Since |
|---|---|---|---|
omsi.process.exit_code(handle) |
code or nil, state or reason | Nonblocking exit code lookup (queued verification also counts as running): nil, "running" while running; code, "exited" after normal exit. A nonzero code is retained. Signal termination returns nil, "exited"; inspect process.status for details. Preparation failure returns nil, "failed", reason. An unknown handle returns nil and a reason. Permission: process. |
unreleased |
omsi.process.forget(handle) |
true, or nil and reason | Release a completed or failed process handle and its retained result. A running process cannot be forgotten. On Windows, closing its job also terminates any remaining descendants. Permission: process. |
unreleased |
omsi.process.kill(handle) |
true, or nil and reason | Cancel a queued start or request termination of a plugin-owned direct child without waiting. Poll process.status for completion; Windows also terminates the job descendants, Unix targets only the direct child. Permission: process. |
unreleased |
omsi.process.start(file, [args], [options]) |
handle, or nil and reason | Queue a native helper without waiting; return a reserved handle immediately. The interactive game asks the player with Allow once, Always allow or Deny unless the exact content was already approved. Embedded hosts without a permission broker remain default-deny. Verification and OS process creation run on two shared workers with at most 32 globally queued starts. The 32-handle plugin limit (including queued and failed starts) is checked before admission. A full queue returns nil and a reason. Accepted starts can fail later: inspect status.error or exit_code/wait returning nil, failed, reason. file must be a relative path inside the plugin folder. Approval is bound to the entry, folder snapshot and helper SHA256. Allow once covers one launch; Always allow saves consent in the host user settings; Deny blocks all native helpers for this canonical plugin entry for the current session, including renamed helpers or changed content or arguments. Changed content needs new approval. While the dialog is open, preparation workers and child cleanup keep running. The entry, executable-content snapshot (including importable Lua modules and native libraries), and helper hashes are rechecked on the worker immediately before each start; code changes revoke consent, while ordinary save/data writes do not. args are separate literal strings without shell expansion. Options: cwd and env (string overrides, other variables inherited, except OMSI_PLUGIN_PROCESS_ALLOW is always removed). Standard streams are disconnected. Windows helpers must be .exe files. At most 32 handles per plugin; forget completed handles. Stop, disable and reload terminate children; Windows job objects also terminate descendants and survive abrupt game exit, Linux uses a parent-death signal for direct children. No native helper runs before player approval. OMSI_PLUGIN_PROCESS_ALLOW can optionally name an absolute JSON grant manifest for preapproved content. Packages must also declare process. Unload/reload cancels unanswered requests. Approved helpers run with the game account's permissions. Permission: process. |
unreleased |
omsi.process.status(handle) |
table, or nil and reason | Nonblocking status: {pid, starting, awaiting_permission, running, exited, failed, error, code, success, signal}. While verification/start is pending, starting and running are true and pid is nil. Failed preparation sets failed/error without an exit code. While running code, success and signal are nil. After exit code is the exit code (including nonzero); termination by a signal has no code, and signal is available on Unix. Results remain readable until forgotten. Permission: process. |
unreleased |
omsi.process.wait(handle) |
exit code or nil, state or reason | Lua: suspend this plugin through queued verification/start and until its direct child exits, then return code, "exited" (nonzero codes retained; nil code on signal exit). The game and other plugins keep running; no game-thread wait occurs. Works in the main chunk, start/frame/event handlers and timers. Queued callbacks resume afterwards (limit 256), and normal frames/timers pause during the wait. Stop/reload cancels the continuation and terminates the child. A nested emit callback or manually resumed coroutine cannot suspend. Preparation failure returns nil, "failed", reason. Other language bindings should poll process.exit_code instead. Permission: process. |
unreleased |
Programs on this computer#
| Function | Returns | What it does | Since |
|---|---|---|---|
omsi.send(port, data) |
true, or false and the reason | Sends data as one UDP datagram to 127.0.0.1:port: to another program on this computer, never over the network. Not sent when the port is below 1024 or one of the game's multiplayer ports (27015-27024), the message is longer than 8 KB, or the plugin sent 100 in the last second. Permission: network_local. |
0.2.21 |
LAN games#
| Function | Returns | What it does | Since |
|---|---|---|---|
omsi.lan.active() |
boolean | Whether this game is in a LAN session. | 0.2.22 |
omsi.lan.chat(text) |
true, or false and the reason | Says a line in the session's chat, as the player would (every player sees it; at most one a second). Permission: lan. |
0.2.22 |
omsi.lan.me() |
id, name, host | This player in the session: its id (the host is 1), its name, whether it hosts. | 0.2.22 |
omsi.lan.players() |
list of tables | The other players of the session: {id, name, host, bus, line, tour, x, y, z, heading, speed, on_foot, passengers}. |
0.2.22 |
omsi.lan.send(to, text) |
true, or false and the reason | Sends a short text (at most 120 characters, no |) to the same plugin on another player's game (to its id; 0: every other player); it hears lan_message(from, text). A player sends at most about ten a second; a game without the plugin ignores them. Permission: lan. |
0.2.22 |
The game#
| Function | Returns | What it does | Since |
|---|---|---|---|
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). Permission: world_write. |
0.1.10 |
omsi.debug([...]) |
nil | A line of the log's debug level (shown with RUST_LOG=debug). |
0.2.22 |
omsi.error([...]) |
nil | The same as an error line (the plugin goes on). | 0.2.22 |
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. Permission: world_write. |
0.2.22 |
omsi.game.api() |
integer | The version of the plugin interface (api_abi of an .oop; raised only when something is taken away or changes). |
0.2.22 |
omsi.game.fps() |
number or nil | Frames a second now. | 0.2.22 |
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. |
0.2.22 |
omsi.game.menu_open() |
boolean | Whether the game menu is open. | 0.2.22 |
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". Permission: ui. |
0.2.22 |
omsi.game.platform() |
string | The system the game runs on: "windows", "macos", "linux", "android". |
0.2.22 |
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). Permission: ui. |
0.2.22 |
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), ... |
0.2.22 |
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, ... |
0.2.22 |
omsi.game.version() |
string | The game's version ("0.2.22"). |
0.2.22 |
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). |
0.1.10 |
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. |
0.2.22 |
omsi.log([...]) |
nil | A line in game.log, tagged [lua <name>] (print does the same). |
0.1.5 |
omsi.warn([...]) |
nil | The same as a warning. | 0.1.5 |
Helpers#
| Function | Returns | What it does | Since |
|---|---|---|---|
omsi.fmt.clock(seconds, [with_seconds]) |
string | Seconds since midnight as "HH:MM" ("HH:MM:SS" with true); past midnight wraps. |
0.2.22 |
omsi.fmt.delay(seconds) |
string | A delay as a timetable display shows it: "+2:30" late, "-0:45" early, "0:00". |
0.2.22 |
omsi.fmt.distance(metres) |
string | A distance as "350 m" or "2.4 km". |
0.2.22 |
omsi.fmt.duration(seconds) |
string | A length of time as people read it: "45 s", "3 min 05 s", "1 h 20 min" (negative with a minus). |
0.2.22 |
omsi.fmt.money(amount, [symbol]) |
string | An amount with two decimals and a currency symbol after it ("12.50 €"; the game knows no currency of its own). |
0.2.22 |
omsi.fmt.number(x, [decimals], [separator]) |
string | A number with decimals (0) and a thousands separator (",", " "; none by default). |
0.2.22 |
omsi.fmt.pad(text, width, [right]) |
string | A text made width characters long with spaces (on the left with right = true, to line numbers up), or cut to it. |
0.2.22 |
omsi.fmt.speed(kmh, [unit]) |
string | A speed as "42 km/h", or in "mph" or "m/s". |
0.2.22 |
omsi.fmt.split(text, [separator]) |
list of strings | A text cut at every separator ("," by default; plainly, no patterns). |
0.2.22 |
omsi.fmt.trim(text) |
string | A text without the spaces at its ends. | 0.2.22 |
omsi.json.decode(text) |
value, or nil and the reason | Reads JSON text: objects and arrays become tables, null nil. |
0.2.22 |
omsi.json.encode(value, [pretty]) |
string | A value as JSON text (a list as an array, a table with keys as an object; pretty: indented). |
0.2.22 |
omsi.util.date([seconds]) |
table | A real time (util.now() by default) as {year, month, day, hour, minute, second, weekday} in UTC (weekday 1 Monday). |
0.2.22 |
omsi.util.ms() |
number | Milliseconds of real time since the game started: for timing a plugin's own work. | 0.2.22 |
omsi.util.now() |
number | The real time: seconds since 1970 (UTC), with fractions. | 0.2.22 |
omsi.util.random([min], [max]) |
number | A random number: 0 to 1 without arguments, else a whole number from min to max (as math.random, but not repeating the same row in every plugin). |
0.2.22 |
omsi.vec.angle_diff(a, b) |
number | The turn from heading a to heading b, -180 to 180 degrees (right positive). |
0.2.22 |
omsi.vec.bearing(x1, y1, x2, y2) |
number | The heading from one map point to another. | 0.2.22 |
omsi.vec.clamp(x, min, max) |
number | x held between min and max. |
0.2.22 |
omsi.vec.distance(x1, y1, x2, y2) |
number | Metres between two map points (on the ground: x and y). | 0.2.22 |
omsi.vec.distance3(x1, y1, z1, x2, y2, z2) |
number | Metres between two points in space. | 0.2.22 |
omsi.vec.dot(x1, y1, x2, y2) |
number | The dot product of two 2D vectors. | 0.2.22 |
omsi.vec.heading(dx, dy) |
number | The heading of a direction on the map, degrees clockwise from north (0 to 360), as the game's headings. | 0.2.22 |
omsi.vec.length(x, y, [z]) |
number | The length of a vector (2D, or 3D with z). |
0.2.22 |
omsi.vec.lerp(a, b, t) |
number | From a to b by t (0 to 1, not held to it). |
0.2.22 |
omsi.vec.normalize(x, y, [z]) |
x, y, z | The vector made 1 long (0 stays 0). | 0.2.22 |
omsi.vec.rotate(x, y, degrees) |
x, y | A vector turned clockwise by degrees (as headings turn). |
0.2.22 |
omsi.vec.to_local(x, y, ox, oy, heading) |
right, ahead | A map point seen from a place facing heading: metres to the right and ahead of it. |
0.2.22 |
Events#
| Event | Arguments | When | Since |
|---|---|---|---|
start |
- | Right after the plugin was loaded (also after a reload). | 0.1.5 |
vehicle |
name |
The player got into a vehicle, changed it, or left it (nil). |
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. |
0.1.5 |
stop |
- | The game ends, or the plugin is about to be loaded again. | 0.1.5 |
key |
key, down |
A key went down (true) or came up: winit's name of it ("KeyH", "F5", "Numpad8"). |
0.1.10 |
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). |
0.1.10 |
view |
new, old |
The view changed ("driver", "pax", "outside", "free", "foot"). |
0.1.10 |
duty |
line, tour |
A line and tour were taken (or given up: nil). |
0.1.10 |
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. | 0.2.21 |
pedestrian |
count |
The bus knocked people down. | 0.2.21 |
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. | 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". |
0.2.21 |
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). |
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. | 0.2.21 |
ticket_sold |
name, price |
A ticket was sold at the cash desk: its name and price as the bus's ticket list has them. | 0.2.21 |
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. |
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. |
0.3.36 |
ui_focus |
focused |
The panels got the mouse or gave it back (also by Esc, or a menu of the game opening). | 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. |
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). |
0.2.22 |
setting |
key, value |
The player changed one of the plugin's settings in its settings panel (plugin.settings). |
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. |
0.2.22 |
doors |
open |
The bus's doors opened (true: one or more open) or were all closed. |
0.2.22 |
engine_start |
- | The player's bus's engine started running. | 0.2.22 |
engine_stop |
- | Its engine stopped. | 0.2.22 |
gear |
new, old |
The gear engaged changed (-1 reverse, 0 neutral), where the bus has a gearbox it shows. | 0.2.22 |
indicator |
new, old |
The indicators changed: "off", "left", "right" or "hazard". |
0.2.22 |
headlights |
new, old |
The headlights changed: 0 off, 1 side lights, 2 dipped, 3 high beam. | 0.2.22 |
horn |
down |
The horn started (true) or stopped. |
0.2.22 |
handbrake |
on |
The parking brake was put on (true) or released. |
0.2.22 |
stop_request |
on |
A passenger asked to stop (true), or the request went out. |
0.2.22 |
passengers |
count, old |
The number of passengers aboard the player's bus changed. | 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). |
0.2.22 |
passenger_alight |
count |
People got out of the player's bus. | 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. |
0.3 |
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). | 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. | 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. | 0.2.22 |
duty_start |
line, tour |
A duty was taken. | 0.2.22 |
duty_end |
line, tour |
The duty was given up (or another taken: duty_end of the old one comes first). |
0.2.22 |
destination |
new, old |
The destination the bus shows changed. | 0.2.22 |
coupled |
parts, old |
Something was coupled to or uncoupled from the bus: the parts behind it now. | 0.2.22 |
minute |
hour, minute |
The game's clock reached a new minute (also when it was set). | 0.2.22 |
hour |
hour |
The game's clock reached a new hour. | 0.2.22 |
day |
year, month, day |
The game's date changed. | 0.2.22 |
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). |
0.2.22 |
weather |
name |
The weather changed: another weather file, rain or snow beginning or ending, the snow cover, the clouds. | 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. |
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. | 0.2.22 |
speed_limit |
kmh, old |
The speed limit of the lane the bus drives on changed. | 0.2.22 |
ai_collision |
id, energy_kj |
The player's bus hit an AI vehicle (its id, as traffic.list gives it) with this energy. |
0.2.22 |
pause |
- | The game was paused (the plugins stand still until resume; nothing else comes in between). |
0.2.22 |
resume |
- | The game goes on after a pause. | 0.2.22 |
menu_open |
- | The game menu opened. | 0.2.22 |
menu_close |
- | The game menu closed. | 0.2.22 |
screenshot |
file |
A screenshot was taken: its file. | 0.2.22 |
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. |
0.2.22 |
lan_join |
id, name |
A player joined the LAN session (or came back). | 0.2.22 |
lan_leave |
id, name |
A player left the LAN session. | 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. |
0.2.22 |
lan_chat |
name, text |
A line was said in the LAN session's chat (by another player or this one). | 0.2.22 |
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. |
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). |
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. | 0.2.22 |
object_click |
id, event |
The player clicked the [mouseevent] of a mesh of an object this script drives. |
0.2.22 |
Something wrong or missing? Fix it on GitHub or open an issue.