- Documentation
- Shared functions
- setPedFocus
Function
setPedFocus
Makes an NPC keep looking at a chosen element: the ped turns its whole body toward it, optionally its head too, and follows it as it moves. On the server everyone sees it. On the client it only works in this game and overrides the server's setting; nil brings back what the server set. Useful for shopkeepers, guards and NPCs in cutscenes.
Syntax
bool setPedFocus(ped ped, element target [, bool head = true])Arguments
pedped- An NPC (a
pedelement). targetelement- The element to look at (player, vehicle, object...), other than the NPC itself.
nil= stop. headbool, optional = truetrue= also turns the head,false= body only.
Returns
true on success.
Example
addEventHandler("onPlayerJoin", root, function()
setPedFocus(shopkeeper, source, true)
end)
See also
getPedFocusReturns the element an NPC keeps looking at (set withsetPedFocus) and whether it turns its head too. On the client it returns the local setting first, and the server's one when there is none. Returnsfalsewhen the NPC is not focused on anything.setPedLookAtTurns a ped toward the given point and remembers where and for how long it should look. The body turn happens immediately (the ped's heading changes), while the point, time and element are stored for scripts and returned bygetPedLookAt; the game does not additionally turn the head. To keep following a target with the eyes usesetPedFocus.