- Documentation
- Server events
- onPedReachedTarget
Event
onPedReachedTarget
The NPC reached the target set by setPedWalkTo (within radius). The walk has already ended, so the handler can send it on right away.
Handler
addEventHandler("onPedReachedTarget", root, function(x, y, z) ... end)Parameters
xfloat- Target X.
yfloat- Target Y.
zfloat- Target Z.
Source
source is the NPC.
Example
local route = { { 1540, -1675, 16 }, { 1540, -1690, 16 }, { 1550, -1690, 16 } }
local guard = createPed(280, 1550, -1675, 16)
local step = 1
setPedWalkTo(guard, unpack(route[step]))
addEventHandler("onPedReachedTarget", guard, function()
step = step % #route + 1
setPedWalkTo(source, unpack(route[step]))
end)
See also
setPedWalkToThe 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, theonPedReachedTargetevent fires.setPedWalkTo(ped, false)stops the walk.getPedWalkTargetReturns the walk target set bysetPedWalkTo.