openOMSI GitHub Discord
Plugin API reference

Docs / Plugins / Plugin API reference

Map

3 min readEdit this pagedocs/PLUGIN_API.md

On this page
  1. omsi.map.entrypoints
  2. omsi.map.ground
  3. omsi.map.info
  4. omsi.map.lane
  5. omsi.map.name
  6. omsi.map.object
  7. omsi.map.objects_near
  8. omsi.map.place_on_road
  9. omsi.map.speed_limit
  10. omsi.map.stops
  11. omsi.map.teleport
  12. omsi.map.teleport_to
  13. omsi.map.terrain
  14. omsi.map.tile
  15. omsi.map.tile_at
  16. omsi.map.tiles
  17. omsi.map.to_world
  18. omsi.scene.raycast

omsi.map.* reads the map: tiles, ground height, lanes, stops, objects, start points; and moves the player's bus. Coordinates are map metres: x east, y north, z up.

omsi.map.entrypoints#

omsi.map.entrypoints() → list of tables

The map's start points: {index, name, x, y, z, heading} (index from 1; the place where the game has read its tile).

Since 0.2.22.

omsi.map.ground#

omsi.map.ground(x, y) → number or nil

The height of the ground (the road where there is one, else the terrain) at a map point, where its tile is loaded.

Parameters: x number; y number.

Since 0.2.22.

Lua
local z = omsi.map.ground(x, y)

omsi.map.info#

omsi.map.info() → table or nil

{name, friendly_name, path, left_hand_traffic, tile_size}: the map's names, its global.cfg and the side it drives on.

Since 0.2.22.

omsi.map.lane#

omsi.map.lane(x, y) → table or nil

The traffic lane nearest to a map point: {index, distance, speed_limit, name, traffic_light}.

Parameters: x number; y number.

Since 0.2.22.

omsi.map.name#

omsi.map.name() → string or nil

The map's name (its folder's).

Since 0.2.22.

omsi.map.object#

omsi.map.object(id) → x, y, z, heading

Where a map object is, by its id (a stop's id of the timetable, say); nothing when the game has not read its tile.

Parameters: id integer.

Since 0.2.22.

omsi.map.objects_near#

omsi.map.objects_near(x, y, [radius]) → list of tables

The map objects within radius m (default 50, at most 2000 of them, nearest first): {id, x, y, z, heading, distance}.

Parameters: x number; y number; radius number, optional.

Since 0.2.22.

Lua
local x, y = omsi.position()
for _, o in ipairs(omsi.map.objects_near(x, y, 30)) do print(o.id, o.distance) end

omsi.map.place_on_road#

omsi.map.place_on_road(x, y) → boolean

Puts the player's bus on the street nearest to a map point (within 300 m), along it.

Parameters: x number; y number.

Since 0.2.22. Permission: world_write.

omsi.map.speed_limit#

omsi.map.speed_limit() → number or nil

The speed limit (km/h) of the lane the player's bus drives on (nil off the lanes).

Since 0.2.22.

omsi.map.stops#

omsi.map.stops() → list of tables

The bus stops of the tiles loaded (around the camera): {id, name, x, y, z, heading}.

Since 0.2.22.

omsi.map.teleport#

omsi.map.teleport(x, y, [z], [heading]) → boolean

Moves the player's bus to a map point (z none: onto the highest ground there) facing heading (default north), as the game menu's move does; the service event says teleport.

Parameters: x number; y number; z number, optional; heading number, optional.

Since 0.2.22. Permission: world_write.

Lua
omsi.map.teleport(x, y, nil, 90)  -- z nil: onto the ground, facing east

omsi.map.teleport_to#

omsi.map.teleport_to(index) → boolean

Moves the player's bus to start point index (from 1, as map.entrypoints lists them).

Parameters: index integer.

Since 0.2.22. Permission: world_write.

omsi.map.terrain#

omsi.map.terrain(x, y) → number or nil

The terrain's height alone at a map point.

Parameters: x number; y number.

Since 0.2.22.

omsi.map.tile#

omsi.map.tile() → tile_x, tile_y

The tile the player's bus is on (nothing on foot).

Since 0.2.22.

omsi.map.tile_at#

omsi.map.tile_at(x, y) → tile_x, tile_y, local_x, local_y

The tile of a map point and the metres in it (x east, y north).

Parameters: x number; y number.

Since 0.2.22.

Lua
local tx, ty, lx, ly = omsi.map.tile_at(x, y)

omsi.map.tiles#

omsi.map.tiles() → list of tables

The map's tiles: {x, y, file, loaded} (numbered as global.cfg's [map] list).

Since 0.2.22.

omsi.map.to_world#

omsi.map.to_world(tile_x, tile_y, local_x, local_y) → x, y

A place given by its tile and the metres in it, in map coordinates.

Parameters: tile_x integer; tile_y integer; local_x number; local_y number.

Since 0.2.22.

omsi.scene.raycast#

omsi.scene.raycast(from, dir, [max]) → x, y, z or nothing

Where a ray from from {x, y, z} along dir {x, y, z} first meets the ground of the loaded tiles, within max metres (default 400, at most 2000): what the camera looks at, where a thrown object lands, the ground under a point.

Parameters: from table; dir table; max number, optional.

Since unreleased.

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

↑↓ to move↵ to open