Skip to content

setPedDriveTo

Client-side

Give an NPC driver a destination and GTA's original driving AI takes over: it follows the native road network, chooses a route, steers, accelerates, and brakes as it drives toward the target.

Complete example

-- client.lua
-- The driver uses GTA's road AI to reach the destination.
local car = createVehicle(492, 2494.0, -1684.0, 13.4)
local driver = createPed(105, 2494.0, -1684.0, 13.4)
local destination = Vector3(2365.0, -1665.0, 13.4)
if car and driver then
warpPedIntoVehicle(driver, car, 0)
assert(setPedDriveTo(driver, car, destination, 18.0, "normal", "avoid_cars"))
end

Syntax

bool setPedDriveTo(ped thePed, vehicle theVehicle, Vector3 target, float speed [, string|int mode = "normal", string|int drivingStyle = "stop_for_cars"])

GTA task mapping

ORIGINAL GTA TASK 05D1
CTaskComplexCarDriveToPoint

SCM equivalent: TASK_CAR_DRIVE_TO_COORD

The direct form supplies the current vehicle, desired model -1, and native radius -1.0 before queuing GTA's original task through the script-command path.

Arguments

thePedped

Living streamed ped simulated by this client.

theVehiclevehicle

Streamed, non-blown vehicle occupied by the ped in driver seat 0 and controlled by this client.

targetVector3

Finite world destination.

speedfloat

Finite cruise speed from 0 up to, but not including, 255.

modestring|intoptional · default normal

Integer 0..3 or normal, accurate, straight_line, or racing.

drivingStylestring|intoptional · default stop_for_cars

Integer 0..6 or one of the documented stop/avoid/plough-through names.

Returns

true when GTA accepted the scripted command; false when ped, vehicle, seat, ownership, target, speed, mode, style, or task construction is invalid.

Ownership and lifecycle

Low-level ped task calls require the client that simulates the living, streamed ped. Driving tasks also require control of the streamed vehicle. They do not create lifecycle handles; the optional native-task-runtime adds server-owned route epochs and reconstruction for drive_to routes. Gang-tag ownership is resource-exclusive, survives object streaming and recreation, and is released automatically when the owner stops.

Important behavior
  • true does not mean the destination has been reached; the API has no completion event or durable task handle.
  • The linked route harness exercises this task inside a native sequence. The standalone call has not been exercised separately in game.

OOP aliases

  • ped:setDriveTo(vehicle, target, speed, mode, drivingStyle)

Where this comes from

RELATED SA:O APIS

Continue exploring

Read the system guide →