openOMSI GitHub Discord
Plugin API reference

Docs / Plugins / Plugin API reference

Player's bus

13 min readEdit this pagedocs/PLUGIN_API.md

On this page
  1. omsi.body_frame
  2. omsi.bus.acceleration
  3. omsi.bus.action
  4. omsi.bus.change
  5. omsi.bus.controls
  6. omsi.bus.cruise
  7. omsi.bus.damage
  8. omsi.bus.destination
  9. omsi.bus.destinations
  10. omsi.bus.dirt
  11. omsi.bus.door
  12. omsi.bus.door_count
  13. omsi.bus.doors
  14. omsi.bus.doors_open
  15. omsi.bus.electrics
  16. omsi.bus.engine
  17. omsi.bus.engine_running
  18. omsi.bus.file
  19. omsi.bus.fuel
  20. omsi.bus.gear
  21. omsi.bus.get_strings
  22. omsi.bus.get_vars
  23. omsi.bus.handbrake
  24. omsi.bus.headlights
  25. omsi.bus.hold_controls
  26. omsi.bus.horn
  27. omsi.bus.indicator
  28. omsi.bus.interior_light
  29. omsi.bus.km_today
  30. omsi.bus.kneeling
  31. omsi.bus.mass
  32. omsi.bus.mesh_get
  33. omsi.bus.mesh_reset
  34. omsi.bus.mesh_set
  35. omsi.bus.meshes
  36. omsi.bus.number
  37. omsi.bus.odometer
  38. omsi.bus.orientation
  39. omsi.bus.passengers
  40. omsi.bus.play_sound
  41. omsi.bus.push
  42. omsi.bus.release_controls
  43. omsi.bus.retarder
  44. omsi.bus.rpm
  45. omsi.bus.sales
  46. omsi.bus.service
  47. omsi.bus.set_cruise
  48. omsi.bus.set_destination
  49. omsi.bus.set_dirt
  50. omsi.bus.set_indicator
  51. omsi.bus.set_interior_light
  52. omsi.bus.set_line
  53. omsi.bus.set_vars
  54. omsi.bus.set_velocity
  55. omsi.bus.shift
  56. omsi.bus.sound_horn
  57. omsi.bus.start_up
  58. omsi.bus.state
  59. omsi.bus.steering_angle
  60. omsi.bus.stop_brake
  61. omsi.bus.stop_requested
  62. omsi.bus.ticket_request
  63. omsi.bus.tickets
  64. omsi.bus.toggle_door
  65. omsi.bus.toggle_handbrake
  66. omsi.bus.track
  67. omsi.bus.trailers
  68. omsi.bus.triggers
  69. omsi.bus.velocity
  70. omsi.bus.velocity_vector
  71. omsi.bus.wheels
  72. omsi.distance
  73. omsi.has_vehicle
  74. omsi.mesh_point
  75. omsi.position
  76. omsi.press
  77. omsi.release
  78. omsi.set_str
  79. omsi.set_var
  80. omsi.speed
  81. omsi.str
  82. omsi.sys
  83. omsi.trigger
  84. omsi.var
  85. omsi.vars
  86. omsi.vehicle
  87. omsi.vehicle_manufacturer
  88. omsi.vehicle_model

omsi.bus.* and the core functions omsi.var, omsi.position, omsi.trigger and friends read and drive the vehicle the player is in. Every reading is nil (or nothing) while the player is on foot. Script variable names are the ones the bus's .osc files use; omsi.vars() lists them.

omsi.body_frame#

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.

Parameters: section integer, optional.

Since 0.2.22.

omsi.bus.acceleration#

omsi.bus.acceleration() → across, along, up

Its acceleration in its own frame, m/s² without gravity: to the right, forwards, up.

Since 0.2.22.

omsi.bus.action#

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.

Parameters: name string; down bool, optional.

Since 0.2.22. Permission: vehicle_write.

Lua
omsi.bus.action("parking_brake_toggle")

omsi.bus.change#

omsi.bus.change(file, [paint]) → true, or false and the reason

The player drives another bus: file a vehicle file under the game folder (Vehicles/MAN_SD200/MAN_SD77.bus, as game.vehicles lists them), in paint paint if given. It is loaded in the background and takes the current bus's place.

Parameters: file string; paint string, optional.

Since unreleased. Permission: vehicle_write.

