Raised This Month: $32 Target: $400
 8% 

[CS:S] Hooking Secondary Knife Attack


Post New Thread Reply   
 
Thread Tools Display Modes
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 05-13-2018 , 18:27   Re: [CS:S] Hooking Secondary Knife Attack
Reply With Quote #11

Quote:
Originally Posted by BraveFox View Post
Use SDKHook_OnTakeDamage and add this to your part after you check if the weapon is a knife:
Code:
if (damagetype & DMG_SLASH)
{}
__________________
Neuro Toxin is offline
Komodo3000
Junior Member
Join Date: Sep 2017
Old 05-17-2018 , 09:49   Re: [CS:S] Hooking Secondary Knife Attack
Reply With Quote #12

Again, thank you for your replies.
I have been testing your suggestions the last few days...

Quote:
Originally Posted by MasterMind420 View Post
I think the most accurate method may be checking the animation sequence using m_nsequence entprop
I guess you mean checking it each GameFrame. That would theoretically work, but the interval between GameFrames is too long --> too inaccurate



Quote:
Originally Posted by Neuro Toxin View Post
Use SDKHook_OnTakeDamage and add this to your part after you check if the weapon is a knife:
Code:
if (damagetype & DMG_SLASH)
{}
I need it to work every time an attack is performed, whether someone was hurt by it or not.



Quote:
Originally Posted by Lux View Post
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.




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
To me it doesn't really matter which knife attack is performed because i need it to work for primary and secondary, but since primary attack fires the "weapon_fire" event, it is only the secondary attack that is causing problems.
I tried that method and until now it is by far the best one, but when i compared it to "weapon_fire" event it has a small but significant delay:
CODE:
PHP Code:
public Action:NormalSoundHook(clients[64], &numClientsString:sample[PLATFORM_MAX_PATH], &entity, &channel, &Float:volume, &level, &pitch, &flags)
{
    
decl String:sKnife[32];
    
sKnife "weapons/knife/knife_";
    
    
decl String:sDeploy[32];
    
sDeploy "weapons/knife/knife_deploy1.wav";

    if(
StrContains(samplesKnifefalse) == && !StrEqual(samplesDeployfalse))
    {
        
PrintToChatAll("[SoundHook] Knife-Attack | Time %f",  GetEngineTime());
    }
    return 
Plugin_Continue;
}

public 
EventWeaponFire(Handle:event,const String:name[],bool:dontBroadcast)
{
    static 
String:Weapon[32];
    
GetEventString(event"weapon"Weaponsizeof(Weapon));
    if(
StrEqual(Weapon"knife"))
    {
        
PrintToChatAll("[WeaponFire] Knife-Attack | Time %f"GetEngineTime());
    }

Tested with primary attack (3 times) since it also triggers "weapon_fire" event!
OUTPUT:
PHP Code:
[WeaponFireKnife-Attack Time 125.506652
[SoundHookKnife-Attack Time 125.506698

[WeaponFireKnife-Attack Time 125.911811
[SoundHookKnife-Attack Time 125.911842

[WeaponFireKnife-Attack Time 126.331619
[SoundHookKnife-Attack Time 126.331657 
It needs to have the same accuracy as "weapon_fire" otherwise it won't work for me.
__________________

Last edited by Komodo3000; 05-17-2018 at 09:51.
Komodo3000 is offline
xerox8521
Senior Member
Join Date: Sep 2011
Old 05-17-2018 , 10:02   Re: [CS:S] Hooking Secondary Knife Attack
Reply With Quote #13

You could just hook CKnife::SecondaryAttack (or actually CBaseCombatWeapon but it shouldn't really matter) using DHooks and then hook the knife entity (OnEntityCreated).

Current offsets: 275 for Linux and 274 for Windows. Use this site to get the offsets.

Last edited by xerox8521; 05-17-2018 at 10:03. Reason: Added link to dhooks
xerox8521 is offline
Lux
Veteran Member
Join Date: Jan 2015
Location: Cat
Old 06-18-2018 , 08:43   Re: [CS:S] Hooking Secondary Knife Attack
Reply With Quote #14

Quote:
Originally Posted by Komodo3000 View Post

Tested with primary attack (3 times) since it also triggers "weapon_fire" event!
OUTPUT:
PHP Code:
[WeaponFireKnife-Attack Time 125.506652
[SoundHookKnife-Attack Time 125.506698

[WeaponFireKnife-Attack Time 125.911811
[SoundHookKnife-Attack Time 125.911842

[WeaponFireKnife-Attack Time 126.331619
[SoundHookKnife-Attack Time 126.331657 
It needs to have the same accuracy as "weapon_fire" otherwise it won't work for me.
That is less than 1ms i don't think you will get any better, and that is very near weapon fire, even if you used dhooks you will see variance time variance between weapon fire
__________________
Connect
My Plugins: KlickME
[My GitHub]

Commission me for L4D
Lux is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 06-19-2018 , 13:36   Re: [CS:S] Hooking Secondary Knife Attack
Reply With Quote #15

Try this on SDKHook_TraceAttack:

https://sm.alliedmods.net/new-api/en...tClientButtons
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
Reply



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 13:14.


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