GM:EntityTakeDamage
Description
Called when an entity takes damage. You can modify all parts of the damage info in this hook.
Applying damage from this hook to the entity taking damage will lead to infinite loop/crash.
Arguments
Returns
Example
Explosion damage is reduced to players only.
hook.Add( "EntityTakeDamage", "EntityDamageExample", function( target, dmginfo )
if ( target:IsPlayer() and dmginfo:IsExplosionDamage() ) then
dmginfo:ScaleDamage( 0.5 ) // Damage is now half of what you would normally take.
end
end )
Example
Players in vehicles takes halved damage.
hook.Add( "EntityTakeDamage", "EntityDamageExample2", function( target, dmginfo )
if ( target:IsVehicle() ) then
local ply = target:GetDriver()
if ( IsValid(ply) && dmginfo:GetDamage() > 1 ) then
dmginfo:SetDamage(dmginfo:GetDamage() / 2)
ply:TakeDamageInfo(dmginfo)
dmginfo:SetDamage(0)
end
end
end )