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

Blocking specific weapon from firing


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
IceCucumber
Member
Join Date: Dec 2011
Old 04-26-2014 , 09:11   Blocking specific weapon from firing
Reply With Quote #1

Hey. Newbie question inbound: how would I go about blocking a certain weapon, say, weapon_ak47, from firing?

What I have so far:
Code:
public OnPluginStart()
{
    HookEvent("player_shoot", Event_Shot_Fired, EventHookMode_Pre);
}

public Action:Event_Shot_Fired(Handle:event, const String:name[], bool:dontBroadcast)
{
    if ( // weapon is weapon_ak47 )
    {
        return Plugin_Handled
    }
    return Plugin_Continue
}
Also, would something like hooking player_shoot be considered too expensive to use like this, as it does tend to happen quite a lot? I assume not...
IceCucumber is offline
Oshizu
Veteran Member
Join Date: Nov 2012
Location: Warsaw
Old 04-26-2014 , 11:05   Re: Blocking specific weapon from firing
Reply With Quote #2

Events in most cases are only indicators of something that happend
example: player_hurt, player_death, round_start
So you can't stop those things from happening by blocking events

You might have some luck with SDKTools thought

Edit: Here's the code
PHP Code:
#include <sdktools>

public Action:OnPlayerRunCmd(client, &buttons, &impulseFloat:vel[3], Float:angles[3], &weapon, &subtype, &cmdnum, &tickcount, &seedmouse[2])
{
    if(
buttons IN_ATTACK)
    {
        if(
IsClientInGame(client) && IsPlayerAlive(client))
        {
            new 
activewep GetEntPropEnt(clientProp_Send"m_hActiveWeapon");
            
            
decl String:classname[64];
            
GetEntityClassname(activewepclassnamesizeof(classname));
            if(
StrEqual(classname"weapon_ak47"))
            {
                
buttons &= ~IN_ATTACK;
                return 
Plugin_Changed;
            }
        }
    }
    return 
Plugin_Continue;

It should work, i guess?
__________________
...

Last edited by Oshizu; 04-26-2014 at 11:15.
Oshizu is offline
IceCucumber
Member
Join Date: Dec 2011
Old 04-26-2014 , 13:00   Re: Blocking specific weapon from firing
Reply With Quote #3

Quote:
Originally Posted by Oshizu View Post
Events in most cases are only indicators of something that happend
example: player_hurt, player_death, round_start
So you can't stop those things from happening by blocking events
Really? After reading the wiki, I was under the assumption that EventHookMode_Pre was handled before actually passing the event: https://wiki.alliedmods.net/Events_%...locking_Events

Thanks for the code, I'll give it a shot later tonight.

Last edited by IceCucumber; 04-26-2014 at 13:04. Reason: fixed the url
IceCucumber is offline
Oshizu
Veteran Member
Join Date: Nov 2012
Location: Warsaw
Old 04-26-2014 , 13:01   Re: Blocking specific weapon from firing
Reply With Quote #4

Quote:
Originally Posted by IceCucumber View Post
Really? After reading the wiki, I was under the assumption that EventHookMode_Pre was handled before actually passing the event: https://wiki.alliedmods.net/Events_%28SourceMod_Scripting%29#Blocking_Eve nts

Thanks for the code, I'll give it a shot later tonight.
Yeah, it's handled before passing the event
But the problem is that event is only notification created to inform client
example: player_death shows killicons etc.
If you block it from happening it wont show killicons but player will die anyway
__________________
...
Oshizu is offline
IceCucumber
Member
Join Date: Dec 2011
Old 04-26-2014 , 13:44   Re: Blocking specific weapon from firing
Reply With Quote #5

I see. Well, your code did indeed work, however the firing animation, kickback, bullet holes, firing sounds etc. still happen, which is confusing. Oh well, back to tinkering. Thanks!
IceCucumber is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 04-26-2014 , 13:45   Re: Blocking specific weapon from firing
Reply With Quote #6

That's due to client prediction. There's not much you can do about that.
bl4nk is offline
RedSword
SourceMod Plugin Approver
Join Date: Mar 2006
Location: Quebec, Canada
Old 04-26-2014 , 13:47   Re: Blocking specific weapon from firing
Reply With Quote #7

They are happening because the client side predict stuff. A normal game would be really laggy otherwise if you were to wait for the server to approve every action.
__________________
My plugins :
Red Maze
Afk Bomb
RAWR (per player/rounds Awp Restrict.)
Kill Assist
Be Medic

You can also Donate if you appreciate my work
RedSword 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 09:49.


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