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

Function

setPedAttackTarget

ServerPedsTrilogy Hub only

Makes 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. Passing nil or false ends the fight. The fight also ends by itself when the target dies, leaves the server or is destroyed.

Syntax

bool setPedAttackTarget(ped ped, element target)

Arguments

pedped
The NPC that should attack.
targetelement
A player or another ped (not the same NPC). nil/false = end the fight.

Returns

true on success.

Example

addCommandHandler("zamach", function(player)
    local x, y, z = getElementPosition(player)
    local thug = createPed(102, x + 5, y, z)
    giveWeapon(thug, 22, 100, true)
    setPedAttackTarget(thug, player)
end)

See also