View Single Post
snowyiet
Member
Join Date: Jan 2010
Old 09-19-2013 , 03:10   Re: server binds key for player
Reply With Quote #22

Quote:
Originally Posted by bl4nk View Post
Ah, I thought it existed already, but couldn't find it due to the name. This should effectively do the same thing that SourceOP does. Type "sm_bindcommand <command>" into console, and it should pop up with the same list asking to bind the given command.

PHP Code:
#pragma semicolon 1

#include <sourcemod>

public OnPluginStart() {
    
RegConsoleCmd("sm_bindcommand"Command_Bind);
    
RegConsoleCmd("bindmenu"Command_BindMenu);
}

public 
Action:Command_Bind(iClientiArgCount) {
    if (
iArgCount 2) {
        
ReplyToCommand(iClient"[SM] Usage: sm_bindcommand <command>");
        return 
Plugin_Handled;
    }

    
decl String:szCommand[32];
    
GetCmdArg(1szCommandsizeof(szCommand));

    
ShowBindMenu(iClientszCommand0);

    return 
Plugin_Handled;
}

public 
Action:Command_BindMenu(iClientiArgCount) {
    if (
iArgCount 1) {
        
decl String:szCommand[32], String:szMenuOpt[2];
        
GetCmdArg(1szCommandsizeof(szCommand));
        
GetCmdArg(2szMenuOptsizeof(szMenuOpt));

        new 
iMenuOpt StringToInt(szMenuOpt);
        if (
iMenuOpt || iMenuOpt 8) {
            
iMenuOpt 0;
        }

        
ShowBindMenu(iClientszCommandiMenuOpt);
    }

    return 
Plugin_Handled;
}

