Garry's Mod Wiki

Garry's Mod Wiki

  boolean GM:EntityTakeDamage( Entity target, CTakeDamageInfo dmg )

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

1 Entity target
The entity taking damage
2 CTakeDamageInfo dmg
Damage info

Returns

1 boolean
Return true to completely block the damage event

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 )

This site is a community mirror of the official Garry's Mod wiki.. This site is not maintained by Facepunch Studios.

Page content is automatically updated twice a day. Edits and history are not available.

Last Parsed: Loading...