Docs / Plugins / Plugin API reference
Player's bus
On this page
- omsi.body_frame
- omsi.bus.acceleration
- omsi.bus.action
- omsi.bus.change
- omsi.bus.controls
- omsi.bus.cruise
- omsi.bus.damage
- omsi.bus.destination
- omsi.bus.destinations
- omsi.bus.dirt
- omsi.bus.door
- omsi.bus.door_count
- omsi.bus.doors
- omsi.bus.doors_open
- omsi.bus.electrics
- omsi.bus.engine
- omsi.bus.engine_running
- omsi.bus.file
- omsi.bus.fuel
- omsi.bus.gear
- omsi.bus.get_strings
- omsi.bus.get_vars
- omsi.bus.handbrake
- omsi.bus.headlights
- omsi.bus.hold_controls
- omsi.bus.horn
- omsi.bus.indicator
- omsi.bus.interior_light
- omsi.bus.km_today
- omsi.bus.kneeling
- omsi.bus.mass
- omsi.bus.mesh_get
- omsi.bus.mesh_reset
- omsi.bus.mesh_set
- omsi.bus.meshes
- omsi.bus.number
- omsi.bus.odometer
- omsi.bus.orientation
- omsi.bus.passengers
- omsi.bus.play_sound
- omsi.bus.push
- omsi.bus.release_controls
- omsi.bus.retarder
- omsi.bus.rpm
- omsi.bus.sales
- omsi.bus.service
- omsi.bus.set_cruise
- omsi.bus.set_destination
- omsi.bus.set_dirt
- omsi.bus.set_indicator
- omsi.bus.set_interior_light
- omsi.bus.set_line
- omsi.bus.set_vars
- omsi.bus.set_velocity
- omsi.bus.shift
- omsi.bus.sound_horn
- omsi.bus.start_up
- omsi.bus.state
- omsi.bus.steering_angle
- omsi.bus.stop_brake
- omsi.bus.stop_requested
- omsi.bus.ticket_request
- omsi.bus.tickets
- omsi.bus.toggle_door
- omsi.bus.toggle_handbrake
- omsi.bus.track
- omsi.bus.trailers
- omsi.bus.triggers
- omsi.bus.velocity
- omsi.bus.velocity_vector
- omsi.bus.wheels
- omsi.distance
- omsi.has_vehicle
- omsi.mesh_point
- omsi.position
- omsi.press
- omsi.release
- omsi.set_str
- omsi.set_var
- omsi.speed
- omsi.str
- omsi.sys
- omsi.trigger
- omsi.var
- omsi.vars
- omsi.vehicle
- omsi.vehicle_manufacturer
- 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.
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.
for _, d in ipairs(omsi.bus.destinations()) do
if d.name == "Hauptbahnhof" then omsi.bus.set_destination(d.index) end
endomsi.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.
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.
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.
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.
local s = omsi.bus.state()
if s then print(s.speed, s.gear, s.doors_open) endomsi.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.
omsi.bus.toggle_door(1) -- the front dooromsi.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.
local t = omsi.bus.track()
if t then print("lane", t.lane, "at", t.s, "of", t.lane_length) endomsi.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.
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.
local x, y, z, heading = omsi.position()
if x then omsi.log(string.format("%.0f %.0f facing %.0f", x, y, heading)) endomsi.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.
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.
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.
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.
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.
local kmh = omsi.var("Velocity")
if kmh and kmh > 50 then omsi.message("Too fast!", 2) endomsi.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.
for _, name in ipairs(omsi.vars()) do print(name) endomsi.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.