Raised This Month: $ Target: $400
 0% 

[SNIPPET] Block Keys


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
zipcore
Veteran Member
Join Date: Mar 2010
Location: m_flZipcore
Old 11-18-2012 , 09:45   [SNIPPET] Block Keys
Reply With Quote #1

If anybody has improvents please tell me.

PHP Code:
#include <sourcemod>
#include <sdktools>

enum keys
{
    
KEY_IN_ALT1 0,
    
KEY_IN_ALT2,
    
KEY_IN_ATTACK,
    
KEY_IN_ATTACK2,
    
KEY_IN_BACK,
    
KEY_IN_BULLRUSH,
    
KEY_IN_CANCEL,
    
KEY_IN_DUCK,
    
KEY_IN_FORWARD,
    
KEY_IN_GRENADE1,
    
KEY_IN_GRENADE2,
    
KEY_IN_JUMP,
    
KEY_IN_LEFT,
    
KEY_IN_MOVELEFT,
    
KEY_IN_MOVERIGHT,
    
KEY_IN_RELOAD,
    
KEY_IN_RIGHT,
    
KEY_IN_RUN,
    
KEY_IN_SCORE,
    
KEY_IN_SPEED,
    
KEY_IN_USE,
    
KEY_IN_WALK,
    
KEY_IN_WEAPON1,
    
KEY_IN_WEAPON2,
    
KEY_IN_ZOOM //24
}

new 
bool:Blocked_Keys[32];

public 
Plugin:myinfo =
{
    
name "KeyBlock",
    
author "ZipcoreQQ",
    
description "type sm_keyblock KEY to lock keys, unlock by typing sm_removekeyblock KEY",
    
version "1.0",
    
url "zipcore#googlmail.com"
}

public 
OnPluginStart()
{
    
RegAdminCmd("sm_removekeyblock"Command_BlockADMFLAG_ROOT);
    
RegAdminCmd("sm_keyblock"Command_RemoveBlockADMFLAG_ROOT);
    
RegAdminCmd("sm_keylist"Command_KeyListADMFLAG_ROOT);
}

public 
OnMapStart()
{
    for(new 
i=0;i<=sizeof(Blocked_Keys);i++)
    {
        
Blocked_Keys[i] = false;
    }
}

public 
Action:Command_Block(client,args)
{
    new 
String:blockkey[32];
    new 
bool:changed false;
    
    if (
args 0)
    {
        
GetCmdArg(1,blockkey,sizeof(blockkey));
        
        if (
StrEqual(blockkey"alt1"false))
        {
            
Blocked_Keys[KEY_IN_ALT1] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"alt2"false))
        {
            
Blocked_Keys[KEY_IN_ALT2] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"attack"false))
        {
            
Blocked_Keys[KEY_IN_ATTACK] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"attack2"false))
        {
            
Blocked_Keys[KEY_IN_ATTACK2] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"back"false))
        {
            
Blocked_Keys[KEY_IN_BACK] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"bullrush"false))
        {
            
Blocked_Keys[KEY_IN_BULLRUSH] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"cancel"false))
        {
            
Blocked_Keys[KEY_IN_CANCEL] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"duck"false))
        {
            
Blocked_Keys[KEY_IN_DUCK] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"forward"false))
        {
            
Blocked_Keys[KEY_IN_FORWARD] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"grenade1"false))
        {
            
Blocked_Keys[KEY_IN_GRENADE1] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"grenade2"false))
        {
            
Blocked_Keys[KEY_IN_GRENADE2] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"jump"false))
        {
            
Blocked_Keys[KEY_IN_JUMP] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"left"false))
        {
            
Blocked_Keys[KEY_IN_LEFT] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"moveleft"false))
        {
            
Blocked_Keys[KEY_IN_MOVELEFT] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"moveright"false))
        {
            
Blocked_Keys[KEY_IN_MOVERIGHT] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"reload"false))
        {
            
Blocked_Keys[KEY_IN_RELOAD] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"right"false))
        {
            
Blocked_Keys[KEY_IN_RIGHT] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"run"false))
        {
            
Blocked_Keys[KEY_IN_RUN] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"score"false))
        {
            
Blocked_Keys[KEY_IN_SCORE] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"speed"false))
        {
            
Blocked_Keys[KEY_IN_SPEED] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"use"false))
        {
            
Blocked_Keys[KEY_IN_USE] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"walk"false))
        {
            
Blocked_Keys[KEY_IN_WALK] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"weapon1"false))
        {
            
Blocked_Keys[KEY_IN_WEAPON1] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"weapon2"false))
        {
            
Blocked_Keys[KEY_IN_WEAPON2] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"zoom"false))
        {
            
Blocked_Keys[KEY_IN_ZOOM] = true;
            
changed true;
        }
        if(
changedPrintToConsole(client"KeyBlock: %s"blockkey);
    }
    return 
