Silent Creating Custom Commands: Difference between revisions

From MyGamingTalk
Jump to navigation Jump to search
Line 18: Line 18:
:*The commands can be anything that can be executed with /rcon.  
:*The commands can be anything that can be executed with /rcon.  
:*The commands can use all [[Silent Shortcuts|shortcuts]] that players can use with their chat messages.
:*The commands can use all [[Silent Shortcuts|shortcuts]] that players can use with their chat messages.
:*Additional shortcut [i] is available. This will be replaced with the player slot number, except if the command is called from the server console.
:*Additional shortcut [i] is available. This will be replaced with the client slot number of the player who called the command. If the command was called from the server console, or /rcon, this shortcut will not be replaced.
:*In addition to the normal shortcuts, the shrubbot custom commands support parameter place holders. These are [1] - [9], where the number is the n:th parameter given to the custom command. When these are used, the server will substitute the placeholder with the n:th parameter given to the command.
:*The shrubbot custom commands support parameter place holders. These are [1] - [9], where the number is the n:th parameter given to the custom command. When these are used, the server will substitute the placeholder with the n:th parameter given to the command.
:*There is also the possibility to add ? to the parameter placeholders. If the question mark is added, the parameter is substituted with a player name if only one name matches the pattern. If there are no matches or there are several matches, the command will fail and reports an informative error. All placeholders can have the question mark if that is needed for the command.
:*There is also the possibility to add ? to the parameter placeholders. If the question mark is added, the parameter is substituted with a player name if only one name matches the pattern. If there are no matches or there are several matches, the command will fail and reports an informative error. All placeholders can have the question mark if that is needed for the command.



Revision as of 12:55, 22 September 2014

What Are Custom Commands

Custom commands are shrubbot like commands that are not implemented by the silEnT mod, but instead by server admins. There are three ways to create custom commands. One is to simply use the [command] blocks in the shrubbot.cfg. Second one is to combine [command] block with a Lua script that will do more complicated work than what just what the rcon can do. And the third method is to implement everything with Lua. The following sections describe each of these methods.

Shrubbot.cfg Method

The shrubbot.cfg file on your server can include following blocks:

   [command]
   command  = The name of the command.
   exec     = The executed command. These must be commands available to /rcon and these will be executed with rcon privileges.
   desc     = The help description of the command.
   syntax   = List of parameters if the command uses them. This is used with !help and it is optional.
   levels   = Space separated list of levels that are allowed to use the command.

These commands appear in the !help output just as if they were implemented by the silEnT mod itself. Also, !help <command name> can be used to see detailed help about the commands. The exec line defines the commands that will be executed by the mod. The exec field supports the following:

  • The commands can be anything that can be executed with /rcon.
  • The commands can use all shortcuts that players can use with their chat messages.
  • Additional shortcut [i] is available. This will be replaced with the client slot number of the player who called the command. If the command was called from the server console, or /rcon, this shortcut will not be replaced.
  • The shrubbot custom commands support parameter place holders. These are [1] - [9], where the number is the n:th parameter given to the custom command. When these are used, the server will substitute the placeholder with the n:th parameter given to the command.
  • There is also the possibility to add ? to the parameter placeholders. If the question mark is added, the parameter is substituted with a player name if only one name matches the pattern. If there are no matches or there are several matches, the command will fail and reports an informative error. All placeholders can have the question mark if that is needed for the command.

Example:

   [command]
   command  = crybaby
   exec     = playsound path/to/sound.wav; chat ^7[1?]^7 is crying like a little baby!
   desc     = Make someone cry like a baby
   syntax   = [name]
   levels   = 0 1 2 3 4 5

Note:

If the command breaks because the name that substitutes a placeholder has spaces, use " characters to surround the placeholder. Like this "[1?]". It will ensure that the full name is parsed as one parameter instead of getting interpreted as separate parameters.

Combining shrubbot.cfg and Lua Scripts

One method to extend what the commands can do, is to use a Lua script to implement the actual command operation. To do this, create a custom command to the shrubbot.cfg, which executes a command, which is not recognized by the silEnT mod. Such command will pass through to the et_ConsoleCommand Lua callback. Where it can be intercepted and proper actions can be taken. The advantage of this method is that the command privileges and help are handled by the silEnT mod. This includes the Admin Level Protection. In other words, it is easy to ensure that the command is not used by unwanted persons.

Only With Lua

Some servers use quite large and complicated additional command implementations that are implemented entirely by Lua scripting.