AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   [Snippet] You need a Help Command to your plugin? Look Here :) (https://forums.alliedmods.net/showthread.php?t=242096)

^SmileY 06-13-2014 20:49

[Snippet] You need a Help Command to your plugin? Look Here :)
 
3 Attachment(s)
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...

HamletEagle 06-14-2014 03:20

Re: [Snippet] You need a Help Command to your plugin? Look Here :)
 
This should be useful, but what about adding a better style to the motd ?

^SmileY 06-14-2014 03:34

Re: [Snippet] You need a Help Command to your plugin? Look Here :)
 
Quote:

Originally Posted by HamletEagle (Post 2151390)
This should be useful, but what about adding a better style to the motd ?

You can of course, only editing style tag, but more precious chars will be used :fox:
Ps. Test if the

Code:

<style type='text/css'
can be used with href tag to use an external .css file ;)

Flick3rR 06-14-2014 04:07

Re: [Snippet] You need a Help Command to your plugin? Look Here :)
 
What about adding the way to get the MOTD window from cstrike directory (and also show how to make it from the configs folder), instead of formating it directly in the code. I think this way is much useful, too, because the user won't need to redact the .sma itself, but just the .txt file in his folder.

^SmileY 06-14-2014 04:27

Re: [Snippet] You need a Help Command to your plugin? Look Here :)
 
If you want to edit the design several times, you van use a cvar too :)

Ah i forgot, you can format the MOTD in plugins_cfg to advoid re-formatting the motd every time when an player put .help in their console. I will be correct this later on main post...

^SmileY 06-16-2014 02:13

Re: [Snippet] You need a Help Command to your plugin? Look Here :)
 
Quote:

Originally Posted by EthicalHacker007 (Post 2152395)
Nice tutorial. You should provide some more examples and explain them. Would give a boost to newbies like me. Good Job though. Maybe you should explain this too...
Code:


register_clcmd = can be executed from client console
register_concmd = can be executed from client & server console
register_srvcmd = can be executed from server console

Some more examples and detailed explanation. This tutorial would be perfect.

Regards,
EH007

You can put in motd any command registered, this also include client and server commands, do not matter how you have registered.

^SmileY 06-16-2014 11:11

Re: [Snippet] You need a Help Command to your plugin? Look Here :)
 
Quote:

Originally Posted by EthicalHacker007 (Post 2152439)
I'm just saying to add it for info but it depends upon you. I also read about that motd. Just add some more examples.

The file above, contain a simple register_clcmd line, because is easy to read.

I will add a example using plugin_cfg to store MOTD into a global string to avoid the plugin to compile MOTD every time when any player uses help command.

^SmileY 06-16-2014 12:57

Re: [Snippet] You need a Help Command to your plugin? Look Here :)
 
Quote:

Originally Posted by EthicalHacker007 (Post 2152678)
Also explain it with a different flag. And
PHP Code:

if ( ! cmd_access idlevel,  cid  


Do not matter in the purpose of this, this only check if the admin has access in that function, if not will return PLUGIN_HANDLED;

EthicalHacker007 06-16-2014 13:09

Re: [Snippet] You need a Help Command to your plugin? Look Here :)
 
Sorry. I misunderstood you. I thought this plugin was about scripting commands. I was confused after reading title, I thought You need help for commands in your plugin? LMAO! But I was more confused when I read about that motd. Haha.


All times are GMT -4. The time now is 13:16.

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