The AttackEntityEvent is fired when a player attacks an Entity.
The AttackEntityEvent class is a subtype of the Event class and inherits all its properties and functions.
Here is an overview of the AttackEntityEvent properties:
Property | Type | read / write |
---|---|---|
player | Player | r |
target | Entity | r |
Below you find short descriptions about each of the properties and some examples about how to use them in your spells.
This is the player that attacks the entity.
Canceling the attack event when the player is invisible.
Events.on('AttackEntityEvent'):call(function(event)
if event.player.invisible then
event.canceled = true
end
end)
This is the entity that is attacked.
Canceling the attack event when the target is a zombie.
Events.on('AttackEntityEvent'):call(function(event)
if event.target.entityType == "zombie" then
event.canceled = true
end
end)