- Documentation
- Server functions
- setPedAttackTarget
Function
setPedAttackTarget
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
getPedAttackTargetReturns the element an NPC is currently attacking (set withsetPedAttackTargetor picked by an aggressive NPC after being hurt). Returnsfalsewhen the NPC is not fighting.setPedAggressiveTurns an NPC's aggression on or off. When an aggressive NPC gets hurt by someone (a player or another ped), it starts attacking the attacker on its own, as if a script calledsetPedAttackTarget. A non-aggressive NPC (the default) takes damage and does not react. Works only for NPCs (ped), not for players.givePedWeaponGives a ped a weapon with ammo, exactly likegiveWeapon(it is the same function under another name). If the ped already has a weapon in the same slot, it is replaced, while ammo for the same weapon adds up.