Examples
Resources
GUI
Building objects
Misc commands
Spawning a crane and an eagle:
cmd = api.cmd.make.spawnAnimal("animal/bird_eagle.mdl", api.type.Vec2f.new(50, 50)) api.cmd.sendCommand(cmd, function(res, valid) end) a = api.cmd.make.spawnAnimal("animal/bird_crane.mdl", api.type.Vec2f.new(.0, .0)) api.cmd.sendCommand(a)
Replacing a vehicle:
tv = api.engine.getComponent(66814, api.type.ComponentType.TRANSPORT_VEHICLE) -- fileName = "vehicle/truck/40_tons.mdl", cfg = api.type.TransportVehicleConfig.new() vehicle = api.type.TransportVehiclePart.new() vehicle.purchaseTime = 2933600 vehicle.maintenanceState = 0.99765330553055 vehicle.targetMaintenanceState = 0 vehicle.autoLoadConfig = { 1 } part = api.type.VehiclePart.new() part.modelId = apt.type. -- 6864 part.loadConfig[1] = 0 vehicle.part = part cfg.vehicles[1] = vehicle cfg.vehicleGroups[1] = 1 cmd = api.cmd.make.replaceVehicle(66814, cfg) api.cmd.sendCommand(cmd, function(cmd, valid) print(valid) end)
Pathfinding
Find a path from two edges of the street entity 170679 to the nodes of the street entity 171540:
e1 = api.type.EdgeId.new(170679, 0) e2 = api.type.EdgeId.new(170679, 1) n1 = api.type.NodeId.new(171540, 0) n2 = api.type.NodeId.new(171540, 1) n3 = api.type.NodeId.new(171540, 2) n4 = api.type.NodeId.new(171540, 3) -- g = api.engine.getComponent(171540, api.type.ComponentType.TRANSPORT_NETWORK) z = api.engine.util.pathfinding.findPath( { api.type.EdgeIdDirAndLength.new(e1, true, .0), api.type.EdgeIdDirAndLength.new(e2, true, .0), }, { n1, n2, n3, n4 }, {}, 1000 )
Useful ID for UI elements
In-game UI elements can be obtained in the following way:
g = api.gui.util.getById("menu.construction.rail.settings")
The id of elements can be obtained with the debug tools "AltGr + D", under "Show UI Element Name".
The main menu has two sub-layouts with ids "mainMenuLeftLayout" and "mainMenuRightLayout".
The id "menu.construction" is reserved to sub-menus of the construction menu, with the following categories: "rail", "road", "air", "water", "town", "terrain" and "industry".
The "settings" suffix tab references the Settings window. Notice that the element is destroyed once a new element is selected.
The individual entries in the construction menus can be obtained using the following
menu.construction.<submenu>.<category>.item.<resource_id>
for example:
menu.construction.road.street-constructions.item.street/roundabout.con
The bottom information bar can be reached with id "gameInfo".
The temporary window displaying information about an entity is
temp.view.entity_<entity_id>
notice that this window is only temporary and will be destroyed once the window is closed.
The module menu can has id "menu.addModuleComp" whereas the temporary menu with parameters has id:
temp.addModuleComp.params.entity_<entity_id>
The cockpit view can be reached with the id "cockpit-view".