openOMSI GitHub Discord

Docs / Plugins / Lua plugins

Reading game data and the complete selected tour

1 min readEdit this pagedocs/PLUGINS.md

omsi.game.query reads the same game-owned sources as the M.V. getters, without running the vehicle script or dispatching its callbacks. Use omsi.game.queries() to discover names, argument names/types and return types. Getter arguments retain OMSI's zero-based indices; other plugin lists use one-based Lua indices.

Reads refer to the player's bus and its current HOF and timetable. No bus returns nil, reason. An optional third argument selects a loaded scripted scenery object's map id instead, allowing GetArrBus* to read a departure board's actual arrivals even without a player vehicle.

Find object ids with omsi.map.objects_near(x, y); an unloaded or nonscripted object returns nil, reason. Mutation/drawing commands are deliberately not data getters. GetFontIndex is excluded because it can load fonts and extend the vehicle's font list.

Lua
local text = omsi.game.query("GetTerminusString", {0, 0})
local arrival = omsi.game.query("GetTTBusstopArr", {0})
local tour = omsi.duty.tour() -- entire source tour, even with just one trip selected
if tour then
    for _, trip in ipairs(tour.trips) do
        for _, stop in ipairs(trip.stops) do
            -- Seconds from service-day midnight, including 24:xx and passing stops.
            print(trip.line, trip.terminus, stop.name, stop.arrival, stop.departure)
        end
    end
end

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

↑↓ to move↵ to open