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

Solved SDK hook for when someone uses a weapon?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 09-26-2017 , 09:38   SDK hook for when someone uses a weapon?
Reply With Quote #1

Hi, is there a SDKHook for when a player is trying to shoot a weapon?
Is this something SDKHook_WeaponCanUse can do?

I want to block firing weapons, as long as the weapon is not a revolver.
__________________

Last edited by condolent; 09-27-2017 at 10:20.
condolent is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-26-2017 , 09:59   Re: SDK hook for when someone uses a weapon?
Reply With Quote #2

Yes there is. You not want try test all those sdkhook types...?
__________________
Do not Private Message @me
Bacardi is offline
Papero
Veteran Member
Join Date: Aug 2016
Location: Italy
Old 09-26-2017 , 12:05   Re: SDK hook for when someone uses a weapon?
Reply With Quote #3

Maybe use this: https://wiki.alliedmods.net/Counter-...ts#weapon_fire (without sdkhooks)
__________________
My Plugins
SPCode


Steam: hexer504
Telegram: Hexah
Discord: Hexah#6903

If you like my work you can donate here!
Papero is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-26-2017 , 12:09   Re: SDK hook for when someone uses a weapon?
Reply With Quote #4

Events are fire after action, so it's too late to block weapon shoot.

*edit
weapon restriction is good plugin example to examine.
__________________
Do not Private Message @me

Last edited by Bacardi; 09-26-2017 at 12:10.
Bacardi is offline
Papero
Veteran Member
Join Date: Aug 2016
Location: Italy
Old 09-26-2017 , 12:20   Re: SDK hook for when someone uses a weapon?
Reply With Quote #5

Quote:
Originally Posted by Bacardi View Post
Events are fire after action, so it's too late to block weapon shoot.

*edit
weapon restriction is good plugin example to examine.
Even with PreHook?
__________________
My Plugins
SPCode


Steam: hexer504
Telegram: Hexah
Discord: Hexah#6903

If you like my work you can donate here!
Papero is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 09-26-2017 , 12:53   Re: SDK hook for when someone uses a weapon?
Reply With Quote #6

Quote:
Originally Posted by Papero View Post
Even with PreHook?
yes, events are after action. Always late.


But there is not also SDKHook type what block shooting... then need block weapon switch or equip weapon else, etc. etc.

*edit
One way is block button. But player still see his weapon firing.
PHP Code:
public Action OnPlayerRunCmd(int clientint &buttonsint &impulsefloat vel[3], float angles[3], int &weaponint &subtypeint &cmdnumint &tickcountint &seedint mouse[2])
{

    if(
buttons IN_ATTACK
    {
        
buttons &= ~IN_ATTACK
        
return Plugin_Changed;
    }

    return 
Plugin_Continue;

__________________
Do not Private Message @me

Last edited by Bacardi; 09-26-2017 at 13:12.
Bacardi is offline
NgBUCKWANGS
Senior Member
Join Date: Dec 2014
Old 09-27-2017 , 06:00   Re: SDK hook for when someone uses a weapon?
Reply With Quote #7

I do the same thing Bacardi does, use OnPlayerRunCmd and in your case, you'll want to do something like this

PHP Code:
ent // entity of the weapon you want to block
SetEntPropFloat(entProp_Send"m_flNextPrimaryAttack"GetGameTime() + 1.0); 
In the example above, the ent is a primary weapon. If you're trying to block a secondary weapon, replace "m_flNextPrimaryAttack" with "m_flNextSecondaryAttack" to block secondary weapon attacks.

Let us know if it works. Good luck
NgBUCKWANGS is offline
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 09-27-2017 , 06:51   Re: SDK hook for when someone uses a weapon?
Reply With Quote #8

So in my plugin, the only thing the players have are decoys and one has a knife aswell. How can I then make it block throwing a decoy grenade? It's basically the only thing that I actually need to block out, the option to throw grenades
__________________
condolent is offline
NgBUCKWANGS
Senior Member
Join Date: Dec 2014
Old 09-27-2017 , 08:12   Re: SDK hook for when someone uses a weapon?
Reply With Quote #9

Quote:
Originally Posted by condolent View Post
So in my plugin, the only thing the players have are decoys and one has a knife aswell. How can I then make it block throwing a decoy grenade? It's basically the only thing that I actually need to block out, the option to throw grenades
I have no idea what you're doing but the code I posted above and Bacardi's code above that is all you should need to block people from using weapons. Instead of blocking individual weapons, maybe just block all but e.g.,

PHP Code:
if (weapon != "only_weapon_that_can_fire") {
    
// block weapon

NgBUCKWANGS is offline
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 09-27-2017 , 08:48   Re: SDK hook for when someone uses a weapon?
Reply With Quote #10

Quote:
Originally Posted by NgBUCKWANGS View Post
I have no idea what you're doing but the code I posted above and Bacardi's code above that is all you should need to block people from using weapons. Instead of blocking individual weapons, maybe just block all but e.g.,

PHP Code:
if (weapon != "only_weapon_that_can_fire") {
    
// block weapon

Bacardi's tip is probably the one that's most relevant in my case, then.
But yours is really good to know about! I keep learning alot with entprops and such and it has helped me in many ways recently!

I did this in the end:
PHP Code:
public Action OnPlayerRunCmd(int clientint &buttonsint &impulsefloat vel[3], float angles[3], int &weaponint &subtypeint &cmdnumint &tickcountint &seedint mouse[2]) { 
    
char sWeapon[64];
    
GetEntityClassname(weaponsWeaponsizeof(sWeapon));
    
    if(
buttons IN_ATTACK) {
        if(
StrEqual(sWeapon"weapon_decoy")) {
            
buttons &= ~IN_ATTACK;
            return 
Plugin_Handled
        }
    } 

    return 
Plugin_Continue

But since I'm at work currently I'm unable to test it. I will test it later today and update this post with the results!
__________________

Last edited by condolent; 09-27-2017 at 08:49.
condolent 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 10:43.


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