GM/EntityTakeDamage

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(Clarification)
Line 1: Line 1:
 
{{Hook
 
{{Hook
|Name=EntityTakeDamage
 
|Parent=GM
 
 
|Description=Called when an entity takes damage. You can modify all parts of the damage info in this hook.
 
|Description=Called when an entity takes damage. You can modify all parts of the damage info in this hook.
 
|Realm=Server
 
|Realm=Server
Line 31: Line 29:
  
 
end
 
end
|Output=Explosion damage reduced by half.
 
 
}}
 
}}
 
{{Example
 
{{Example
Line 50: Line 47:
  
 
end
 
end
|Output=Driver takes halved damage.
 
 
}}
 
}}

Revision as of 01:48, 4 March 2017

 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

boolean

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


Personal tools
Navigation