- Documentation
- Server functions
- setPedAggressive
Function
setPedAggressive
Turns 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 called setPedAttackTarget. A non-aggressive NPC (the default) takes damage and does not react. Works only for NPCs (ped), not for players.
Syntax
bool setPedAggressive(ped ped, bool on)Arguments
pedped- An NPC (a
pedelement). onbooltrue= aggressive,false= passive.
Returns
true on success.
Example
local bouncer = createPed(164, 1833.5, -1682.4, 13.5, 90)
setPedAggressive(bouncer, true)
See also
isPedAggressiveChecks whether an NPC is aggressive, i.e. whether it fights back on its own when someone hurts it. Aggression is set withsetPedAggressiveor the seventh argument ofcreatePed.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.createPedCreates a new NPC ped on the server (a pedestrian driven by the game, not by a player) and shows it right away to every player nearby. The ped gets 100 health, a random appearance variant (clothes and skin tone, seesetPedVariant) and belongs to the resource that created it, so it disappears together with that resource onstop. Optionally it can be made aggressive straight away or told to attack a chosen target.