setPedNavigateTo
Give an NPC a destination and GTA's pedestrian pathfinder takes over: it chooses a route through the native path network, goes around buildings, walks or runs naturally, slows down, and stops near the target.
Complete example
-- client.lua-- GTA chooses the pedestrian route; Lua only gives the destination.local sweet = createPed(270, 2495.2, -1687.4, 13.5)local destination = Vector3(2520.0, -1672.0, 13.8)
if sweet then assert(setPedNavigateTo(sweet, destination, "run"))endSyntax
bool setPedNavigateTo(ped thePed, Vector3 target [, string movement = "walk", float radius = 0.5, float slowdownRadius = 3.0, float heightChangeThreshold = 2.0, bool keepNodesHeadingAwayFromTarget = false, int timeout = -1, bool useBlending = true])GTA task mapping
CTaskComplexFollowNodeRouteGTA builds and follows its pedestrian node route. San Andreas Online also preserves the task's native recovery when the ped meets a building collision. The audited source identifies task type 906; no numeric SCM opcode is claimed.
Arguments
thePedpedLiving streamed ped simulated by this client.
targetVector3Finite world destination.
movementstringoptional · default walkwalk, run, or sprint.
radiusfloatoptional · default 0.5Positive arrival radius.
slowdownRadiusfloatoptional · default 3.0Slowdown radius not smaller than radius.
heightChangeThresholdfloatoptional · default 2.0Positive vertical-change threshold used while GTA builds the route.
keepNodesHeadingAwayFromTargetbooloptional · default falseKeep route nodes that initially head away from the target when GTA needs them.
timeoutintoptional · default -1-1 for no timeout, or a non-negative timeout in milliseconds.
useBlendingbooloptional · default trueBlend the native movement transitions.
Returns
true when GTA accepted the route task; false when the ped, ownership, streaming, liveness, destination, movement, radii, height threshold, or timeout 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.
- true means the task was accepted, not that the NPC has arrived. There is no completion event or durable route handle.
OOP aliases
ped:setNavigateTo(target, movement, radius, slowdownRadius, heightChangeThreshold, keepNodesHeadingAwayFromTarget, timeout, useBlending)
Where this comes from
Continue exploring
← Back to the SA:O Lua API · How Native ped tasks and gang tags works →