View Single Post
Author Message
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 06-13-2014 , 20:49   [Snippet] You need a Help Command to your plugin? Look Here :)
Reply With Quote #1

Hi, i actually using this on my plugins, this is a small code to detect what commands you are using in your plugin and put in a MOTD file.

Let's learn:

PHP Code:
public plugin_init()
{
    
register_plugin("Helper MOTD (Example plugin)","0.0.1","SmileY");
    
    
/*
        Here, you need to register an command using an prefix, i used . (Point),
        but you can perfectly use yorprefix_, / (bar), ! (exclamation) and others)
        
        After, you need to put a valid FLAG to use with their commands, in this case i
        used the ADMIN_ALL flag (0), to use with all players in the server.
        
        You can use this to Admin Commands (To your boring custom Admin Plugin), just
        add the correct flags for Admins, and in function put appropriated flag too.
        
        And also wee need a information about command, this will displayed in MOTD.
        For commands with parameters, you can put in this format:
        
        >> "<Player> - Description of command"
        
        register_clcmd(".kick","CommandKick",ADMIN_KICK,"<Player> - Kicks the given player");
        
        Of course you can use the:
        
        register_clcmd
        register_concmd and
        register_srvcmd for do that part,
    */
    
    
register_clcmd(".rs","CommandResetScore",ADMIN_ALL,"Reset your score in any situation");
    
register_clcmd(".help","CommandHelp",ADMIN_ALL,"Show a list with a registred commands to users");


We need a functions to work with code above:
You can use more functions of course..


PHP Code:
public CommandResetScore(id)     // Reset score: Example function
{                // For sure, to register a command you need a funcion :)
    
set_user_frags(id,0);
    
cs_set_user_deaths(id,0);
    
    new 
sName[32];
    
get_user_name(id,sName,charsmax(sName));
    
    
client_print_color(0,print_team_grey,"[RS] %s has just reset his score.",sName);
    
    return 
PLUGIN_HANDLED;

Finally, we need a function of helper command:

PHP Code:
public CommandHelp(id)
{
    
/*
        Here we have all static variables, because the console commands
        are commonly added in plugin_init and will not be changed until the end of the map.
        
        For Motd, i used the common style of default motds from Half life, is very fun too :O
        Change if you need.
        
        About MOTD limitation, i think any plugin will be a lot of commands but doesn't matter for me..
    
    */
    
static sMOTD[1600],sCommand[64],sInfo[256],iFlags;
    
formatex(sMOTD,charsmax(sMOTD),"<style type='text/css'>body{background:#000; margin:2px; color:#FFB000; font:normal 6px/6px Lucida Console;}</style><table width='100%%'>");
    
    
/*
        We will get all commands that are using the ADMIN_ALL flag registred in the
        register_clcmd / register_concmd / register_srvcmd and store into a variable.
        
        You can define this with a macro in begin of your plugin.
    */
    
new iCommands get_concmdsnum(ADMIN_ALL);
    
    
/*
        Yep, you can put this to activate if you need..
        
        if(iCommands == 0)
        {
            console_print(id,"* Sorry, the developers has not added commands with this flag.");
            
            return PLUGIN_HANDLED;
        }
    */
    
    
for(new i;iCommands;i++) // Begin a LOOP with a number of registred commands.
    
{
        
/*
            YAW! We are getting commands from console, with specified flags and storing into a variables.
        */
    
        
get_concmd(i,sCommand,charsmax(sCommand),iFlags,sInfo,charsmax(sInfo),ADMIN_ALL);
        
        
/*
            If a command begin with . (Point), add to MOTD the Command name and their info
            If you are using prefixes, this can replaced to:
            
            if(containi("yourprefix_",sCommand) != -1)
            {
                // Rest of code
            }
        */
        
if(sCommand[0] == '.')
        {
            
replace_all(sInfo,sizeof(sInfo),"<","<"); // If you are using into a info, replace with appropriated HTML special char.
            
replace_all(sInfo,sizeof(sInfo),">",">"); // :P
            
            // We can use formatex to do this? I do not know, i think NOT
            // So we create a simple table to align the commands correctly,
            // you will see the result in attached screenshot in the post.
            
format(sMOTD,charsmax(sMOTD),"%s<tr><td>%s</td><td>%s</td></tr>",sMOTD,sCommand,sInfo);
        }
    }
    
    
/*
        Finally show the motd with a title to client.
    */
    
    
show_motd(id,sMOTD,"Client Commands");
    
    return 
PLUGIN_HANDLED// This will remove uknow command from console :)

Example plugin and screen-shot of final example attached, sorry for errors, if you found tell to us...
Attached Images
File Type: jpg de_lite.jpg (64.7 KB, 277 views)
Attached Files
File Type: sma Get Plugin or Get Source (helper.sma - 791 views - 4.0 KB)
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 

Last edited by ^SmileY; 06-13-2014 at 20:59.
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY