openOMSI GitHub Discord
Writing plugins

Docs / Plugins / Writing plugins

Passengers' tickets

2 min readEdit this pagedocs/PLUGINS.md

What a passenger asks for at the cash desk is normally the ticket pack's choice. A plugin can change it, for example to charge by zones, by fare units, or to accept a pass.

Everybody boarding the player's bus is reported once, on the way to the door, as the passenger_ticket event. It says who they are (id, age), what they do about a ticket (kind: "none", "stamp" or "buy"), the pack's ticket and price, the stop they board at and the stop they ride to, and where both are in the duty's trip.

The passenger waits in the doorway until the plugins have had that frame (normally the next one, at most 5 s of game time). In that time a plugin can hand over its own fare with omsi.people.set_ticket:

Lua
omsi.on("passenger_ticket", function(p)
  if p.kind ~= "buy" or not p.destination_number then return end
  local stops = p.destination_number - p.stop_number
  omsi.people.set_ticket(p.id, {
    name = stops <= 3 and "Short hop" or "Single",
    price = stops <= 3 and 1.5 or 3,
    voice = "Zone_" .. stops,   -- Zone_<n>.wav of the passenger's voice folder
    tag = "my_tariff",          -- kept with the passenger: omsi.people.get(id).tag
  })
end)

The rules:

  • kind can change only until the passenger is in the bus. The ticket, name, price, payment and voice can change until they have asked at the desk (omsi.people.get(id).ticket_asked).
  • ticket picks another ticket of the pack, with its name, price and GivenTicket number. name and price alone keep the pack's number, so the bus's ticket printer and the driver's ticket key keep working.
  • A buyer always has a ticket of the pack that the driver can give. ticket = 0 is refused for them. Somebody made a buyer without ticket gets the pack's ticket for their age; when the pack has none for their age, the change is refused.
  • payment is the money handed over. It does not change the price and is at least the price. The amount may be higher when the currency's coins and notes cannot make it exactly.
  • A voice line the passenger's voice folder does not have falls back to the usual Ticket_<n>_<k>.
  • omsi.people.get(id) shows the passenger's ticket now and which plugin changed it (ticket_by).

Without a plugin listening, passengers ask for what the ticket pack gives them and nobody waits.

reduced_tickets.lua has every adult ask for the reduced fare of the stock Berlin ticket packs. passenger_log.lua writes what a plugin learns of each passenger into game.log.

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

↑↓ to move↵ to open