Plugin_Handled;
}

public 
Action:Command_RemoveBlock(client,args)
{
    new 
String:blockkey[32];
    new 
bool:changed false;
    
    if (
args 0)
    {
        
GetCmdArg(1,blockkey,sizeof(blockkey));
        
        if (
StrEqual(blockkey"alt1"false))
        {
            
Blocked_Keys[KEY_IN_ALT1] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"alt2"false))
        {
            
Blocked_Keys[KEY_IN_ALT2] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"attack"false))
        {
            
Blocked_Keys[KEY_IN_ATTACK] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"attack2"false))
        {
            
Blocked_Keys[KEY_IN_ATTACK2] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"back"false))
        {
            
Blocked_Keys[KEY_IN_BACK] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"bullrush"false))
        {
            
Blocked_Keys[KEY_IN_BULLRUSH] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"cancel"false))
        {
            
Blocked_Keys[KEY_IN_CANCEL] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"duck"false))
        {
            
Blocked_Keys[KEY_IN_DUCK] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"forward"false))
        {
            
Blocked_Keys[KEY_IN_FORWARD] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"grenade1"false))
        {
            
Blocked_Keys[KEY_IN_GRENADE1] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"grenade2"false))
        {
            
Blocked_Keys[KEY_IN_GRENADE2] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"jump"false))
        {
            
Blocked_Keys[KEY_IN_JUMP] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"left"false))
        {
            
Blocked_Keys[KEY_IN_LEFT] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"moveleft"false))
        {
            
Blocked_Keys[KEY_IN_MOVELEFT] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"moveright"false))
        {
            
Blocked_Keys[KEY_IN_MOVERIGHT] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"reload"false))
        {
            
Blocked_Keys[KEY_IN_RELOAD] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"right"false))
        {
            
Blocked_Keys[KEY_IN_RIGHT] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"run"false))
        {
            
Blocked_Keys[KEY_IN_RUN] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"score"false))
        {
            
Blocked_Keys[KEY_IN_SCORE] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"speed"false))
        {
            
Blocked_Keys[KEY_IN_SPEED] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"use"false))
        {
            
Blocked_Keys[KEY_IN_USE] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"walk"false))
        {
            
Blocked_Keys[KEY_IN_WALK] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"weapon1"false))
        {
            
Blocked_Keys[KEY_IN_WEAPON1] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"weapon2"false))
        {
            
Blocked_Keys[KEY_IN_WEAPON2] = false;
            
changed true;
        }
        else if (
StrEqual(blockkey"zoom"false))
        {
            
Blocked_Keys[KEY_IN_ZOOM] = false;
            
changed true;
        }
        if(
changedPrintToConsole(client"RemoveKeyBlock: %s"blockkey);
    }
    return 
Plugin_Handled;
}

public 
Action:Command_KeyList(client,args)
{
    
    
PrintToConsole(client"alt1, alt2, attack, attack2, back, bullrush, cancel, duck, forward, grenade1, grenade2, jump, left, moveleft, moveright, reload, right, run, score, speed, use, walk, weapon1, weapon2, zoom");
    return 
Plugin_Handled;
}