omsi.bus.controls#

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.

Since 0.2.22.

omsi.bus.cruise#

omsi.bus.cruise() → number or nil

The speed the cruise control holds, km/h (nil while it is off). The player switches it with Num0 or a key of their own in the launcher's Controls page.

Since 0.3.55.

omsi.bus.damage#

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).

Since 0.2.22.

omsi.bus.destination#

omsi.bus.destination() → name, index

The destination the bus shows and its index in destinations (nothing when none).

Since 0.2.22.

omsi.bus.destinations#

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).

Since 0.2.22.

Lua
for _, d in ipairs(omsi.bus.destinations()) do
  if d.name == "Hauptbahnhof" then omsi.bus.set_destination(d.index) end
end

omsi.bus.dirt#

omsi.bus.dirt() → number or nil

How dirty the bus is, 0 (clean) to 1.

Since 0.2.22.

omsi.bus.door#

omsi.bus.door(n) → boolean or nil

Whether door leaf n (from 1) is open.

Parameters: n integer.

Since 0.2.22.

omsi.bus.door_count#

omsi.bus.door_count() → integer

The doorways the door keys work, front to back.

Since 0.2.22.

omsi.bus.doors#

omsi.bus.doors() → list of numbers

Each door leaf's position, front to back: 0 shut, 1 open (the scripts' door_0, door_1, ...).

Since 0.2.22.

omsi.bus.doors_open#

omsi.bus.doors_open() → boolean or nil

