Skip to content

damaged⚓︎

The damaged event triggers after an actor has been damaged.

--- @param e damagedEventData
local function damagedCallback(e)
end
event.register(tes3.event.damaged, damagedCallback)

Tip

An event can be claimed by setting e.claim to true, or by returning false from the callback. Claiming the event prevents any lower priority callbacks from being called.

Event Data⚓︎

  • activeMagicEffect (tes3activeMagicEffect): Read-only. Only valid for elemental shield reactive damage. It is the magic effect of the shield which caused damage. Can be nil.
  • attacker (tes3mobileActor): Read-only. The mobile actor dealing the damage. Can be nil.
  • attackerReference (tes3reference): Read-only. The attacker mobile's associated reference. Can be nil.
  • damage (number): Read-only. The amount of damage done.
  • killingBlow (boolean): Read-only. If true, the damage killed the target.
  • magicEffect (tes3effect): Read-only. The specific effect that triggered the event. This is equal to accessing e.magicSourceInstance.effects[effectIndex]. Only valid if magicSourceInstance is set.
  • magicEffectIndex (number): Read-only. The index of the effect in source's effects list. Only valid if magicSourceInstance is set.
  • magicEffectInstance (tes3magicEffectInstance): Read-only. An instance of the magic effect in the spell that caused damage. Can be nil.
  • magicSourceInstance (tes3magicSourceInstance): Read-only. A tes3magicSourceInstance object of a spell that caused damage. Can be nil.
  • mobile (tes3mobileActor): Read-only. The mobile actor that took damage.
  • projectile (tes3mobileProjectile): Read-only. Projectile that dealt the damage. Can be nil.
  • reference (tes3reference): Read-only. The mobile’s associated reference.
  • source (tes3.damageSource): Read-only. The origin of damage. These damage sources are present as tes3.damageSource constants. See the example. Damage with tes3.damageSource.shield source comes from magic shields. Other sources are self-explanatory.

Examples⚓︎

Example: Notify the player that their arrow/bolt killed their opponent

-- Print a message if player's arrow killed its target
local function onDamaged(e)
    -- We only care if the player did the damage
    if e.attackerReference ~= tes3.player then
        return
    end

    -- Check if the damage was caused by a projectile, but not by a spell, so it must be an arrow or a bolt
    if e.projectile ~= nil and e.magicSourceInstance == nil then

        -- Did the damage kill the target?
        if e.killingBlow == true then
            tes3.messageBox("Your arrow felled its target!")
        end
    end
end
event.register(tes3.event.damaged, onDamaged)

Example: Detect that the player died from drowning

local function onDamaged(e)
    -- We only care if the player recieved the damage
    if e.reference ~= tes3.player then
        return
    end

    -- Does the damage come from drowining?
    if e.source ~= tes3.damageSource.suffocation then
        return
    end

    -- Is the player in Mudan Grotto?
    if tes3.mobilePlayer.cell.id:lower() == "mudan grotto" then

        -- Did the damage kill the player?
        if e.killingBlow == true then
            tes3.messageBox("You died diving for treasure!")
        end
    end
end
event.register(tes3.event.damaged, onDamaged)

damagedamageddamageHandToHanddamagedHandToHand