AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [SNIPPET] Block Keys (https://forums.alliedmods.net/showthread.php?t=201196)

zipcore 11-18-2012 09:45

[SNIPPET] Block Keys
 
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;



Powerlord 11-18-2012 11:37

Re: [SNIPPET] Block Keys
 
Any particular reason you created the keys enum instead of using entity_prop_stocks's bitflags directly?

psychonic 11-18-2012 12:26

Re: [SNIPPET] Block Keys
 
Quote:

Originally Posted by Powerlord (Post 1839959)
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.

Powerlord 11-18-2012 13:47

Re: [SNIPPET] Block Keys
 
Quote:

Originally Posted by psychonic (Post 1839994)
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.

Mathias. 11-18-2012 14:43

Re: [SNIPPET] Block Keys
 
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.

zipcore 11-18-2012 17:54

Re: [SNIPPET] Block Keys
 
Quote:

Originally Posted by Black-Rabbit (Post 1840100)
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 ^^

eric0279 11-19-2012 02:04

Re: [SNIPPET] Block Keys
 
Hello,

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

Nice plugin!

zipcore 11-19-2012 08:34

Re: [SNIPPET] Block Keys
 
Quote:

Originally Posted by eric0279 (Post 1840340)
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 :P

Despirator 11-19-2012 11:04

Re: [SNIPPET] Block Keys
 
Quote:

Originally Posted by zipcore (Post 1839901)
if(iInitialButtons != buttons)
return Plugin_Changed
else
return Plugin_Continue;
}[/PHP]

You have to remove "else" there

eric0279 11-19-2012 16:25

Re: [SNIPPET] Block Keys
 
ok hoping someone improve this plugin :)


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

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