ServersYour serverFor creatorsForumFAQDocumentationSecurity
Download the launcher
  1. Documentation
  2. Server functions
  3. setPedWalkTo

Function

setPedWalkTo

ServerPedsTrilogy Hub only

The NPC walks straight to a point. It avoids other peds but does not find a way around buildings, so split a longer route into points. When it arrives, the onPedReachedTarget event fires. setPedWalkTo(ped, false) stops the walk.

Syntax

bool setPedWalkTo(ped ped, float x, float y, float z [, string speed = "walk", float radius = 1])

Arguments

pedped
The NPC.
xfloat
Target X, or false to stop.
yfloat
Target Y.
zfloat
Target Z.
speedstring, optional = "walk"
"walk", "run" or "sprint".
radiusfloat, optional = 1
The distance that counts as arrived, in metres.

Returns

true on success.

Example

local guard = createPed(280, 1550, -1675, 16)
setPedWalkTo(guard, 1540, -1675, 16, "walk")
addEventHandler("onPedReachedTarget", guard, function()
    setPedWalkTo(source, 1550, -1675, 16, "walk")
end)

Notes

The walk is driven by the game of the player nearest to the NPC (up to 250 m); with no players nearby the NPC waits. Combat takes priority over walking.

See also