damage⚓︎
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)
Tip
This event supports blocking by setting e.block
to true
or returning false
. Blocking the event prevents vanilla behavior from happening. For example, blocking an equip
event prevents the item from being equipped.
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 will cause 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): The amount of damage done.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 will cause the damage. Can benil
.magicSourceInstance
(tes3magicSourceInstance): Read-only. Ates3magicSourceInstance
object of a spell that will cause the damage. Can benil
.mobile
(tes3mobileActor): Read-only. The mobile actor that is taking damage.projectile
(tes3mobileProjectile): Read-only. Projectile that will deal 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: 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)