public 
Action:OnPlayerRunCmd(client, &buttons, &impulseFloat:vel[3], Float:angles[3], &weapon)
{
    new 
iInitialButtons buttons;
    
    if(
buttons IN_ALT1 && Blocked_Keys[KEY_IN_ALT1])
    {
        
buttons &= ~IN_ALT1;
    }
    if(
buttons IN_ALT2 && Blocked_Keys[KEY_IN_ALT2])
    {
        
buttons &= ~IN_ALT2;
    }
    if(
buttons IN_ATTACK && Blocked_Keys[KEY_IN_ATTACK])
    {
        
buttons &= ~IN_ATTACK;
    }
    if(
buttons IN_ATTACK2 && Blocked_Keys[KEY_IN_ATTACK2])
    {
        
buttons &= ~IN_ATTACK2;
    }
    if(
buttons IN_BACK && Blocked_Keys[KEY_IN_BACK])
    {
        
buttons &= ~IN_BACK;
    }
    if(
buttons IN_BULLRUSH && Blocked_Keys[KEY_IN_BULLRUSH])
    {
        
buttons &= ~IN_BULLRUSH;
    }
    if(
buttons IN_CANCEL && Blocked_Keys[KEY_IN_CANCEL])
    {
        
buttons &= ~IN_CANCEL;
    }
    if(
buttons IN_DUCK && Blocked_Keys[KEY_IN_DUCK])
    {
        
buttons &= ~IN_DUCK;
    }
    if(
buttons IN_FORWARD && Blocked_Keys[KEY_IN_FORWARD])
    {
        
buttons &= ~IN_FORWARD;
    }
    if(
buttons IN_GRENADE1 && Blocked_Keys[KEY_IN_GRENADE1])
    {
        
buttons &= ~IN_GRENADE1;
    }
    if(
buttons IN_GRENADE2 && Blocked_Keys[KEY_IN_GRENADE2])
    {
        
buttons &= ~IN_GRENADE2;
    }
    if(
buttons IN_JUMP && Blocked_Keys[KEY_IN_JUMP])
    {
        
buttons &= ~IN_JUMP;
    }
    if(
buttons IN_LEFT && Blocked_Keys[KEY_IN_LEFT])
    {
        
buttons &= ~IN_LEFT;
    }
    if(
buttons IN_MOVELEFT && Blocked_Keys[KEY_IN_MOVELEFT])
    {
        
buttons &= ~IN_MOVELEFT;
    }
    if(
buttons IN_MOVERIGHT && Blocked_Keys[KEY_IN_MOVERIGHT])
    {
        
buttons &= ~IN_MOVERIGHT;
    }
    if(
buttons IN_RELOAD && Blocked_Keys[KEY_IN_RELOAD])
    {
        
buttons &= ~IN_RELOAD;
    }
    if(
buttons IN_RIGHT && Blocked_Keys[KEY_IN_RIGHT])
    {
        
buttons &= ~IN_RIGHT;
    }
    if(
buttons IN_RUN && Blocked_Keys[KEY_IN_RUN])
    {
        
buttons &= ~IN_RUN;
    }
    if(
buttons IN_SCORE && Blocked_Keys[KEY_IN_SCORE])
    {
        
buttons &= ~IN_SCORE;
    }
    if(
buttons IN_SPEED && Blocked_Keys[KEY_IN_SPEED])
    {
        
buttons &= ~IN_SPEED;
    }
    if(
buttons IN_USE && Blocked_Keys[KEY_IN_USE])
    {
        
buttons &= ~IN_USE;
    }
    if(
buttons IN_WALK && Blocked_Keys[KEY_IN_WALK])
    {
        
buttons &= ~IN_WALK;
    }
    if(
buttons IN_WEAPON1 && Blocked_Keys[KEY_IN_WEAPON1])
    {
        
buttons &= ~IN_WEAPON1;
    }
    if(
buttons IN_WEAPON2 && Blocked_Keys[KEY_IN_WEAPON2])
    {
        
buttons &= ~IN_WEAPON2;
    }
    
    if(
iInitialButtons != buttons)
        return 
Plugin_Changed
    
    
return Plugin_Continue;


Last edited by zipcore; 11-19-2012 at 19:45.
zipcore is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 11-18-2012 , 11:37   Re: [SNIPPET] Block Keys
Reply With Quote #2

Any particular reason you created the keys enum instead of using entity_prop_stocks's bitflags directly?
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 11-18-2012 at 11:39.
Powerlord is offline
psychonic

BAFFLED
Join Date: May 2008
Old 11-18-2012 , 12:26   Re: [SNIPPET] Block Keys
Reply With Quote #3

Quote:
Originally Posted by Powerlord View Post
Any particular reason you created the keys enum instead of using entity_prop_stocks's bitflags directly?
I'm assuming that he's trying to avoid Logarithm+RoundToNearest calls when looking up the array index.
psychonic is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 11-18-2012 , 13:47   Re: [SNIPPET] Block Keys
Reply With Quote #4

Quote:
Originally Posted by psychonic View Post
I'm assuming that he's trying to avoid Logarithm+RoundToNearest calls when looking up the array index.
Except that the bitflags render the array redundant as you can store them in a single cell.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 11-18-2012 , 14:43   Re: [SNIPPET] Block Keys
Reply With Quote #5

PHP Code:
        if (StrEqual(blockkey"alt1"false))
        {
            
Blocked_Keys[KEY_IN_ALT1] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"al2"false))
        {
            
Blocked_Keys[KEY_IN_ALT2] = true;
            
changed true;
        }... 
