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 benil
.attacker
(tes3mobileActor): Read-only. The mobile actor dealing the damage. Can benil
.attackerReference
(tes3reference): Read-only. The attacker mobile's associated reference. Can benil
.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 accessinge.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 benil
.magicSourceInstance
(tes3magicSourceInstance): Read-only. Ates3magicSourceInstance
object of a spell that caused damage. Can benil
.mobile
(tes3mobileActor): Read-only. The mobile actor that took damage.projectile
(tes3mobileProjectile): Read-only. Projectile that dealt the damage. Can benil
.reference
(tes3reference): Read-only. The mobile’s associated reference.source
(tes3.damageSource): Read-only. The origin of the damage. These damage sources are present astes3.damageSource
constants. See the example. Damage withtes3.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)