ShowBindMenu(iClient, const String:szCommand[], iMenuOpt) {
    if (
iClient && IsClientConnected(iClient)) {
        new 
Handle:hKV CreateKeyValues("menu");
        
KvSetString(hKV"title""Bind menu, hit ESC");
        
KvSetNum(hKV"level"1);
        
KvSetColor(hKV"color"1282550255);
        
KvSetNum(hKV"time"20);
        
        
decl String:szBuffer[192];
        
Format(szBuffersizeof(szBuffer), "Bind Menu.\nPick a key to bind %s to."szCommand);
        
KvSetString(hKV"msg"szBuffer);

        switch (
iMenuOpt) {
            case 
1: {
                
KvJumpToKey(hKV"1"true);
                
KvSetString(hKV"msg""A");
                
Format(szBuffersizeof(szBuffer), "bind a %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"2"true);
                
KvSetString(hKV"msg""B");
                
Format(szBuffersizeof(szBuffer), "bind b %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"3"true);
                
KvSetString(hKV"msg""C");
                
Format(szBuffersizeof(szBuffer), "bind c %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"4"true);
                
KvSetString(hKV"msg""D");
                
Format(szBuffersizeof(szBuffer), "bind d %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"5"true);
                
KvSetString(hKV"msg""E");
                
Format(szBuffersizeof(szBuffer), "bind e %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"6"true);
                
KvSetString(hKV"msg""F");
                
Format(szBuffersizeof(szBuffer), "bind f %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);

                
KvJumpToKey(hKV"7"true);
                
KvSetString(hKV"msg""G");
                
Format(szBuffersizeof(szBuffer), "bind g %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);

                
KvJumpToKey(hKV"8"true);
                
KvSetString(hKV"msg""<< Back");
                
Format(szBuffersizeof(szBuffer), "bindmenu %s 0"szCommand);
                
KvSetString(hKV"command"szBuffer);
            }
            case 
2: {
                
KvJumpToKey(hKV"1"true);
                
KvSetString(hKV"msg""H");
                
Format(szBuffersizeof(szBuffer), "bind h %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"2"true);
                
KvSetString(hKV"msg""I");
                
Format(szBuffersizeof(szBuffer), "bind i %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"3"true);
                
KvSetString(hKV"msg""J");
                
Format(szBuffersizeof(szBuffer), "bind j %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"4"true);
                
KvSetString(hKV"msg""K");
                
Format(szBuffersizeof(szBuffer), "bind k %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"5"true);
                
KvSetString(hKV"msg""L");
                
Format(szBuffersizeof(szBuffer), "bind l %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"6"true);
                
KvSetString(hKV"msg""M");
                
Format(szBuffersizeof(szBuffer), "bind m %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);

                
KvJumpToKey(hKV"7"true);
                
KvSetString(hKV"msg""N");
                
Format(szBuffersizeof(szBuffer), "bind n %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);

                
KvJumpToKey(hKV"8"true);
                
KvSetString(hKV"msg""<< Back");
                
Format(szBuffersizeof(szBuffer), "bindmenu %s 0"szCommand);
                
KvSetString(hKV"command"szBuffer);
            }
            case 
3: {
                
KvJumpToKey(hKV"1"true);
                
KvSetString(hKV"msg""O");
                
Format(szBuffersizeof(szBuffer), "bind o %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"2"true);
                
KvSetString(hKV"msg""P");
                
Format(szBuffersizeof(szBuffer), "bind p %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"3"true);
                
KvSetString(hKV"msg""Q");
                
Format(szBuffersizeof(szBuffer), "bind q %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"4"true);
                
KvSetString(hKV"msg""R");
                
Format(szBuffersizeof(szBuffer), "bind r %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"5"true);
                
KvSetString(hKV"msg""S");
                
Format(szBuffersizeof(szBuffer), "bind s %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"6"true);
                
KvSetString(hKV"msg""T");
                
Format(szBuffersizeof(szBuffer), "bind t %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);

                
KvJumpToKey(hKV"7"true);
                
KvSetString(hKV"msg""U");
                
Format(szBuffersizeof(szBuffer), "bind u %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);

                
KvJumpToKey(hKV"8"true);
                
KvSetString(hKV"msg""<< Back");
                
Format(szBuffersizeof(szBuffer), "bindmenu %s 0"szCommand);
                
KvSetString(hKV"command"szBuffer);
            }
            case 
4: {
                
KvJumpToKey(hKV"1"true);
                
KvSetString(hKV"msg""V");
                
Format(szBuffersizeof(szBuffer), "bind v %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"2"true);
                
KvSetString(hKV"msg""W");
                
Format(szBuffersizeof(szBuffer), "bind w %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"3"true);
                
KvSetString(hKV"msg""X");
                
Format(szBuffersizeof(szBuffer), "bind x %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"4"true);
                
KvSetString(hKV"msg""Y");
                
Format(szBuffersizeof(szBuffer), "bind y %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"5"true);
                
KvSetString(hKV"msg""Z");
                
Format(szBuffersizeof(szBuffer), "bind z %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);

                
KvJumpToKey(hKV"6"true);
                
KvSetString(hKV"msg""<< Back");
                
Format(szBuffersizeof(szBuffer), "bindmenu %s 0"szCommand);
                
KvSetString(hKV"command"szBuffer);
            }
            case 
5: {
                
KvJumpToKey(hKV"1"true);
                
KvSetString(hKV"msg""-");
                
Format(szBuffersizeof(szBuffer), "bind - %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"2"true);
                
KvSetString(hKV"msg""=");
                
Format(szBuffersizeof(szBuffer), "bind = %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"3"true);
                
KvSetString(hKV"msg""[");
                
Format(szBuffersizeof(szBuffer), "bind [ %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"4"true);
                
KvSetString(hKV"msg""]");
                
Format(szBuffersizeof(szBuffer), "bind ] %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"5"true);
                
KvSetString(hKV"msg""\\");
                
Format(szBuffersizeof(szBuffer), "bind \\ %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"6"true);
                
KvSetString(hKV"msg"";");
                
Format(szBuffersizeof(szBuffer), "bind semicolon %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);

                
KvJumpToKey(hKV"7"true);
                
KvSetString(hKV"msg""More >>");
                
Format(szBuffersizeof(szBuffer), "bindmenu %s 6"szCommand);
                
KvSetString(hKV"command"szBuffer);

                
KvJumpToKey(hKV"8"true);
                
KvSetString(hKV"msg""<< Back");
                
Format(szBuffersizeof(szBuffer), "bindmenu %s 0"szCommand);
                
KvSetString(hKV"command"szBuffer);
            }
            case 
6: {
                
KvJumpToKey(hKV"1"true);
                
KvSetString(hKV"msg""'");
                
Format(szBuffersizeof(szBuffer), "bind ' %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"2"true);
                
KvSetString(hKV"msg"",");
                
Format(szBuffersizeof(szBuffer), "bind , %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"3"true);
                
KvSetString(hKV"msg"".");
                
Format(szBuffersizeof(szBuffer), "bind . %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"4"true);
                
KvSetString(hKV"msg""/");
                
Format(szBuffersizeof(szBuffer), "bind / %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"5"true);
                
KvSetString(hKV"msg""Shift");
                
Format(szBuffersizeof(szBuffer), "bind shift %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"6"true);
                
KvSetString(hKV"msg""Ctrl");
                
Format(szBuffersizeof(szBuffer), "bind ctrl %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);

                
KvJumpToKey(hKV"7"true);
                
KvSetString(hKV"msg""Alt");
                
Format(szBuffersizeof(szBuffer), "bind alt %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);

                
KvJumpToKey(hKV"8"true);
                
KvSetString(hKV"msg""<< Back");
                
Format(szBuffersizeof(szBuffer), "bindmenu %s 0"szCommand);
                
KvSetString(hKV"command"szBuffer);
            }
            case 
7: {
                
KvJumpToKey(hKV"1"true);
                
KvSetString(hKV"msg""Up Arrow");
                
Format(szBuffersizeof(szBuffer), "bind uparrow %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"2"true);
                
KvSetString(hKV"msg""Right Arrow");
                
Format(szBuffersizeof(szBuffer), "bind rightarrow %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"3"true);
                
KvSetString(hKV"msg""Down Arrow");
                
Format(szBuffersizeof(szBuffer), "bind downarrow %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"4"true);
                
KvSetString(hKV"msg""Left Arrow");
                
Format(szBuffersizeof(szBuffer), "bind leftarrow %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);

                
KvJumpToKey(hKV"5"true);
                
KvSetString(hKV"msg""<< Back");
                
Format(szBuffersizeof(szBuffer), "bindmenu %s 0"szCommand);
                
KvSetString(hKV"command"szBuffer);
            }
            case 
8: {
                
KvJumpToKey(hKV"1"true);
                
KvSetString(hKV"msg""Mouse Button 3");
                
Format(szBuffersizeof(szBuffer), "bind mouse3 %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"2"true);
                
KvSetString(hKV"msg""Mouse Button 4");
                
Format(szBuffersizeof(szBuffer), "bind mouse4 %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"3"true);
                
KvSetString(hKV"msg""Mouse Button 5");
                
Format(szBuffersizeof(szBuffer), "bind mouse5 %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"4"true);
                
KvSetString(hKV"msg""Mouse Wheel Up");
                
Format(szBuffersizeof(szBuffer), "bind mwheelup %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"5"true);
                
KvSetString(hKV"msg""Mouse Wheel Down");
                
Format(szBuffersizeof(szBuffer), "bind mwheeldown %s;cancelselect"szCommand);
                
KvSetString(hKV"command"szBuffer);

                
KvJumpToKey(hKV"6"true);
                
KvSetString(hKV"msg""<< Back");
                
Format(szBuffersizeof(szBuffer), "bindmenu %s 0"szCommand);
                
KvSetString(hKV"command"szBuffer);
            }
            default: {
                
KvJumpToKey(hKV"1"true);
                
KvSetString(hKV"msg""A-G");
                
Format(szBuffersizeof(szBuffer), "bindmenu %s 1"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"2"true);
                
KvSetString(hKV"msg""H-N");
                
Format(szBuffersizeof(szBuffer), "bindmenu %s 2"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"3"true);
                
KvSetString(hKV"msg""P-U");
                
Format(szBuffersizeof(szBuffer), "bindmenu %s 3"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"4"true);
                
KvSetString(hKV"msg""V-Z");
                
Format(szBuffersizeof(szBuffer), "bindmenu %s 4"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"5"true);
                
KvSetString(hKV"msg""Symbols");
                
Format(szBuffersizeof(szBuffer), "bindmenu %s 5"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"6"true);
                
KvSetString(hKV"msg""Arrows");
                
Format(szBuffersizeof(szBuffer), "bindmenu %s 7"szCommand);
                
KvSetString(hKV"command"szBuffer);
                
                
KvJumpToKey(hKV"7"true);
                
KvSetString(hKV"msg""Mouse Buttons");
                
Format(szBuffersizeof(szBuffer), "bindmenu %s 8"szCommand);
                
KvSetString(hKV"command"szBuffer);
            }
        }

        
CreateDialog(iClienthKVDialogType_Menu);
        
CloseHandle(hKV);
    }


This compiles without any errors but it doesn't work. It would be really nice if there was a working plugin like this for sourcemod.
snowyiet is offline