Raised This Month: $12 Target: $400
 3% 

[CS:S] Hooking Secondary Knife Attack


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Komodo3000
Junior Member
Join Date: Sep 2017
Old 05-10-2018 , 00:11   [CS:S] Hooking Secondary Knife Attack
Reply With Quote #1

Is there a way to hook secondary knife attack in CS:S?

The 'weapon_fire' event is not fired by secondary attack:
PHP Code:
HookEvent("weapon_fire"EventWeaponFireEventHookMode_Post); 
PHP Code:
public EventWeaponFire(Handle:event,const String:name[],bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    static 
String:Weapon[32];
    
GetEventString(event"weapon"Weaponsizeof(Weapon));
    if(
StrEqual(Weapon"knife"))
    {
        
//Code
    
}

I also tried using
PHP Code:
AddCommandListener(SecondaryAttack"+attack2"
or
PHP Code:
public Action:OnPlayerRunCmd(client, &buttons)
{
    if(
buttons IN_ATTACK2)
    {
        
//Code
    
}
    return 
Plugin_Continue;

but they keep getting called as long as "+attack2" button is pushed and not when the actual attack is performed.
I also need it to work, every time secondary attack is performed and not only when someone is hurt/hit by it, so 'player_hurt' event and 'SDKHook_TraceAttack' is not an option.
__________________
Komodo3000 is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 05-10-2018 , 11:01   Re: [CS:S] Hooking Secondary Knife Attack
Reply With Quote #2

Quote:
Originally Posted by Komodo3000 View Post
Is there a way to hook secondary knife attack in CS:S?

The 'weapon_fire' event is not fired by secondary attack:
PHP Code:
HookEvent("weapon_fire"EventWeaponFireEventHookMode_Post); 
PHP Code:
public EventWeaponFire(Handle:event,const String:name[],bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    static 
String:Weapon[32];
    
GetEventString(event"weapon"Weaponsizeof(Weapon));
    if(
StrEqual(Weapon"knife"))
    {
        
//Code
    
}

I also tried using
PHP Code:
AddCommandListener(SecondaryAttack"+attack2"
or
PHP Code:
public Action:OnPlayerRunCmd(client, &buttons)
{
    if(
buttons IN_ATTACK2)
    {
        
//Code
    
}
    return 
Plugin_Continue;

but they keep getting called as long as "+attack2" button is pushed and not when the actual attack is performed.
I also need it to work, every time secondary attack is performed and not only when someone is hurt/hit by it, so 'player_hurt' event and 'SDKHook_TraceAttack' is not an option.
Use a timer....time exactly when u press attack2. So if it happens 0.3 seconds or whatever after u press the button
MasterMind420 is offline
Lux
Veteran Member
Join Date: Jan 2015
Location: Cat
Old 05-10-2018 , 13:51   Re: [CS:S] Hooking Secondary Knife Attack
Reply With Quote #3

sound hook should work?
https://sm.alliedmods.net/api/index....d=show&id=787&

Only ever tried to mod CSS for viewmodel legs never messed with anything else
__________________
Connect
My Plugins: KlickME
[My GitHub]

Commission me for L4D
Lux is offline
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
Komodo3000
Junior Member
Join Date: Sep 2017
Old 05-10-2018 , 14:18   Re: [CS:S] Hooking Secondary Knife Attack
Reply With Quote #5

Thanks for your fast replies...

@MasterMind420
Quote:
Originally Posted by MasterMind420 View Post
Use a timer....time exactly when u press attack2. So if it happens 0.3 seconds or whatever after u press the button
I already tried that but soon encountered a problem:
When trying to figure out the exact interval betweet two secondary knife attacks using this code:

PHP Code:
public OnClientAuthorized(client)
{
    
SDKHook(clientSDKHook_TraceAttackOnTraceAttack);
}

public 
Action:OnTraceAttack(victim, &attacker, &inflictor, &Float:damage, &damagetype, &ammotypehitboxhitgroup)
{
    
decl String:Weapon[32];            
    
GetClientWeapon(attackerWeaponsizeof(Weapon));
    if(
StrEqual(Weapon[7], "knife"false))
    {
        
PrintToChat(attacker"Attacked with Knife | Time: %f"GetEngineTime());
    }
    return 
Plugin_Continue;

the output is the following.:
PHP Code:
Attacked with Knife Time549.686523
Attacked with Knife 
Time550.781555
Attacked with Knife 
Time551.906555
Attacked with Knife 
Time553.001525
Attacked with Knife 
Time554.111572
Attacked with Knife 
Time555.446594
Attacked with Knife 
Time556.556518 
As you can see the interval is not constant, it varies from '1.09497' to '1.335022'. Using this method is too inaccurate for me.


@Lux
Quote:
Originally Posted by Lux View Post
sound hook should work?
https://sm.alliedmods.net/api/index....d=show&id=787&

Only ever tried to mod CSS for viewmodel legs never messed with anything else
You mean hooking the swing sound of knife attack? That actually would be possible but i never used this method. Where do i get the path of the swing sound?
__________________

Last edited by Komodo3000; 05-10-2018 at 14:20.
Komodo3000 is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 05-10-2018 , 22:56   Re: [CS:S] Hooking Secondary Knife Attack
Reply With Quote #6

you can use "soundlist" command to print all precached sounds in console. There's a few issues with this though, i think the same sound plays for left click stabs as well as right click. There's also probably a lot of specific knife sounds for when you hit materials like metal or flesh that play which aren't specific to being a knife but is equal to a bullet impact sound. The sounds i found are "weapons\knife\knife_hitwall1.wav" and "weapons\knife\knife_stab.wav" for example.
__________________
I highly recommend joining the SourceMod Discord Server for real time support.
backwards is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 05-11-2018 , 03:25   Re: [CS:S] Hooking Secondary Knife Attack
Reply With Quote #7

PHP Code:
public Action OnPlayerRunCmd(int clientintbuttons)
{
    
int pressedButtons GetEntProp(clientProp_Data"m_afButtonPressed");
    if(
pressedButtons IN_ATTACK2)
    { 
        
//Code 
    
}

    return 
Plugin_Continue;

This would tell you when +attack2 was initially pressed. The prop exists in CS:GO, you'll have to check if it exists in CS:S. If not you can always just keep track of last buttons to find out when the button is pressed.

EDIT: After thinking about it this might not be the most accurate method since clicking the button might not always correspond to the secondary attack happening, might need a different method.

Last edited by hmmmmm; 05-11-2018 at 03:29.
hmmmmm is offline
MasterMind420
BANNED
Join Date: Nov 2010
Old 05-11-2018 , 13:40   Re: [CS:S] Hooking Secondary Knife Attack
Reply With Quote #8

I think the most accurate method may be checking the animation sequence using m_nsequence entprop
MasterMind420 is offline
Lux
Veteran Member
Join Date: Jan 2015
Location: Cat
Old 05-11-2018 , 23:47   Re: [CS:S] Hooking Secondary Knife Attack
Reply With Quote #9

Quote:
Originally Posted by hmmmmm View Post
PHP Code:
public Action OnPlayerRunCmd(int clientintbuttons)
{
    
int pressedButtons GetEntProp(clientProp_Data"m_afButtonPressed");
    if(
pressedButtons IN_ATTACK2)
    { 
        
//Code 
    
}

    return 
Plugin_Continue;

This would tell you when +attack2 was initially pressed. The prop exists in CS:GO, you'll have to check if it exists in CS:S. If not you can always just keep track of last buttons to find out when the button is pressed.

EDIT: After thinking about it this might not be the most accurate method since clicking the button might not always correspond to the secondary attack happening, might need a different method.

This might be a longshot but.

Is the button press in the same gameframe of the sound being emitted?

if so we can use the button press to determine which attack is being performed?
example in my own way

[Framestart]
OnPlayerRunCmd
Source Processing buttons
Starts attack
SoundHook checks
SoundEmitted

[frameend]

it maywork.

Quote:
Originally Posted by Komodo3000 View Post
@Lux

You mean hooking the swing sound of knife attack? That actually would be possible but i never used this method. Where do i get the path of the swing sound?

Its in old syntax sorry i prefer it.
PHP Code:
public OnPluginStart()
{
    
AddNormalSoundHook(SoundHook);
}

public 
Action:SoundHook(iClients[64], &iNumClientsString:sSampleFile[PLATFORM_MAX_PATH], &iEntity, &iChannel, &Float:fVolume, &fLevel, &iPitch, &iFlags)
{
    
//checks for sounds
    //Note besure to optimize heavily this will forward all sounds that are emitted!
    //like storing ent refs of already checked entitys that are not knife or client
    

I'm not a css coder so its just a shot in the dark of how i would go about doing it in l4d2 hope this helps
__________________
Connect
My Plugins: KlickME
[My GitHub]

Commission me for L4D
Lux is offline
BraveFox
AlliedModders Donor
Join Date: May 2015
Location: Israel
Old 05-12-2018 , 04:18   Re: [CS:S] Hooking Secondary Knife Attack
Reply With Quote #10

Use SDKHook_OnTakeDamage and add this to your part after you check if the weapon is a knife:
Quote:
if (damage == 65 || damage == 180)
{
//Attack2
}
__________________
Contact Me:
Steam: NoyB
Discord: Noy#9999
Taking Private Requests
BraveFox is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:33.


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