I'm trying to allow all bullet-based weapons in TF2 to do headshots with the same method that sniper rifles, bows and the revolver hitlocation attribute use. Quite a bit of searching and the source code for CTFSniperRifle::GetDamageType and CTFProjectile_Arrow::GetDamageType lead me to believe that OR-ing in the DMG_USE_HITLOCATIONS damagebit would do the trick but of course I was wrong. The damagetype changed but the game still doesn't use hit location damage.
I simply can't figure out how to get this to work. The bits get modified but the weapon won't headshot. Tested with SMG, Pistol and Minigun.
PHP Code:
public Action Client_OnTakeDamage(int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &weapon, float damageForce[3], float damagePosition[3], int damagecustom)
{
if (damagetype & DMG_BULLET)
{
damagetype |= DMG_USE_HITLOCATIONS;
return Plugin_Changed;
}
return Plugin_Continue;
}
The above function is hooked to all clients.
Yes, I am aware that SDKHook_TraceAttack and the head hitgroup exists, however this comes with its own quirks and I'd rather use TF2's built in hitlocation damage.