CTakeDamageInfo
A class used to store and modify all the data concerning a damage event. An empty CTakeDamageInfo object can be created with DamageInfo
List of hooks that this object is passed to:
- ENTITY:OnTakeDamage
- GM:DoPlayerDeath
- GM:EntityTakeDamage
- GM:PostEntityTakeDamage
- GM:OnDamagedByExplosion
- GM:ScaleNPCDamage
- GM:ScalePlayerDamage
- NEXTBOT:OnInjured
- NEXTBOT:OnKilled
- NEXTBOT:OnOtherKilled
List of functions that use this object:
Methods
number CTakeDamageInfo:GetAmmoType()
Returns the ammo type used by the weapon that inflicted the damage.
Entity CTakeDamageInfo:GetAttacker()
Returns the attacker ( character who originated the attack ), for example a player or an NPC that shot the weapon.
number CTakeDamageInfo:GetBaseDamage()
Returns the initial unmodified by skill level ( game. GetSkillLevel ) damage.
number CTakeDamageInfo:GetDamageBonus()
Gets the current bonus damage.
number CTakeDamageInfo:GetDamageCustom()
Gets the custom damage type. This is used by Day of Defeat: Source and Team Fortress 2 for extended damage info, but isn't used in Garry's Mod by default.
Vector CTakeDamageInfo:GetDamageForce()
Returns a vector representing the damage force.
Can be set with CTakeDamageInfo:SetDamageForce.
Vector CTakeDamageInfo:GetDamagePosition()
Returns the position where the damage was or is going to be applied to.
Can be set using CTakeDamageInfo:SetDamagePosition.
number CTakeDamageInfo:GetDamageType()
Returns a bitflag which indicates the damage type(s) of the damage.
Consider using CTakeDamageInfo:IsDamageType instead. Value returned by this function can contain multiple damage types.
Entity CTakeDamageInfo:GetInflictor()
Returns the inflictor of the damage. This is not necessarily a weapon.
For hitscan weapons this is the weapon.
For projectile weapons this is the projectile.
For a more reliable method of getting the weapon that damaged an entity, use CTakeDamageInfo:GetWeapon or GetAttacker with GetActiveWeapon.
number CTakeDamageInfo:GetMaxDamage()
Returns the maximum damage. See CTakeDamageInfo:SetMaxDamage
Vector CTakeDamageInfo:GetReportedPosition()
Returns the initial, unmodified position where the damage occured.
Returns the inflicting weapon of the damage event, if there is any.
This is not necessarily a Weapon entity, but it is very likely to be one.
See CTakeDamageInfo:GetInflictor for the actual entity that did the damage.
boolean CTakeDamageInfo:IsBulletDamage()
Returns true if the damage was caused by a bullet.
Returns whenever the damageinfo contains the damage type specified.
boolean CTakeDamageInfo:IsExplosionDamage()
Returns whenever the damageinfo contains explosion damage.
boolean CTakeDamageInfo:IsFallDamage()
Returns whenever the damageinfo contains fall damage.
CTakeDamageInfo:ScaleDamage( number scale )
Scales the damage by the given value.
CTakeDamageInfo:SetAmmoType( number ammoType )
Changes the ammo type used by the weapon that inflicted the damage.
CTakeDamageInfo:SetAttacker( Entity ent )
Sets the attacker ( character who originated the attack ) of the damage, for example a player or an NPC.
CTakeDamageInfo:SetBaseDamage( number )
Sets the initial unmodified by skill level ( game. GetSkillLevel ) damage. This function will not update or touch CTakeDamageInfo:GetDamage.
CTakeDamageInfo:SetDamageBonus( number damage )
Sets the bonus damage. Bonus damage isn't automatically applied, so this will have no outer effect by default.
CTakeDamageInfo:SetDamageCustom( number DamageType )
Sets the custom damage type. This is used by Day of Defeat: Source and Team Fortress 2 for extended damage info, but isn't used in Garry's Mod by default.
CTakeDamageInfo:SetDamageForce( Vector force )
Sets the directional force of the damage.
This function only affects entities using the VPHYSICS movetype. This means players and most NPCs won't receive the force vector you provide as knockback.
If the entity taking damage is using the WALK or STEP holdtypes, the damage force is instead automatically calculated. It will push the entity away from the inflictor's Entity:WorldSpaceCenter, scaling the push by a calculated value involving the total amount of damage and the size of the entity. Source
To disable knockback entirely, see EFL_NO_DAMAGE_FORCES or use the workaround example below.
CTakeDamageInfo:SetDamagePosition( Vector pos )
Sets the position of where the damage gets applied to.
CTakeDamageInfo:SetDamageType( number type )
Sets the damage type.
CTakeDamageInfo:SetInflictor( Entity inflictor )
Sets the inflictor of the damage for example a weapon.
For hitscan/bullet weapons this should the weapon.
For projectile (rocket launchers, grenades, etc) weapons this should be the projectile and CTakeDamageInfo:SetWeapon should be the weapon.
CTakeDamageInfo:SetMaxDamage( number maxDamage )
Sets the maximum damage this damage event can cause.
CTakeDamageInfo:SetReportedPosition( Vector pos )
Sets the origin of the damage.
Sets the damage-inflicting weapon of the damage event.
This should be a Weapon entity, not a projectile. See also CTakeDamageInfo:SetInflictor.
CTakeDamageInfo:SubtractDamage( number damage )
Subtracts the specified amount from the damage.