- Documentation
- Server functions
- setPedWalkTo
Function
setPedWalkTo
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
falseto 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
getPedWalkTargetReturns the walk target set bysetPedWalkTo.onPedReachedTargetThe NPC reached the target set bysetPedWalkTo(withinradius). The walk has already ended, so the handler can send it on right away.setPedAttackTargetMakes an NPC attack a player or another ped: the NPC walks up and punches or shoots with the weapon in its hand until the target dies, disappears or a script stops the fight. The fight is simulated by one player's game (the target player or the nearest player in the same dimension), so the NPC behaves the same for everyone. Passingnilorfalseends the fight. The fight also ends by itself when the target dies, leaves the server or is destroyed.