#include "cbase.h"
#include "tf_gamerules.h"
#include "tf_weapon_knife.h"
#include "decals.h"

#ifdef CLIENT_DLL
#include "c_tf_player.h"
#else
#include "tf_player.h"
#include "tf_gamestats.h"
#endif

IMPLEMENT_NETWORKCLASS_ALIASED(TFKnife, DT_TFWeaponKnife)

BEGIN_NETWORK_TABLE(CTFKnife, DT_TFWeaponKnife)
END_NETWORK_TABLE()

BEGIN_PREDICTION_DATA(CTFKnife)
END_PREDICTION_DATA()

LINK_ENTITY_TO_CLASS(tf_weapon_knife, CTFKnife);
PRECACHE_WEAPON_REGISTER(tf_weapon_knife);

CTFKnife::CTFKnife()
{
}

void CTFKnife::PrimaryAttack(void)
{
    CTFPlayer *pPlayer = ToTFPlayer(GetPlayerOwner());
    
    if (!CanAttack())
        return;
    
    m_iWeaponMode = TF_WEAPON_PRIMARY_MODE;
    
    trace_t trace;
    if (DoSwingTrace(trace) == true)
    {
        if (trace.m_pEnt && trace.m_pEnt->IsPlayer())
        {
            CTFPlayer *pTarget = ToTFPlayer(trace.m_pEnt);
            
            if (pTarget && pTarget->GetTeamNumber() != pPlayer->GetTeamNumber())
            {
                if (IsBehindTarget(trace.m_pEnt))
                {
                    m_iWeaponMode = TF_WEAPON_SECONDARY_MODE;
                    
                    m_hBackstabVictim = trace.m_pEnt;
                }
            }
        }
    }
    
#ifndef CLIENT_DLL
    pPlayer->RemoveInvisibility();
    pPlayer->RemoveDisguise();
#endif

    Swing(pPlayer);
    
#if !defined(CLIENT_DLL)
    pPlayer->SpeakWeaponFire();
    CTF_GameStats.Event_PlayerFiredWeaponed(pPlayer, IsCurrentAttackACritial());
#endif
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: