View Single Post
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 10-24-2012 , 21:45   Re: How to add commands ? :D
Reply With Quote #10

Something like this maybe?

PHP Code:
#include <sourcemod>

new Handle:g_hMenu INVALID_HANDLE;

public 
OnPluginStart()
{
    
RegAdminCmd("sm_mix"OnMixCommandADMFLAG_ROOT"Mix menu");
}

public 
OnMapStart()
{
    
g_hMenu CreateMenu(MenuHandler);
    
SetMenuTitle(g_hMenu"Mix Menu");
    
AddMenuItem(g_hMenu"0""Restart");
    
AddMenuItem(g_hMenu"1""Spectate All");
    
AddMenuItem(g_hMenu"2""Live");
    
AddMenuItem(g_hMenu"3""Reset Mix");
}

public 
OnMapEnd()
{
    if (
g_hMenu != INVALID_HANDLE)
    {
        
CloseHandle(g_hMenu);
        
g_hMenu INVALID_HANDLE;
    }
}

public 
MenuHandler(Handle:menuMenuAction:actionparam1param2)
{
    if (
action == MenuAction_Select && IsClientInGame(param1))
    {
        switch (
param2)
        {
            case 
0//Restart
            
{
                
PrintToChat(param1"Restart was selected");
            }

            case 
1//Spectate All
            
{
                
PrintToChat(param1"Spectate All was selected");
            }
            case 
2//Live
            
{
                
PrintToChat(param1"Live was selected");
            }
            case 
3//Reset Mix
            
{
                
PrintToChat(param1"Reset Mix was selected");
            }
        }    
    }
}
 
public 
Action:OnMixCommand(clientargs)
{
    if (
client == 0)
    {
        
ReplyToCommand(client"Cannot use command from RCON.");
        return 
Plugin_Handled;
    }
    
    if (
g_hMenu == INVALID_HANDLE)
    {
        
PrintToConsole(client"Unable to open menu!");
    }
    else
    {
        
DisplayMenu(g_hMenuclientMENU_TIME_FOREVER);
    }
 
    return 
Plugin_Handled;

__________________

Last edited by 11530; 10-24-2012 at 21:54.
11530 is offline