Skip to content

setPedWander

Client-side

Tell an NPC to wander and GTA's original pedestrian AI takes over: it follows the native path network, chooses its own direction from node to node, and keeps walking or running without Lua waypoints.

Complete example

-- client.lua
-- This local ped picks its own walking path instead of following Lua waypoints.
local pedestrian = createPed(7, 2498.0, -1687.0, 13.5)
if pedestrian then
assert(setPedWander(pedestrian, "walk", -1, true))
end

Syntax

bool setPedWander(ped thePed [, string movement = "walk", int direction = -1, bool wanderSensibly = true])

GTA task mapping

ORIGINAL GTA TASK 05DE
CTaskComplexWanderStandardCTaskComplexWander

SCM equivalent: TASK_WANDER_STANDARD

A direction of -1 is resolved by GTA's native random-direction helper before the standard wander task is created. Under the ambient-cop-safe profile San Andreas Online builds a WANDER_TYPE_COP task on GTA's base Wander locomotion vtable with an empty scanner, so police escalation is unreachable.

Arguments

thePedped

Living streamed ped simulated by this client.

movementstringoptional · default walk

walk or run.

directionintoptional · default -1

-1 for GTA's native random direction, or a direction from 0 through 7.

wanderSensiblybooloptional · default true

Use the native sensible-wander behavior. Rejected as false while the ambient-cop-safe profile is selected.

Returns

true when the task was queued; false for invalid movement, direction, ped state, ownership, or task construction.

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
  • A ped holding the ambient-cop-safe event profile gets San Andreas Online's safe ambient-cop wander task instead of WanderStandard.
  • Under that profile wanderSensibly = false returns false rather than being applied. Retail WanderCop hardcodes sensible walking, so accepting it would produce a hybrid state neither task can reach.

OOP aliases

  • ped:setWander(movement, direction, wanderSensibly)

Where this comes from

RELATED SA:O APIS

Continue exploring

Read the system guide →