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..
/* 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;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. */
/* 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...
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.
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...
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.
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.
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.