Wizards of Lua

The Art of Spell Crafting


AttackEntityEvent

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

Properties

Below you find short descriptions about each of the properties and some examples about how to use them in your spells.


player : Player

This is the player that attacks the entity.

Example

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)

target : Entity

This is the entity that is attacked.

Example

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)