setPedDriveWander
Put an NPC behind the wheel and tell it to cruise. GTA's original driving AI takes over: it follows the native road network, chooses streets, steers, accelerates, brakes, and reacts to traffic according to the driving style.
Complete example
-- client.lua-- Create a local traffic car and give its driver GTA's road autopilot.local car = createVehicle(492, 2494.0, -1684.0, 13.4)local driver = createPed(105, 2494.0, -1684.0, 13.4)
if car and driver then warpPedIntoVehicle(driver, car, 0) assert(setPedDriveWander(driver, car, 20.0, "avoid_cars"))endSyntax
bool setPedDriveWander(ped thePed, vehicle theVehicle, float speed [, string|int drivingStyle = 0])GTA task mapping
05D2 CTaskComplexCarDriveWanderSCM equivalent: TASK_CAR_DRIVE_WANDER
San Andreas Online calls GTA's original constructor and preserves the verified speed, driving-style, and autopilot layout. The task runs until it is replaced or cancelled.
Arguments
thePedpedLiving streamed ped simulated by this client.
theVehiclevehicleStreamed, non-blown vehicle occupied by the ped as driver.
speedfloatFinite speed from 0 through 255.
drivingStylestring|intoptional · default 0Integer 0..6 or one of the documented stop/avoid/plough-through names.
Returns
true when the native wander task was assigned; false when ownership, vehicle, seat, speed, or style checks fail.
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.
OOP aliases
ped:setDriveWander(vehicle, speed, drivingStyle)
Where this comes from
Continue exploring
← Back to the SA:O Lua API · How Native ped tasks and gang tags works →