Whether any door is open (by the passengers' door flags where the bus has them).

Since 0.2.22.

omsi.bus.electrics#

omsi.bus.electrics() → boolean or nil

Whether the bus's electrics are on (the main switch).

Since 0.2.22.

omsi.bus.engine#

omsi.bus.engine() → running, rpm, electrics

The engine: whether it runs, its rpm (where the bus shows one) and whether the electrics are on.

Since 0.2.22.

omsi.bus.engine_running#

omsi.bus.engine_running() → boolean or nil

Whether the engine runs.

Since 0.2.22.

omsi.bus.file#

omsi.bus.file() → string or nil

The bus's .bus file, relative to the game folder.

Since 0.2.22.

omsi.bus.fuel#

omsi.bus.fuel() → number or nil

The fuel in the tank, litres (the scripts' engine_tank_content).

Since 0.2.22.

omsi.bus.gear#

omsi.bus.gear() → integer or nil

The gear engaged (-1 reverse, 0 neutral), where the bus shows one.

Since 0.2.22.

omsi.bus.get_strings#

omsi.bus.get_strings([names]) → table

The same for string variables.

Parameters: names table, optional.

Since 0.2.22.

omsi.bus.get_vars#

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.

Parameters: names table, optional.

Since 0.2.22.

Lua
local v = omsi.bus.get_vars({ "Velocity", "throttle" })
print(v.Velocity, v.throttle)

omsi.bus.handbrake#

omsi.bus.handbrake() → boolean or nil

Whether the parking brake is on.

Since 0.2.22.

omsi.bus.headlights#

omsi.bus.headlights() → integer or nil

The headlights: 0 off, 1 side lights, 2 dipped, 3 high beam.

Since 0.2.22.

omsi.bus.hold_controls#

omsi.bus.hold_controls(controls, [seconds]) → boolean

Holds the player's bus's pedals and steering for seconds (default 0.5; call it again each frame to keep driving): {throttle, brake, clutch, steering}, pedals 0 to 1, steering -1 (left) to 1 (right); a key left out stays the driver's. An autopilot, a driving school, a remote control. bus.release_controls() lets go.

Parameters: controls table; seconds number, optional.

Since unreleased. Permission: vehicle_write.

omsi.bus.horn#

omsi.bus.horn() → boolean or nil

Whether the horn sounds.

Since 0.2.22.

omsi.bus.indicator#

omsi.bus.indicator() → string or nil

The indicators: "off", "left", "right" or "hazard".

Since 0.2.22.

omsi.bus.interior_light#

omsi.bus.interior_light() → number or nil

The passenger room's light, 0 (off) to 1.

Since 0.2.22.

omsi.bus.km_today#

omsi.bus.km_today() → number or nil

Kilometres driven this session (as the personnel file counts them).

Since 0.2.22.

omsi.bus.kneeling#

omsi.bus.kneeling() → boolean or nil

Whether the bus kneels.

Since 0.2.22.

omsi.bus.mass#

omsi.bus.mass() → number or nil

The bus's mass in kg. With Passengers add weight to the bus (passenger_mass) on, the weight of the riders in its front section is included (see Passenger weight).

Since 0.2.22.

omsi.bus.mesh_get#

omsi.bus.mesh_get(index) → {positions, normals, uvs, indices} or nil

The geometry of mesh index of the player's bus as it is drawn now, in the bus's frame (x right, y forward, z up, metres): flat lists of 3, 3 and 2 numbers a vertex, three indices a triangle (from 0).

Parameters: index integer.

Since unreleased.

omsi.bus.mesh_reset#

omsi.bus.mesh_reset(index) → boolean

Mesh index of the player's bus as its model has it again (collision dents included).

Parameters: index integer.

Since unreleased. Permission: vehicle_write.

omsi.bus.mesh_set#

omsi.bus.mesh_set(index, mesh) → true, or false and the reason

Draws mesh index of the player's bus with other geometry: {positions, normals, uvs, indices} as bus.mesh_get gives it. With the same number of vertices and no indices only the vertices move (a dent, a bend, a door that warps); with indices the mesh is made anew. Missing normals are worked out, missing uvs kept.

Only this bus changes, not others of its type; the change lasts until bus.mesh_reset or the player leaves the bus.

Parameters: index integer; mesh table.

Since unreleased. Permission: vehicle_write.

omsi.bus.meshes#

omsi.bus.meshes() → list of {index, file, vertices, triangles, changed}

The meshes of the player's bus in its model's order (index from 0, as bus.mesh_get takes it); changed when a plugin changed its geometry.

Since unreleased.

omsi.bus.number#

omsi.bus.number() → string or nil

The bus's fleet number.

Since 0.2.22.

omsi.bus.odometer#

omsi.bus.odometer() → number or nil

The bus's odometer in km.

Since 0.2.22.

omsi.bus.orientation#

omsi.bus.orientation() → heading, pitch, bank

Heading (degrees clockwise from north), pitch (nose up positive) and bank (right side down positive).

Since 0.2.22.

omsi.bus.passengers#

omsi.bus.passengers() → total, seated, standing

The people aboard the bus: all, sitting, standing.

Since 0.2.22.

Lua
local all, seated, standing = omsi.bus.passengers()

omsi.bus.play_sound#

omsi.bus.play_sound(event) → boolean

Plays the bus's own sound of this event (a trigger name of its sound files, ev_...).

Parameters: event string.

Since 0.2.22. Permission: vehicle_write.

omsi.bus.push#

omsi.bus.push(dv) → boolean

Adds {x, y, z} m/s to the player's bus's speed in the map's frame at once: a shove, a gust, a ramp.

Parameters: dv table.

Since unreleased. Permission: vehicle_write.

omsi.bus.release_controls#

omsi.bus.release_controls() → boolean

The driver has the pedals and the steering again.

Since unreleased. Permission: vehicle_write.

omsi.bus.retarder#

omsi.bus.retarder() → number or nil

The retarder's step, where the bus has one.

Since 0.2.22.

omsi.bus.rpm#

omsi.bus.rpm() → number or nil

The engine's revolutions per minute.

Since 0.2.22.

omsi.bus.sales#

omsi.bus.sales() → tickets, money

Tickets sold this session and the money taken (the game knows no currency).

Since 0.2.22.

omsi.bus.service#

omsi.bus.service(what) → number or nil

A workshop service for the player's bus at once: "refuel" (fills the tank, or charges the battery, as its scripts do; gives the tank's content), "wash" (gives the dirt left) or "repair" (every damage; gives 1). nil when the bus has no such service.

Parameters: what string.

Since unreleased. Permission: vehicle_write.

omsi.bus.set_cruise#

omsi.bus.set_cruise([kmh]) → boolean

Switches the cruise control on to hold kmh (5 km/h or more), or off (nil). Like Num0, it is refused (false) while the bus goes slower than 5 km/h. It works the throttle and the brake the bus's scripts read, which a plugin's set_var("Throttle") cannot: the player's pedals are written over it every step. The brake switches it off; the throttle pressed further wins while held.

Since 0.3.55. Permission: vehicle_write.

omsi.bus.set_destination#

omsi.bus.set_destination(index) → boolean

Shows destination index (from 1, as destinations lists them).

Parameters: index integer.

Since 0.2.22. Permission: vehicle_write.

omsi.bus.set_dirt#

omsi.bus.set_dirt(dirt) → boolean

How dirty the player's bus is, 0 (clean) to 1.

Parameters: dirt number.

Since unreleased. Permission: vehicle_write.

omsi.bus.set_indicator#

omsi.bus.set_indicator(state) → boolean

Sets the indicators: "off", "left", "right" or "hazard".

Parameters: state string.

Since 0.2.22. Permission: vehicle_write.

Lua
omsi.bus.set_indicator("left")

omsi.bus.set_interior_light#

omsi.bus.set_interior_light(on) → boolean

Switches the passenger room's light on or off.

Parameters: on bool.

Since 0.2.22. Permission: vehicle_write.

omsi.bus.set_line#

omsi.bus.set_line(line) → boolean

Types a line (route) into the bus's IBIS, as the player would.

Parameters: line string.

Since 0.2.22. Permission: vehicle_write.

omsi.bus.set_vars#

omsi.bus.set_vars(values) → integer

Sets many script variables at once (a table name -> number); how many the bus has.

Parameters: values table.

Since 0.2.22. Permission: vehicle_write.

omsi.bus.set_velocity#

omsi.bus.set_velocity(velocity, [spin]) → boolean

Sets how the player's bus moves from this step on: velocity {x, y, z} in m/s in the map's frame (x east, y north, z up), and with spin {pitch, roll, yaw} its turning in rad/s about its own axes. Launch it, stop it dead, make it jump. false when the bus has no such physics.

Parameters: velocity table; spin table, optional.

Since unreleased. Permission: vehicle_write.

omsi.bus.shift#

omsi.bus.shift(gear) → boolean

Puts a manual gearbox's lever in a gear (-1 reverse, 0 neutral).

Parameters: gear integer.

Since 0.2.22. Permission: vehicle_write.

omsi.bus.sound_horn#

omsi.bus.sound_horn(down) → boolean

Holds the horn (true) or lets it go.

Parameters: down bool.

Since 0.2.22. Permission: vehicle_write.

omsi.bus.start_up#

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.

Since 0.2.22. Permission: vehicle_write.

omsi.bus.state#

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).

