Raised This Month: $32 Target: $400
 8% 

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


Post New Thread Reply   
 
Thread Tools Display Modes
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, 274 views)
Attached Files
File Type: sma Get Plugin or Get Source (helper.sma - 776 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
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 06-14-2014 , 03:20   Re: [Snippet] You need a Help Command to your plugin? Look Here :)
Reply With Quote #2

This should be useful, but what about adding a better style to the motd ?
HamletEagle is offline
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 06-14-2014 , 03:34   Re: [Snippet] You need a Help Command to your plugin? Look Here :)
Reply With Quote #3

Quote:
Originally Posted by HamletEagle View Post
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
Ps. Test if the

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

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

Last edited by ^SmileY; 06-14-2014 at 03:35.
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 06-14-2014 , 04:07   Re: [Snippet] You need a Help Command to your plugin? Look Here :)
Reply With Quote #4

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.
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 06-14-2014 , 04:27   Re: [Snippet] You need a Help Command to your plugin? Look Here :)
Reply With Quote #5

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...
__________________
Projects:

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

Last edited by ^SmileY; 06-14-2014 at 04:33.
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Old 06-15-2014, 23:30
EthicalHacker007
This message has been deleted by EthicalHacker007.
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 06-16-2014 , 02:13   Re: [Snippet] You need a Help Command to your plugin? Look Here :)
Reply With Quote #6

Quote:
Originally Posted by EthicalHacker007 View Post
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.
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Old 06-16-2014, 02:21
EthicalHacker007
This message has been deleted by EthicalHacker007.
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 06-16-2014 , 11:11   Re: [Snippet] You need a Help Command to your plugin? Look Here :)
Reply With Quote #7

Quote:
Originally Posted by EthicalHacker007 View Post
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.
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
Old 06-16-2014, 11:55
EthicalHacker007
This message has been deleted by EthicalHacker007.
^SmileY
Veteran Member
Join Date: Jan 2010
Location: Brazil [<o>]
Old 06-16-2014 , 12:57   Re: [Snippet] You need a Help Command to your plugin? Look Here :)
Reply With Quote #8

Quote:
Originally Posted by EthicalHacker007 View Post
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;
__________________
Projects:

- See my Git Hub: https://github.com/SmileYzn
PHP Code:
set_pcvar_num(pCvar, !get_pcvar_num(pCvar)); 
^SmileY is offline
Send a message via MSN to ^SmileY Send a message via Skype™ to ^SmileY
EthicalHacker007
Veteran Member
Join Date: May 2014
Old 06-16-2014 , 13:09   Re: [Snippet] You need a Help Command to your plugin? Look Here :)
Reply With Quote #9

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.
__________________
EthicalHacker007 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:49.


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