Don't put else if since you can have many keys to block. Exemple, if you block 'al2' (which spelling wrong by the way) it will work fine, but if you block alt1 and al2 and the player hold alt1 and al2 in the same time than al2 won't be blocked since it check the condition of alt1, do is part and switch to the end.
Mathias. is offline
zipcore
Veteran Member
Join Date: Mar 2010
Location: m_flZipcore
Old 11-18-2012 , 17:54   Re: [SNIPPET] Block Keys
Reply With Quote #6

Quote:
Originally Posted by Black-Rabbit View Post
PHP Code:
        if (StrEqual(blockkey"alt1"false))
        {
            
Blocked_Keys[KEY_IN_ALT1] = true;
            
changed true;
        }
        else if (
StrEqual(blockkey"al2"false))
        {
            
Blocked_Keys[KEY_IN_ALT2] = true;
            
changed true;
        }... 
Don't put else if since you can have many keys to block. Exemple, if you block 'al2' (which spelling wrong by the way) it will work fine, but if you block alt1 and al2 and the player hold alt1 and al2 in the same time than al2 won't be blocked since it check the condition of alt1, do is part and switch to the end.
thanks ^^
zipcore is offline
eric0279
AlliedModders Donor
Join Date: May 2007
Old 11-19-2012 , 02:04   Re: [SNIPPET] Block Keys
Reply With Quote #7

Hello,

is it possible you add a target to block the keys?

Nice plugin!
eric0279 is offline
zipcore
Veteran Member
Join Date: Mar 2010
Location: m_flZipcore
Old 11-19-2012 , 08:34   Re: [SNIPPET] Block Keys
Reply With Quote #8

Quote:
Originally Posted by eric0279 View Post
Hello,

is it possible you add a target to block the keys?

Nice plugin!
Sry I rleased this only as a sippet, more features can be added, but are not planned by myself.
If anyone like to improve this and realease it as a plugin, I don't care
zipcore is offline
Despirator
Senior Member
Join Date: Jun 2011
Location: Kazakhstan ->Shymkent
Old 11-19-2012 , 11:04   Re: [SNIPPET] Block Keys
Reply With Quote #9

Quote:
Originally Posted by zipcore View Post
if(iInitialButtons != buttons)
return Plugin_Changed
else
return Plugin_Continue;
}[/PHP]
You have to remove "else" there
Despirator is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 11-19-2012 , 19:20   Re: [SNIPPET] Block Keys
Reply With Quote #10

Quote:
Originally Posted by Despirator View Post
You have to remove "else" there
Yeah, the wrong one was removed, you can only have one match on the command, so that should be if..elseif, but when checking the buttons they should be separate statements.
__________________
asherkin 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 18:37.


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