Clientcmd

From EventScripts Community Encyclopedia

New in EventScripts 1.5: See the Authorization FAQ for some detailed information on using clientcmd.


Overview

Syntax: clientcmd <create/delete> <say/console> <command name> [block to call] [capability name] [permission level]

Note: Command parameters are described inside the < and > characters. Optional parameters are contained within [ and ] characters.

Variation of this command that doesn't expand variables: none

Description

Registers a say or console command that will initiate the specified block of code when used by an authorized player, passing its parameters.

Parameters

  • create/delete - Denotes whether the command should be created or delete.
  • say/console - Denotes whether the command is a say or console command.
  • command name - Name of the command to be created or deleted
  • block to call - Name of block that should initiate when the command is used in script/block notation. (Only used for creating commands.)
  • capability name - Name of the capability players must have to use the command, see naming capabilities. (Only used for creating commands.)
  • permission level - Default permission level for the capability, can be #root, #admin, #poweruser, #known, #all. (Only used for creating commands.)


Examples

// ./addons/eventscripts/myaddon/es_myaddon.txt
// Say command only authorized players can execute
 
block load
{
   // Register a say command to the block mysaycmd with the 'use_broadcast' capability
   // If at this point an auth provider is not loaded the following line will error.
   // This works similar to es_regsaycmd only it allows capabilities/permissions
   clientcmd create say broadcast "myaddon/mysaycmd" "use_broadcast" #admin
   // Possible values for the recommend level include: #root, #admin, #poweruser, #known, #all
}
 
block mysaycmd
{
   // The user must be authorized so let's display the text
   es_set myaddon_userid 0
   es_set myaddon_username 0
   es_set myaddon_broadcast 0
 
   // Get the player's name
   es_getcmduserid myaddon_userid
   es_getplayername myaddon_username server_var(myaddon_userid)
 
   // Get the text to broadcast
   es_getargs myaddon_broadcast
 
   // Format the text to broadcast to include the player's name
   es_formatv myaddon_broadcast "%1: %2" myaddon_username myaddon_broadcast
 
   // Broadcast the message
   esnq es_xcentermsg server_var(myaddon_broadcast)
}
 
block unload
{
   // Now we delete the say command since we are done with it
   // This works similar to es_unregsaycmd
   clientcmd delete say broadcast
}
// Console commands work much the same way only they use:
clientcmd create console <command name> <block to call> <capability name> <permission level>
clientcmd delete console <command name>


Notes

  • Once a command is registered, trying to register the same command will fail on subsequents attempt. Overwriting is currently not supported so you can use es_exists to test for existence to avoid an error message in the console when trying to reregister. You can also help prevent this problem by deleting and registered clientcmds.


See also

blog comments powered by Disqus