Docs / Plugins / Writing plugins
Reading timetable and depot data
Game data getters#
omsi.game.query(name, args) reads the same data as the vehicle scripts' getters (GetTerminusString, GetTTBusstopArr and so on), without running a script. omsi.game.queries() lists the names, argument names and types, and result types; the full list is in the reference. Getter arguments keep OMSI's zero-based indices.
Reads use the player's bus and its current HOF and timetable. Without a bus they return nil and a reason. As a third argument, pass the map id of a loaded scripted scenery object to read that object instead; this lets GetArrBus* read a departure board's arrivals without a player vehicle. Find object ids with omsi.map.objects_near(x, y).
The whole tour#
omsi.duty.tour() returns the complete source tour of the current duty, even when only one trip was chosen. omsi.timetable.tour(line, tour) reads any tour without taking it. Times are seconds from midnight of the service day, can go past 24:00, and passing stops are included.
local tour = omsi.duty.tour()
if tour then
for _, trip in ipairs(tour.trips) do
for _, stop in ipairs(trip.stops) do
print(trip.line, trip.terminus, stop.name, stop.arrival, stop.departure)
end
end
endThe loaded HOF file#
omsi.hof.get() returns a snapshot of every field of the player's loaded depot (HOF) file: its name and path, the service-trip identifier, the global strings and string counts, all termini and bus stops with their identifiers and strings, and the info-system trips, stop lists and stop rows.
Empty strings and the original order are kept. info_trips[].code stays a string, leading zeroes included. Comments and unknown directives are not part of it.
omsi.hof.terminus(identifier) and omsi.hof.busstop(identifier) look up one entry without copying the whole depot. Both match the identifier exactly, case-sensitively, and return the first match. For a terminus, the identifier is the HOF's internal one, not a display text or IBIS code.
index fields are zero-based, as GetTerminusString and GetBusstopString expect, while Lua lists start at 1. So getter field 8 is strings[9]:
local tour = omsi.duty.tour()
if tour then
for _, trip in ipairs(tour.trips) do
local t = omsi.hof.terminus(trip.terminus)
if t then
print(trip.name, t.index, t.code, t.strings[9] or "", t.strings[10] or "")
end
end
endGetTTTerminusIndex reads the current timetable state and takes no trip, so the code above is how to resolve every trip of a tour without changing the duty.
Snapshots are copies: changing them changes nothing in the game. Keep a snapshot for repeated reads instead of copying the depot every frame, and read a new one when the vehicle or its HOF changes. The API cannot open other HOF files or change the depot, needs no permission, and works the same in Lua and WebAssembly.
Something wrong or missing? Fix it on GitHub or open an issue.