Since 0.2.22.

Lua
local s = omsi.bus.state()
if s then print(s.speed, s.gear, s.doors_open) end

omsi.bus.steering_angle#

omsi.bus.steering_angle() → angle, max

The front wheels' angle and the most they turn, degrees (right positive).

Since 0.2.22.

omsi.bus.stop_brake#

omsi.bus.stop_brake() → boolean or nil

Whether the stop brake (the door brake) holds the bus.

Since 0.2.22.

omsi.bus.stop_requested#

omsi.bus.stop_requested() → boolean or nil

Whether a passenger has asked to stop.

Since 0.2.22.

omsi.bus.ticket_request#

omsi.bus.ticket_request() → name, price

The ticket the passenger at the cash desk asks for (nothing when nobody asks).

Since 0.2.22.

omsi.bus.tickets#

omsi.bus.tickets() → list of tables

The tickets the map sells: {name, price, day_ticket}.

Since 0.2.22.

omsi.bus.toggle_door#

omsi.bus.toggle_door([n]) → boolean

Presses the key of doorway n (from 1; 0 or none: all doors), as the player would.

Parameters: n integer, optional.

Since 0.2.22. Permission: vehicle_write.

Lua
omsi.bus.toggle_door(1)  -- the front door

omsi.bus.toggle_handbrake#

omsi.bus.toggle_handbrake() → boolean

Puts the parking brake on or off, as its key does.

Since 0.2.22. Permission: vehicle_write.

omsi.bus.track#

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.

Since 0.3.55.

Lua
local t = omsi.bus.track()
if t then print("lane", t.lane, "at", t.s, "of", t.lane_length) end

omsi.bus.trailers#

omsi.bus.trailers() → integer or nil

