Skip to content

Instantly share code, notes, and snippets.

@nosoop
Last active January 1, 2024 01:35
Show Gist options
  • Save nosoop/84575380e148a222f2cf52ae0f2c234c to your computer and use it in GitHub Desktop.
Save nosoop/84575380e148a222f2cf52ae0f2c234c to your computer and use it in GitHub Desktop.

TF2's player damage process

note: documentation is released as-is and reports of any inaccuracies will be ignored

Call tree:

  • CTFPlayer::ModifyDamageInfo
  • CTFPlayer::OnTakeDamage
    • If attacker is carrying RUNE_STRENGTH, scale damage by 2.0f.
    • CTFGameRules::ApplyOnDamageModifyRules
      • CTFWeaponBase::ApplyOnHitAttributes
    • If phasing: CTFPlayer::ApplyPushFromDamage
    • Otherwise: CBaseCombatCharacter::OnTakeDamage (bypasses override on CBasePlayer)
      • If lifestate is alive: CTFPlayer::OnTakeDamage_Alive
        • CTFGameRules::ApplyOnDamageAliveModifyRules
        • CTFPlayer::ApplyPushFromDamage
    • CTFWeaponBase::ApplyOnInjuredAttributes on victim's weapon
    • CTFWeaponBase::ApplyPostHitEffects on attacker's weapon
    • CTFPlayer::OnDealtDamage on attacker

Function information

CTFPlayer::ModifyDamageInfo

  • Called before damage is applied.
  • Only used for scaling damage against sentry targets (8185700)

CTFGameRules::ApplyOnDamageModifyRules

  • Applies minicrit / critical alterations.
  • Applies distance rampup / falloff modifiers.
  • Applies (mini)crit damage modifiers.

CTFGameRules::ApplyOnDamageAliveModifyRules

  • The return value controls the actual damage taken. This allows for modifying the result independently of any damage forces.
  • However, Mad Milk effects still perform healing based on the original damage.
    • It sounds like you should be able to preserve the damage force by using m_flDamageForForce, but it doesn't appear to work in practice.
  • A return value of -1.0f indicates a "hard out", which bypasses additional damage effects in CTFPlayer::OnTakeDamage_Alive.

CTFWeaponBase::ApplyOnHitAttributes

  • This does not get called if the target is invulnerable. Target may be a non-player entity.
  • Attribute classes that are applied here:
    • add_onhit_addammo
    • extra_damage_on_hit
    • (Attributes past this point are only applied to player enemies and halloween bosses.)
    • reveal_cloaked_victim_on_hit
    • reveal_disguised_victim_on_hit
    • (Attributes past this point are not applied if the target is disguised or from burn damage.)
    • add_onhit_addhealth
    • charge_meter_on_hit
    • speed_boost_on_hit
    • add_onhit_ubercharge
    • rage_on_hit
    • boost_on_damage
    • aoe_heal_chance
    • crits_on_damage
    • stun_on_damage
    • aoe_blast_on_damage
    • generate_rage_on_dmg
    • mult_onhit_enemyspeed
    • mult_onhit_enemyspeed_major
    • mark_for_death
    • stun_waist_high_airborne

CTFWeaponBase::ApplyOnInjuredAttributes

  • Called on a victim's active weapon; damage must be applied by a player.
  • Currently used for the following attribute classes:
    • melts_in_fire (only applicable to Knife-based items)
    • become_fireproof_on_hit_by_fire (applicable to all weapons)

CTFWeaponBase::ApplyPostHitEffects

  • Called on an attacker's weapon when damage has been applied to another player.
  • Used for the following attribute classes:
    • scattergun_knockback_mult (only applicable to Scatterguns with the ability to inflict knockback)
    • For all weapons:
      • subtract_victim_medigun_charge_onhit
      • subtract_victim_cloak_on_hit

CTFPlayer::OnDealtDamage

  • Called on the attacker when damage was applied. Victim can be any entity; not just players.
  • This is only used for DPS statistics tracking.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment