15.04.2015, 18:46
Introduction
This is an update to my old command processing system in YSI. Since then I have steamlined a lot of the code and made it more robust and easier to use. It can also now be used as a drop in replacement for zcmd.
y_commands is actually now FASTER than ZCMD and is designed to handle huge numbers of commands. Additionally included in that speed is permission checks (to set exactly who can use the command), a help system, command renaming and removal plus more.
Download
This library is a part of YSI, which can be found here. Keep your eye on that topic and your server log for updates.
YSI Download Topic
Features
The full list of commands is given below.
This graph is a comparison between zcmd, y_command and fcmd. Note that strcmp based command processors are excluded for brevity - they are no-where near this speed.
Currently there is no graph displaying the speed comparison. You can make one yourself, or if there is a demand for it I might attempt to make one.
The code for this test can be found here:
http://y-less.pastebin.com/HLgGVynL
http://y-less.pastebin.com/8Cp2p5Pv
The batch command to build the required scripts is:
Credits
I am reposting this include (made by Y_Less) with the thought of what he said to several members of the community. Everything that could help someone should not be deleted from the forums, which is something I agree with since I learned a lot by reading the tutorials on here. He made a lot of things that are used by lots of servers and that knowledge should not be lost for present and future developers.
This is an update to my old command processing system in YSI. Since then I have steamlined a lot of the code and made it more robust and easier to use. It can also now be used as a drop in replacement for zcmd.
- Why?
y_commands is actually now FASTER than ZCMD and is designed to handle huge numbers of commands. Additionally included in that speed is permission checks (to set exactly who can use the command), a help system, command renaming and removal plus more.
- Master
Download
This library is a part of YSI, which can be found here. Keep your eye on that topic and your server log for updates.
YSI Download Topic
Features
- Fast commands - This system uses the same CallRemoteFunction used in ZCMD to get good command processing speed.
- Permissions - The system has in-built support for per-player permissions. No more code like:
Code:CMD:ban(playerid, params[]) { if (gIsAdmin[playerid]) { // Do your code here. } }
- Renaming - This system allows you to dynamically rename or remove commands. Imagine a server where English players type "/help", Dutch type "/hulp" and Italian type "/aiuto"!
- Lists - Using my y_scripting library the command system gathers information about commands in modes. It knows every command you have - you never need to worry about keeping the list in "/commands" updated. Using functions in the system you can list only the commands a single player can use, and if there are multiple language versions of a command it will only list the ones they need:
Code:YCMD:commands(playerid, params[], help) { if (help) { SendClientMessage(playerid, 0xFF0000AA, "Lists all the commands a player can use."); } else { new count = Command_GetPlayerCommandCount(playerid); for (new i = 0; i != count; ++i) { SendClientMessage(playerid, 0xFF0000AA, Command_GetNext(i, playerid)); } } return 1; }
- Help - The command system, as shown above, has inbuilt support for a help system. You define the help for a command with that command, making managing your script VASTLY easier. To use this feature from your help command simply do something like:
Code:YCMD:help(playerid, params[], help) { if (help) { SendClientMessage(playerid, 0xFF0000AA, "Displays help about your mode."); } else { if (isnull(params)) { new str[128]; SendClientMessage(playerid, 0xFF0000AA, "Welcome to my mode."); format(str, sizeof (str), "Type \"/%s [command]\" for more help on a command", Command_GetDisplayNamed("help", playerid)); SendClientMessage(playerid, 0xFF0000AA, str); } else { Command_ReProcess(playerid, params, true); } } return 1; }
- Distribution - Every script on your server which uses this command system is linked. Any script can set who can use any command. If you have a custom admin script as a filterscript this can set the permissions on any command in the main gamemode for example. The "/commands" command above will list all commands on the server, whatever mode they are in.
- To use the system simply add the following to the top of your mode:
Code:#include <YSI\y_commands> #include <YSI\y_master>
- To add a command do:
Code:YCMD:me(playerid, params[], help) { if (help) { SendClientMessage(playerid, 0xFF0000AA, "Sends an action to other players."); } else { new str[128]; if (isnull(params)) { format(str, sizeof (str), "Usage: \"/%s [action]\"", Command_GetDisplayNamed("me", playerid)); SendClientMessage(playerid, 0xFF0000AA, str); } else { GetPlayerName(playerid, str, sizeof (str)); format(str, sizeof (str), "* %s %s", str, params); SendClientMessageToAll(0xFF0000AA, str); } } return 1; }
- To add an alternate spelling do:
Code:Command_AddAltNamed("help", "aiuto");
- To set command permissions:
Code:Command_SetPlayerNamed("help", playerid, false);
Code:public OnPlayerLogin(playerid) { if (gLanguage[playerid] == LANGUAGE_ITALIAN) { Command_SetPlayerNamed("help", playerid, false); Command_SetPlayerNamed("aiuto", playerid, true); } else { Command_SetPlayerNamed("help", playerid, true); Command_SetPlayerNamed("aiuto", playerid, false); } }
The full list of commands is given below.
- Command_GetID(funcname[]) - All the examples above used the command's name to set the permissions, if you want you can also use the ID, which this gets.
- Command_SetPlayer(command, playerid, set) - Enables or disables a player's use of a command by ID.
- Command_SetPlayerNamed(command[], playerid, set) - Enables or disables a player's use of a command by name.
- Command_GetPlayer(command, playerid) - Gets a player's use of a command by ID.
- Command_GetPlayerNamed(command[], playerid) - Gets a player's use of a command by name.
- Command_AddAlt(oldid, altname[]) - Adds an alternate spelling for a command by ID.
- Command_AddAltNamed(old[], altname[]) - Adds an alternate spelling for a command by name.
- Command_ReProcess(playerid, cmdtext[], help) - Call to put text through the command processor, with the help functions enabled or disabled.
- Command_GetName(id) - Get the name of a command by ID.
- Command_GetDisplay(command, playerid) - Get the first found command name a player can type to get this functionality.
- Command_GetDisplayNamed(command[], playerid) - Get the first found command name a player can type to get this functionality by name. For example:
Code:Command_GetDisplayNamed("help", playerid);
- Command_GetPlayerCommandCount(playerid) - Get the number of commands in the system the player can use.
- Command_GetNext(index, playerid) - Used for looping through all the commands a player can use, not all the commands that exist.
- Command_SetDeniedReturn(set) - If this is "false" the system will report a command you're not allowed to use as unknown. If it is "true" the system will not run the command but will not send a failure message.
- Command_GetDeniedReturn() - Get the denied return current status.
This graph is a comparison between zcmd, y_command and fcmd. Note that strcmp based command processors are excluded for brevity - they are no-where near this speed.
Currently there is no graph displaying the speed comparison. You can make one yourself, or if there is a demand for it I might attempt to make one.
The code for this test can be found here:
http://y-less.pastebin.com/HLgGVynL
http://y-less.pastebin.com/8Cp2p5Pv
The batch command to build the required scripts is:
Code:
FOR /L %%i IN (0, 1, 2703) DO pawncc.exe "..\gamemodes\cmdtest.pwn" -;+ -\ -(+ CMD_NUM=%%i -o..\gamemodes\cmdtest_%%i
I am reposting this include (made by Y_Less) with the thought of what he said to several members of the community. Everything that could help someone should not be deleted from the forums, which is something I agree with since I learned a lot by reading the tutorials on here. He made a lot of things that are used by lots of servers and that knowledge should not be lost for present and future developers.