Vehicle -_- RTS Control (formerly AutoDrive Fixed)


Vehicle autopilot, RTS controls, smart convoy

Content
3 days ago
2.0 - 2.1
209
Transportation Combat

a Remote Interface (Lua API)

10 days ago
(updated 3 days ago)

-

10 days ago
(updated 10 days ago)

1. Integration (info.json)

Add RTS Control to the required dependencies of your mod:

"dependencies": [
  "base >= 2.0.0",
  "vehicle-_-rts-control >= 2.0.44"
]

2. Main Method: give_order

Call via "rts_control" (or "vehicle-_-rts-control") remote interface:

local success, error_msg = remote.call("rts_control", "give_order", params)
  • Returns: true on success, or false, "error message" on invalid parameters.

Parameters Table (params):

Parameter Type Required? Default
vehicles number / LuaEntity / table Yes none
Single vehicle (numerical ID unit_number or LuaEntity) or array of vehicles ({101, 102} / {car1, car2}).
────────────────────────────── ─────────────── ───────── ───────
action string No "move"
Action type: "move", "patrol", "follow", "stop".
────────────────────────────── ─────────────── ───────── ───────
target table / LuaEntity / LuaPlayer For move/patrol owner / none
Coordinates {x, y}, points array, or target entity. Not needed for "stop"; defaults to vehicle owner for "follow".
────────────────────────────── ─────────────── ───────── ───────
queue boolean No false
true — append to end of queue; false — clear old orders and execute immediately.
────────────────────────────── ─────────────── ───────── ───────
convoy boolean No false
Group multiple vehicles into a coordinated convoy formation.

2.1. Vehicle Passing Methods

The interface accepts vehicles in whichever format suits your mod:

  1. Single vehicle by ID (unit_number) — recommended for console testing or when storing entity IDs:
    lua vehicles = 452
  2. Single vehicle by game entity (LuaEntity) — convenient when handling mod events (event.entity):
    lua vehicles = entity
  3. In bulk by ID array:
    lua vehicles = {452, 453, 454}
  4. In bulk by entity array:
    lua vehicles = {car_entity_1, car_entity_2}

3. Quick In-Game Console Testing (~)

When testing commands directly in-game without writing a mod, use this 2-step workflow:


Step 1: Hover over a vehicle and print its ID:

/c game.print("ID: " .. tostring(remote.call("rts_control", "get_selected_id", game.player)))

The console will display the number (e.g. 452).


Step 2: Issue orders using the returned ID:

-- 1. Drive to player position:
/c remote.call("rts_control", "give_order", {vehicles = 452, action = "move", target = game.player.position})

-- 2. Append next destination to order queue (queue = true):
/c remote.call("rts_control", "give_order", {vehicles = 452, action = "move", target = {game.player.position.x + 50, game.player.position.y}, queue = true})

-- 3. Engage player escort (requires Follow sensor module in grid):
/c remote.call("rts_control", "give_order", {vehicles = 452, action = "follow", target = game.player})

-- 4. Start patrol loop around a square:
/c local p = game.player.position; remote.call("rts_control", "give_order", {vehicles = 452, action = "patrol", target = {{p.x+20, p.y}, {p.x+20, p.y+20}, {p.x, p.y+20}, p}})

-- 5. Stop vehicle and clear all queues:
/c remote.call("rts_control", "give_order", {vehicles = 452, action = "stop"})

4. Lua Mod Usage Examples


4.1. Standard Movement to a Point (action = "move")

The vehicle calculates a path, navigates around obstacles, and drives to the target position:

remote.call("rts_control", "give_order", {
  vehicles = my_car,
  action = "move",
  target = {x = 150.5, y = -80.0}
})

4.2. Multi-Waypoint Route

Passing an array of coordinates causes the vehicle to visit each waypoint sequentially:

remote.call("rts_control", "give_order", {
  vehicles = my_car,
  action = "move",
  target = {
    {x = 100, y = 100},
    {x = 200, y = 100},
    {x = 200, y = 200}
  }
})

4.3. Queuing Orders (queue = true)

Equivalent to Shift-clicking in-game — the new waypoint is appended to the queue and executed after completing current paths:

remote.call("rts_control", "give_order", {
  vehicles = my_car,
  action = "move",
  target = {x = 350, y = 400},
  queue = true
})

4.4. Looped Patrol Route (action = "patrol")

The vehicle cycles through the waypoints indefinitely (1 → 2 → 3 → 1 → ...):

remote.call("rts_control", "give_order", {
  vehicles = my_car,
  action = "patrol",
  target = {
    {x = -50, y = -50},
    {x = 50, y = -50},
    {x = 50, y = 50},
    {x = -50, y = 50}
  }
})

4.5. Following a Player or Leader Vehicle (action = "follow")

  • Following a player: Requires an installed Follow sensor module in the vehicle grid. The vehicle locks onto the player and escorts them at a safe distance:
remote.call("rts_control", "give_order", {
  vehicles = my_car,
  action = "follow",
  target = game.player -- or game.player.character
})
  • Following another vehicle:
remote.call("rts_control", "give_order", {
  vehicles = escort_tank,
  action = "follow",
  target = lead_truck
})

4.6. Emergency Stop & Clearing Orders (action = "stop")

Immediately brakes, flushes order queues, breaks out of patrol loops, and disengages follow mode:

remote.call("rts_control", "give_order", {
  vehicles = my_car,
  action = "stop"
})

-- Or using the quick shortcut:
remote.call("rts_control", "stop", my_car)

5. Utility Methods


5.1. Inspecting Vehicle Status (get_order_status)

Retrieve real-time navigation and queue status of a vehicle:

local status = remote.call("rts_control", "get_order_status", my_car)
--[[
Returns table:
{
  valid = true,
  unit_number = 1234,
  action = "move",        -- "move" | "patrol" | "convoy" | "idle"
  is_driving = true,      -- currently in motion
  arrived = false,        -- has reached final destination
  current_goal = {x, y},  -- immediate waypoint coordinate
  destination = {x, y},   -- final destination coordinate
  queue_length = 2,       -- waypoints remaining in queue
  is_patrol = false,      -- currently in active patrol loop
  convoy_id = nil         -- convoy group ID if part of a formation
}
--]]

5.2. Getting Selected Vehicle ID (get_selected_id)

Utility for testing and interactive scripts to retrieve the vehicle ID under a player's cursor:

local vehicle_id = remote.call("rts_control", "get_selected_id", player)

6. Important Technical Details

  1. Fuel / Grid Energy: The vehicle must have fuel in its burner inventory or energy in its equipment grid; otherwise, movement commands will be rejected with an error.

7. Developer Feedback

I don't actively use this interface myself, so it is likely far from perfect. Any feedback, suggestions, or feature requests from other mod authors will receive top priority — feel free to post in this thread if something is missing or could be improved!

New response