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

How to 'hook' when player uses heavy attack with knife


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
impossible_cc
Senior Member
Join Date: Sep 2018
Location: Ukraine
Old 06-24-2019 , 16:46   How to 'hook' when player uses heavy attack with knife
Reply With Quote #1

csgo.
Is there any way to catch when player attacks heavily (right-click) with knife.
weapon_fire event triggers only for left-click attacks.

Also second question, is it possible to 'force' player to use heavy attack. I tried to modify that in OnPlayerRunCmd:

PHP Code:
buttons &= ~IN_ATTACK;
buttons &= IN_ATTACK2
but it doesnt work.
__________________

Last edited by impossible_cc; 06-24-2019 at 16:48.
impossible_cc is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 06-24-2019 , 17:27   Re: How to 'hook' when player uses heavy attack with knife
Reply With Quote #2

Something like this should work to force a player to secondary attack with the knife:
PHP Code:
public OnClientPutInServer(client)
{
    
SDKHook(clientSDKHook_PostThinkPostOnPostThinkPost);
}

public 
OnPostThinkPost(client)
{
    new 
knife GetPlayerWeaponSlot(clientCS_SLOT_KNIFE);

    if(
IsValidEntity(knife))
        
SetEntPropFloat(knifeProp_Send"m_flNextPrimaryAttack", (GetGameTime() + 9999.9));

Seeing if the player is using secondary attack with a knife on a damage hook can be done by checking the damage amount.

PHP Code:
public OnClientPutInServer(client)
{
    
SDKHook(clientSDKHook_OnTakeDamageOnTakeDamage);
}

public 
Action OnTakeDamage(int victimint &attackerint &inflictorfloat &damageint &damagetype)
{
    if(!
IsValidClient(attacker))
        return 
Plugin_Continue;
        
    if (
damage 55.0)
    {
        new 
weaponEnt GetEntDataEnt2(attackeractiveOffset);
        if(
IsValidEdict(weaponEnt) && IsValidEntity(weaponEnt))
        {
            
decl String:className[128];
            
GetEntityClassname(weaponEntclassNamesizeof(className));
            
            if(
StrEqual("weapon_knife"className))
            {
                
//secondary attack with knife used
                
return Plugin_Changed;
            }
        }
    }
    return 
Plugin_Continue;

__________________
I highly recommend joining the SourceMod Discord Server for real time support.
backwards is offline
impossible_cc
Senior Member
Join Date: Sep 2018
Location: Ukraine
Old 06-24-2019 , 19:11   Re: How to 'hook' when player uses heavy attack with knife
Reply With Quote #3

Sorry for my English, but that is not what I want.
'Force player to use heavy attack' means force to do that right now, but not just to forbid primary attack. So I want to make player to do secondary attack at any moment
( I tried to do the thing above with OnPlayerRunCmd with setting m_flNextSecondaryAttack to GetGameTime() )
About hook
I want some hook, that would work when player uses secondary attack with knife, no matter if it deals any damage or not (like weapon_fire, but it works only for primary attacks)
__________________
impossible_cc 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 22:27.


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