Wizards of Lua

The Art of Spell Crafting


LivingDeathEvent - When a Living Entity Dies

The LivingDeathEvent class is fired when an entity dies.

The LivingDeathEvent class is a subtype of the LivingEvent class and inherits all its properties and functions.

Here is an overview of the LivingDeathEvent properties:

Property Type read / write
cause string r

Properties

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


cause : string

The cause of death. This is something like ‘drown’, ‘lava’, ‘fall’, etc.

Example

Rewarding a player who died in lava with a brand new lava bucket.

local causes = {}
local queue = Events.collect("LivingDeathEvent","PlayerRespawnEvent")
while true do
  local event = queue:next()
  if event.name == "LivingDeathEvent" and type(event.entity)=="Player" then
    causes[event.entity.name] = event.cause
  elseif event.name == "PlayerRespawnEvent" then
    if causes[event.player.name]=="lava" then
      spell:execute("/give %s minecraft:lava_bucket", event.player.name)
    end
  end
end