Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TF2] damage_for_force_calc in OnTakeDamage is broken #6056

Open
doclic opened this issue Jun 7, 2024 · 2 comments · May be fixed by ValveSoftware/source-sdk-2013#966
Open

[TF2] damage_for_force_calc in OnTakeDamage is broken #6056

doclic opened this issue Jun 7, 2024 · 2 comments · May be fixed by ValveSoftware/source-sdk-2013#966

Comments

@doclic
Copy link

doclic commented Jun 7, 2024

The following vscript should, when executed, make all damage knock players back as if they took only one point of damage:

function
OnScriptHook_OnTakeDamage(params)
{
	params.damage_for_force_calc = 1.0;
}

__CollectGameEventCallbacks(this);

This however doesn't happen, damage force is still calculated normally, using params.damage.

@doclic
Copy link
Author

doclic commented Jun 7, 2024

After doing a bit of digging, it seems that in CBaseEntity::TakeDamage, damage_for_force_calc is set before calling the hook, and it's retrieved after, but the retrieved value is not used anywhere.

Edit:
I spent a bit more time on reversing, and the CTakeDamageInfo passed to CBaseEntity::OnTakeDamage has m_flDamageForForce properly set:
image
I wanted to try hooking to OnTakeDamage via a SourceMod plugin instead of a VScript, but SourceMod doesn't expose m_flDamageForForce.

While reverse-engineering, I've also found that damage_custom is effectively useless, reported in #4481.

@doclic
Copy link
Author

doclic commented Feb 25, 2025

Using the updated source-sdk-2013, I found that the problem comes from CTFGameRules::ApplyOnDamageModifyRules in game/shared/tf/tf_gamerules.cpp which starts with this line:

	info.SetDamageForForceCalc( info.GetDamage() );

which resets the damage for force calc value to the regular damage value.
Removing this line fixes the issue, and doesn't seem to break anything else. (Edit: this is wrong and I am stupid)
Only running this code if the damage for force calc is set to 0 (meaning it wasn't overridden by a mod), fixes this.

doclic added a commit to doclic/source-sdk-2013 that referenced this issue Mar 8, 2025
doclic added a commit to doclic/source-sdk-2013 that referenced this issue Mar 8, 2025
doclic added a commit to doclic/source-sdk-2013 that referenced this issue Mar 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants