AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Need a hook on secondary fire shotgun (https://forums.alliedmods.net/showthread.php?t=94879)

Afion 06-16-2009 18:56

Need a hook on secondary fire shotgun
 
I've been searching for something like this for ages. It's for the Vampire-Slayer mod. The secondary fire on fatherD's slot3 shotgun is way overpowered and considered very lame to use. This ofcourse doesn't stop ppl from doing so even when it's included in the server rules.

That's why I need a way to hook this so a punishment can be given. A way to block it or make it do a normal shot would even be better but I guess that's going to be extremely hard. A hook when doing damage with it would actually be enough. I know how to get one when doing damage with that shotgun but it makes not difference between primary or secondary fire.

I hope to find somebody with enough knowledge to help me :)

Bugsy 06-16-2009 22:05

Re: Need a hook on secondary fire shotgun
 
Here is one way you could do it. I made this example for usp but you can make it work with any gun by replacing the classname. There is a cvar [bsa_forceprimary] that if enabled [1] will force primary attack if secondary attack is clicked; when disabled the secondary attack will just be blocked.

With this method, when primary attack is forced you will not see the weapon animation when it occurs but it will still occur. Compile\install this code and use secondary attack with usp to see what I mean. Your ammo will go down with each attack but you will not see the weapon fire.

PHP Code:

#include <amxmodx>
#include <fakemeta>

#define m_pActiveItem 373

new g_pForcePrimaryAttack;

public 
plugin_init() 
{
    
register_plugin"Block\Hook Secondary Attack" "1.0" "bugsy" )
    
    
register_forwardFM_CmdStart "fw_FM_CmdStart" );
    
    
g_pForcePrimaryAttack register_cvar"bsa_forceprimary" "1" );
}

public 
fw_FM_CmdStartid Handle 
{
    static 
iButtonsiButtons get_ucHandle UC_Buttons );
    static 
iOldButtonsiOldButtons pevid pev_oldbuttons );
    static 
szWeaponClassName33 ];

    if ( ( 
iButtons IN_ATTACK2 ) && !( iOldButtons IN_ATTACK2 ) )
    {
        
pevget_pdata_cbaseid m_pActiveItem ) , pev_classname szWeaponClassName 32 );
        
        if ( 
equalszWeaponClassName "weapon_usp" ) )
        {
            if ( 
get_pcvar_numg_pForcePrimaryAttack ) )
                
iButtons |= IN_ATTACK;

            
set_ucHandle UC_Buttons iButtons & ~IN_ATTACK2 );

            
//Issue punishment here if desired.
        
}
    }



Afion 06-17-2009 10:53

Re: Need a hook on secondary fire shotgun
 
Thank you for the fast and helpful reply.

There are a few problems though.
This line doesn't work at all, so I had to change it to an engine version of it.
PHP Code:

pevget_pdata_cbaseid m_pActiveItem ) , pev_classname szWeaponClassName 32 );
//changed to
get_weaponnameget_user_weapon(id) , szWeaponClassName 32 ); 

And then i get this code
PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <engine>


new g_pForcePrimaryAttack;

public 
plugin_init() 
{

    
register_plugin"Block\Hook Secondary Attack" "1.0" "bugsy" )
    
    
register_forwardFM_CmdStart "fw_FM_CmdStart" );
    
    
g_pForcePrimaryAttack register_cvar"bsa_forceprimary" "0" );
}

public 
fw_FM_CmdStartid Handle 
{
    static 
iButtonsiButtons get_ucHandle UC_Buttons );
    static 
iOldButtonsiOldButtons pevid pev_oldbuttons );
    static 
szWeaponClassName33 ];
    
    if ( ( 
iButtons IN_ATTACK2 ) && !( iOldButtons IN_ATTACK2 ) )
    {
        
get_weaponnameget_user_weapon(id) , szWeaponClassName 32 );
        
        if ( 
equalszWeaponClassName "weapon_vsshotgun" ) )
        {
            if ( 
get_pcvar_numg_pForcePrimaryAttack ) )
                
iButtons |= IN_ATTACK;
            
            
set_ucHandle UC_Buttons iButtons & ~IN_ATTACK2 );
                
            
//client_print(id,print_center,"Fired %s", szWeaponClassName)
        
}
    }


Which works like you said, the secondary attack is a primary one with secondary sounds & animation BUT changing the cvar just makes it do a normal secondary attack and doesn't block it. I was thinking that if it could be blocked, i could call something like client_cmd(id, "+attack") and have a perfect primary fire.

It's very helpful anyway but having the ability to block it would be nice. Also, I do not understand these 2 lines:
PHP Code:

iButtons |= IN_ATTACK;
set_ucHandle UC_Buttons iButtons & ~IN_ATTACK2 ); 

An explanation on how this works might help me figure it out on my own (or use it for other things).

Bugsy 06-17-2009 21:41

Re: Need a hook on secondary fire shotgun
 
You cannot block the secondary-attack animation though the actual workings of the secondary attack are blocked. Try it with the usp, you will see the silencer being applied but it really doesn't get put on once the animation completes.

This line sets primary attack bits in the buttons bit-field if you have the cvar enabled for force primary attack. If you are unfamiliar with bit operators, do a quick google search and you will find plenty of reading material.
PHP Code:

if ( get_pcvar_numg_pForcePrimaryAttack ) )
        
iButtons |= IN_ATTACK

This updates the actual buttons issued to the game with our modified buttons value. With this line we are removing the secondary attack bits to make it not occur (& ~IN_ATTACK2). If you have the force-primary cvar enabled, the primary attack bits were set in the iButtons bit-field [above] so this will take care of both blocking secondary-attack and issue a primary attack.
PHP Code:

set_ucHandle UC_Buttons iButtons & ~IN_ATTACK2 ); 

Hope that helped.

ConnorMcLeod 06-18-2009 00:31

Re: Need a hook on secondary fire shotgun
 
Bugsy you used a cs offset, there's no 2nd attack on cs shotguns, i guess this is for HL.


All times are GMT -4. The time now is 15:37.

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