Parts coupled behind the bus (an articulated bus's rear counts).

Since 0.2.22.

omsi.bus.triggers#

omsi.bus.triggers() → list of strings

The names of the bus's script triggers (for trigger, press).

Since 0.2.22.

omsi.bus.velocity#

omsi.bus.velocity() → number or nil

The bus's speed in km/h, negative backwards.

Since 0.2.22.

omsi.bus.velocity_vector#

omsi.bus.velocity_vector() → x, y, z

Its velocity in the world, m/s (x east, y north, z up).

Since 0.2.22.

omsi.bus.wheels#

omsi.bus.wheels() → list of tables

Each wheel: {axle, side, rpm, radius, suspension, driven} (side 0 left, 1 right; suspension the spring's travel).

Since 0.2.22.

omsi.distance#

omsi.distance(x, y) → number or nil

Metres from the bus to a map point, or nil on foot.

Parameters: x number; y number.

Since 0.1.10.

omsi.has_vehicle#

omsi.has_vehicle() → boolean

true while the player drives a vehicle.

Since 0.1.5.

omsi.mesh_point#

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.

Parameters: mesh string; x number; y number; z number; section integer, optional.

Since 0.2.22.

Lua
local x, y, z = omsi.mesh_point("mirror.o3d", 0.2, 1.0, 2.1)

omsi.position#

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.

Since 0.1.10.

Lua
local x, y, z, heading = omsi.position()
if x then omsi.log(string.format("%.0f %.0f facing %.0f", x, y, heading)) end

omsi.press#

omsi.press(name) → nil

Holds a key of the bus down: fires the trigger name (let it go with release).

Parameters: name string.

Since 0.1.5. Permission: vehicle_write.

Lua
omsi.press("bus_horn")
omsi.after(0.5, function() omsi.release("bus_horn") end)

omsi.release#

omsi.release(name) → nil

Lets a key go: fires <name>_off.

Parameters: name string.

Since 0.1.5. Permission: vehicle_write.

omsi.set_str#

omsi.set_str(name, text) → boolean

Sets a string variable; true when the bus has it.

Parameters: name string; text string.

Since 0.1.5. Permission: vehicle_write.

omsi.set_var#

omsi.set_var(name, value) → boolean

Sets a script variable; true when the bus has that variable.

Parameters: name string; value number.

Since 0.1.5. Permission: vehicle_write.

Lua
omsi.set_var("elec_busbar_main", 1)

omsi.speed#

omsi.speed() → number

The bus's speed in km/h, forwards or backwards (0 on foot).

Since 0.1.10.

omsi.str#

omsi.str(name) → string or nil

A string variable of the bus's scripts (IBIS_terminus_name).

Parameters: name string.

Since 0.1.5.

omsi.sys#

omsi.sys(name) → number or nil

A system variable of the scripts: Time, Day, Weather_Temperature, SunAlt, ... (read only).

Parameters: name string.

Since 0.1.5.

The system variables (the scripts' S.L. list), read only:

Timegap, GetTime, NoSound, Pause, Time, Day, Month, Year, DayOfYear, mouse_x, mouse_y, PrecipType, PrecipRate, coll_pos_x, coll_pos_y, coll_pos_z, coll_energy, Weather_Temperature, Weather_AbsHum, wearlifespan, AutoClutch, SunAlt. Names are matched without regard to case.

Lua
local temp = omsi.sys("Weather_Temperature")

omsi.trigger#

omsi.trigger(name) → nil

A key press of the bus: fires the trigger, then <name>_off.

Parameters: name string.

Since 0.1.5. Permission: vehicle_write.

Lua
omsi.trigger("bus_horn")

omsi.var#

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.

Parameters: name string.

Since 0.1.5.

Lua
local kmh = omsi.var("Velocity")
if kmh and kmh > 50 then omsi.message("Too fast!", 2) end

omsi.vars#

omsi.vars([kind]) → list of strings

The names of every variable of the bus's scripts, or of every string variable with "str".

Parameters: kind string, optional.

Since 0.1.10.

Lua
for _, name in ipairs(omsi.vars()) do print(name) end

omsi.vehicle#

omsi.vehicle() → string or nil

The vehicle's name (manufacturer and type), or nil on foot.

Since 0.1.5.

omsi.vehicle_manufacturer#

omsi.vehicle_manufacturer() → string or nil

The manufacturer part of the vehicle's name, as its [friendlyname] has it ("Solaris III Gen").

Since 0.2.21.

omsi.vehicle_model#

omsi.vehicle_model() → string or nil

The model part of the vehicle's name ("Urbino 10 / 2D").

Since 0.2.21.

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

↑↓ to move↵ to open