View Single Post
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 05-10-2018 , 14:07   Re: [CS:S] Hooking Secondary Knife Attack
Reply With Quote #4

Maybe something like this if the sound hook isn't a reliable method.

PHP Code:
#include <sourcemod>
#include <sdktools>

new g_offsNextSecondaryAttackg_offsTimeWeaponIdle;

public 
OnPluginStart()
{
    
g_offsNextSecondaryAttack FindSendPropOffs("CBaseCombatWeapon""m_flNextSecondaryAttack");
    
g_offsTimeWeaponIdle FindSendPropOffs("CBaseCombatWeapon""m_flTimeWeaponIdle");
}

public 
Action:OnPlayerRunCmd(client, &buttons
{
    if(
IsValidClient(client))
    {
        new 
weapon GetEntPropEnt(clientProp_Send"m_hActiveWeapon");
        if (
weapon != -1)
        {
            new 
knife_weapon GetPlayerWeaponSlot(client2);
            if(
knife_weapon != -1)
            {
                if(
knife_weapon == weapon &&
                
buttons IN_ATTACK2
                
&& GetEntDataFloat(weapong_offsNextSecondaryAttack) <= GetGameTime()
                )
//&& GetEntDataFloat(weapon, g_offsTimeWeaponIdle) >= GetGameTime()) 
                
{
                    
PrintToChat(client"Second Attack %f %f"GetEntDataFloat(weapong_offsNextSecondaryAttack), GetEntDataFloat(weapong_offsTimeWeaponIdle));
                }
            }
        }
    }

    return 
Plugin_Continue


bool IsValidClient(int client)
{
    if (!(
<= client <= MaxClients) || !IsClientInGame(client) || IsClientSourceTV(client) || IsClientReplay(client))
        return 
false;

    return 
true;

Note: I'm not sure what m_flTimeWeaponIdle exactly for as it doesn't seem to behave as i originally assumed.
You have to account for weapon draw time and primary attack cool down times as well but this should get you in the right direction.
__________________
I highly recommend joining the SourceMod Discord Server for real time support.
backwards is offline