GM/EntityTakeDamage
From Garry's Mod
GM:EntityTakeDamage( )
Contents |
Description
Called when an entity takes damage. You can modify all parts of the damage info in this hook.
Arguments
Entity target
The entity taking damage
Arguments
CTakeDamageInfo dmg
Damage info
Returns
Return true to completely block the damage event
Examples
Example
Explosion damage is reduced to players only.
function GM:EntityTakeDamage( 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
Examples
Example
Players in vehicles takes halved damage.
function GM:EntityTakeDamage( 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