Garry's Mod Wiki

ENTITY:OnTakeDamage

ENTITY:OnTakeDamage( CTakeDamageInfo damage )

Description

Called when the entity is taking damage.

Calling Entity:TakeDamage, Entity:TakeDamageInfo, Entity:DispatchTraceAttack, or Player:TraceHullAttack (if the entity is hit) in this hook on the victim entity can cause infinite loops since the hook will be called again. Make sure to setup recursion safeguards like the example below.

Arguments

1 CTakeDamageInfo damage
The damage to be applied to the entity.

Example

All damage taken by this entity is applied twice. This will count the damage taken as two distinctive hits as opposed to just scaling it in GM:EntityTakeDamage.

function ENT:OnTakeDamage( dmginfo ) -- Make sure we're not already applying damage a second time -- This prevents infinite loops if ( not self.m_bApplyingDamage ) then self.m_bApplyingDamage = true self:TakeDamageInfo( dmginfo ) self.m_bApplyingDamage = false end end

Page Links


Special Pages


Wikis

?

Render Time: 526ms

DB GetPage 41
Generate Html 14
SaveChanges (1) 455
Render Body 0
Render Sidebar 14