AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [TF2] Make every weapon headshot (https://forums.alliedmods.net/showthread.php?t=320471)

Mikusch 12-23-2019 14:06

[TF2] Make every weapon headshot
 
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 victimint &attackerint &inflictorfloat &damageint &damagetypeint &weaponfloat 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.

Scag 01-01-2020 20:34

Re: [TF2] Make every weapon headshot
 
Looking at this it appears you'll need to DHook CTFWeaponBase::CanFireCriticalShot. Including everything you still have under a TraceAttack hook.

Mikusch 01-02-2020 16:30

Re: [TF2] Make every weapon headshot
 
Quote:

Originally Posted by Ragenewb (Post 2678718)
Looking at this it appears you'll need to DHook CTFWeaponBase::CanFireCriticalShot. Including everything you still have under a TraceAttack hook.

It appears that this function only gets called for weapons that are actually capable of doing headshots (sniper rifles and the ambassador) and only gets called on a successful headshot, meaning it is kinda pointless.

The reason I can't use SDKHook_TraceAttack is that I can't modify the damagecustom attribute, and SDKHook_OnTakeDamage has no information about the hitgroup, meaning I can't differentiate between normal crits and my custom headshot crits.

Scag 01-02-2020 16:56

Re: [TF2] Make every weapon headshot
 
If you glanced at the link I posted you would be able to see that Valve code would have done all of the heavy lifting for you.

Even if you aren't that adept at reading C++ code, you can decipher that:
  • It's a TraceAttack function
  • CanFireCriticalShot is only fired if both the hitgroup == 1 (HITGROUP_HEAD) and damagetype & DMG_USE_HITLOCATIONS
  • If all of that stuff is true, it would both add the DMG_CRIT to the damagetype and set the custom to TF_CUSTOM_HEADSHOT

So in the end, you will need to use a TraceAttack hook and set the update the damagetype as you have it already.

sapphonie 10-05-2021 17:13

Re: [TF2] Make every weapon headshot
 
HTML Code:

public Action Client_TraceAttack (int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &ammotype, int hitbox, int hitgroup)
{

    // headbox
    if (hitgroup == 1)
    {
        damagetype |= (DMG_USE_HITLOCATIONS | TF_CUSTOM_HEADSHOT | DMG_CRIT);
    }
    return Plugin_Changed;
}


This works for me.

Psyk0tik 10-05-2021 18:52

Re: [TF2] Make every weapon headshot
 
Quote:

Originally Posted by sapphonie (Post 2759737)
HTML Code:

public Action Client_TraceAttack (int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &ammotype, int hitbox, int hitgroup)
{

    // headbox
    if (hitgroup == 1)
    {
        damagetype |= (DMG_USE_HITLOCATIONS | TF_CUSTOM_HEADSHOT | DMG_CRIT);
    }
    return Plugin_Changed;
}


This works for me.

You should only return Plugin_Changed inside that hitgroup check and Plugin_Continue for any other scenario.

sapphonie 10-07-2021 01:08

Re: [TF2] Make every weapon headshot
 
Actually I'm wrong here, TF_CUSTOM_HEADSHOT isn't a flag for damage, it's a flag for kills.

A working plugin would look something like this:


HTML Code:

public void OnPluginStart()
{
    // for lateloading
    for (int i = 1; i <= MaxClients; i++)
    {
        if (!IsValidClient(i))
        {
            continue;
        }
        OnClientPutInServer(i);
    }


}

public void OnClientPutInServer(int client)
{
    SDKHook(client, SDKHook_TraceAttack, OnTraceAttack);
}


public Action OnTraceAttack(int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &ammotype, int hitbox, int hitgroup)
{
    // headbox
    if (hitgroup == 1)
    {
        // always headshot if we hit the head
        damagetype |= (DMG_USE_HITLOCATIONS | DMG_CRIT);
        return Plugin_Changed;
    }
    return Plugin_Continue;
}



All times are GMT -4. The time now is 05:00.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.