The damage event triggers before an actor is damaged. The damage value can be modified, or the damage can be prevented completely by blocking the event.
--- @param e damageEventData local function damageCallback(e) end event.register(tes3.event.damage, damageCallback)
This event supports blocking by setting
true or returning
false. Blocking the event prevents vanilla behavior from happening. For example, blocking an
equip event prevents the item from being equipped.
An event can be claimed by setting
true, or by returning
false from the callback. Claiming the event prevents any lower priority callbacks from being called.
activeMagicEffect(tes3activeMagicEffect): Read-only. Only valid for elemental shield reactive damage. It is the magic effect of the shield which will cause damage. Can be
attacker(tes3mobileActor): Read-only. The mobile actor dealing the damage. Can be
attackerReference(tes3reference): Read-only. The attacker mobile's associated reference. Can be
damage(number): The amount of damage done.
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 will cause the damage. Can be
magicSourceInstance(tes3magicSourceInstance): Read-only. A
tes3magicSourceInstanceobject of a spell that will cause the damage. Can be
mobile(tes3mobileActor): Read-only. The mobile actor that is taking damage.
projectile(tes3mobileProjectile): Read-only. Projectile that will deal the damage. Can be
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.damageSourceconstants. See the example. Damage with
tes3.damageSource.shieldsource comes from magic shields. Other sources are self-explanatory.
Example: Change fall damage
-- Change fall damage if player is a Bosmer local function onDamage(e) -- We only care if the player took some damage if e.reference ~= tes3.player then return end -- Check if the damage was caused by a fall if e.source ~= tes3.damageSource.fall then return end -- Check weather the player is a Bosmer if e.reference.object.race.id:lower() == "bosmer" then -- This is the same as tes3.player.object.race.id:lower() == "bosmer" -- Taunt the player tes3.messageBox("Ha ha ha, you broke your leg Bosmer") -- Double the damage. He is Fargoth's cousin after all e.damage = e.damage * 2 end end event.register(tes3.event.damage, onDamage)