Docs / Plugins / Plugin API reference
AI traffic
On this page
omsi.traffic.* reads and changes the AI traffic. omsi.others and the other_* functions also cover other players' buses in a LAN game.
omsi.other_body_frame#
omsi.other_body_frame(id, [section]) → x, y, z, rx, ry, rz, fx, fy, fz, ux, uy, uz
body_frame of one of others: its body now, origin and axes.
Parameters: id integer; section integer, optional.
Since 0.2.22.
omsi.other_mesh_point#
omsi.other_mesh_point(id, mesh, x, y, z, [section]) → x, y, z
mesh_point of one of others: where a point of one of its meshes (or, with section, of one of its coupled sections') is now.
Parameters: id integer; mesh string; x number; y number; z number; section integer, optional.
Since 0.2.22.
omsi.other_var#
omsi.other_var(id, name) → number or nil
A script variable of one of others, or nil.
Parameters: id integer; name string.
Since 0.2.21.
omsi.others#
omsi.others([radius]) → list of tables
The other vehicles within radius m of the bus (default 300): each {id, kind, name, x, y, z, heading}, kind being "ai" (the traffic) or "player" (another player's bus in a LAN game); empty on foot.
Parameters: radius number, optional.
Since 0.2.21.
for _, v in ipairs(omsi.others(100)) do print(v.kind, v.name) endomsi.set_other_var#
omsi.set_other_var(id, name, value) → boolean
Sets a script variable of one of others; true when that vehicle has it. An AI vehicle keeps it until its scripts write it again; another player's bus takes its values from the network again.
Parameters: id integer; name string; value number.
Since 0.2.21. Permission: traffic_write.
omsi.traffic.ahead#
omsi.traffic.ahead([reach]) → table or nil
The AI vehicle ahead of the player's bus within reach m (default 100) and 20° of its heading, with its distance: for a distance warning or a cruise control.
Parameters: reach number, optional.
Since 0.2.22.
local car = omsi.traffic.ahead(80)
if car and car.distance < 15 then omsi.message("Keep your distance", 2) endomsi.traffic.clear#
omsi.traffic.clear() → integer or nil
Takes every car not running to a timetable off the road; how many went.
Since 0.2.22. Permission: traffic_write.
omsi.traffic.counts#
omsi.traffic.counts() → driving, buses, asleep, parked
The AI vehicles: driving, timetable buses among them, asleep out of range, parked.
Since 0.2.22.
omsi.traffic.density#
omsi.traffic.density() → cars, share
How many cars the traffic keeps around the camera, and the share of them that do not run to a timetable (0 to 1).
Since 0.2.22.
omsi.traffic.get#
omsi.traffic.get(id) → table or nil
One AI vehicle by its id, as traffic.list gives them.
Parameters: id integer.
Since 0.2.22.
omsi.traffic.light_ahead#
omsi.traffic.light_ahead([reach]) → table or nil
The traffic light the player's bus comes to within reach m (default 80): {aspect, change_in, distance} - aspect "red", "red_yellow", "green", "green_yellow", "yellow" or "dark", change_in the seconds to its next change.
Parameters: reach number, optional.
Since 0.2.22.
local l = omsi.traffic.light_ahead()
if l and l.aspect == "red" then print("red in", l.distance, "m") endomsi.traffic.list#
omsi.traffic.list([radius]) → list of tables
The AI vehicles (within radius m of the player's bus, when given): {id, kind, name, x, y, z, heading, speed, max_speed, waiting_for, standing, braking, blinker, line, bounding_box, distance}. kind: "car", "taxi", "bus", "truck", "timetable_bus", "tram", "bicycle";
waiting_for why it waits or slows ("lead", "light", "yield", "people", ...); standing the seconds it has stood;
bounding_box the body's [boundingbox] as {width, length, height, cx, cy, cz, heading, default} (metres, the .bus/.ovh order; cx/cy/cz the box centre's offset from the vehicle's x, y, z along the body's right, forward and up, which follow heading; default when the file gives no box and the collision code's 2.5 x 12 x 3 m is used).
Parameters: radius number, optional.
Since 0.2.22.
omsi.traffic.nearest#
omsi.traffic.nearest([kind]) → table or nil
The AI vehicle nearest to the player's bus (of that kind, when given), with its distance.
Parameters: kind string, optional.
Since 0.2.22.
omsi.traffic.remove#
omsi.traffic.remove(id) → boolean
Takes an AI vehicle off the road (a timetable bus too: its timetable forgets it); its passengers get out.
Parameters: id integer.
Since 0.2.22. Permission: traffic_write.
omsi.traffic.set_density#
omsi.traffic.set_density(cars, [share]) → boolean
Changes the traffic's amount (as the game menu's slider: 0 to 500 cars) and, when given, the share not running to a timetable; it fills up or thins out over the next seconds.
Parameters: cars integer; share number, optional.
Since 0.2.22. Permission: traffic_write.
omsi.traffic.set_density(50)omsi.traffic.spawn#
omsi.traffic.spawn(at, [options]) → the car's id, or nil
An AI car appears on the street lane nearest at {x, y, z} and drives on as the traffic does: options.model picks one of the map's traffic types whose file names it ("Golf", Vehicles/Cars/Polizei), any without; options.speed its speed at first, km/h. A traffic jam, a police escort, a car that cuts in. nil without a lane or traffic there.
Parameters: at table; options table, optional.
Since unreleased. Permission: traffic_write.
Something wrong or missing? Fix it on GitHub or open an issue.