Custom Commands
Skript allows you to easily create custom commands in your scripts, like the following:
# A simple "broadcast" command for broadcasting the text argument.
# This is accessible only to users with the "skript.example.broadcast" permission.
command /broadcast <text>:
permission: skript.example.broadcast
description: Broadcasts a message to everyone including console.
trigger:
broadcast arg-textThat's a simple example, but you can do much more complex things with custom commands! That "/broadcast" command only shows a few of the options you have available when creating a custom command.
Command Pattern
Here's the full list of features that you can use in your commands. They're all optional, except for the trigger section. We'll explain each one individually below.
command /<command name> <arguments>:
prefix: # command prefix, defaults to "skript"
aliases: # alternate command names
executable by: # players or console
usage: # the message that explains how to use the command
description: # the command's description
permission: # the permission needed to use the command
permission message: # the message sent to users without the correct permissions
cooldown: # a timespan, during which the command can't be used again
cooldown message: # the message sent when the command is used again too fast
cooldown bypass: # the permission necessary to bypass the cooldown
cooldown storage: # what variable to store the cooldown in
trigger:
# The code to run goes here.Command Name
The command name is what comes immediately after command. It can consist of any characters you want, except for space. Additionally, the / in front of the command is optional. This means command /broadcast and command broadcast are the same. Here are a few examples:
Arguments
Arguments follow the command name, and are separated by spaces.
You can make arguments optional by surrounding them with square brackets [], like this: command /kill [all entities].
However, the real power in arguments comes from type arguments. These allow a command to take in a type, like command /kill <player>. Type arguments must be surrounded by angle brackets <> and can also be made optional by surrounding them with square brackets: [<player>].
The argument can then be referenced in the trigger section by arg-1 or argument 1 or a number of other ways. You can also name type variables like so: <name:type>, which can then be referenced as a local variable: {_name}. Here's the full pattern for arguments:
Arguments can be used in a lot of different ways, so I'll provide some examples ranging from the simplest possible to more complex uses.
Prefix
A prefix is something all commands have, and it goes before the command when Minecraft registers them. You do not have to type this out when executing commands, but you can. The prefix, by default, is skript, which means if you leave this blank your command (with its prefix) will look like /skript:commandName.
If two commands have the same name but different prefixes, only one will be registered.
Aliases
Aliases are alternate names for your command. For example, the command /teleport could have an alias /tp. Like in the command name, the forward slash (/) is optional.
Aliases will not overwrite commands registered by other plugins. Say another plugin registers /spawn, and you have the following command:
If you run /spawn, that other plugin's command will run. You'll need to register a new command with that name and have it run your first command.
Executable by
Who can execute this command. The options are players, console, or players and console.
Description
The description of the command. Other plugins can get/show this with /help, like /help teleport.
Permission
The permission required to execute this command. The message sent to players without the proper permission can be customized with the permission message: field.
Cooldowns
This field takes a timespan that the player must wait out before executing the command again. The cooldown can be canceled with cancel the cooldown (documentation here). Like with the permissions, you can change the default cooldown message with the cooldown message: field. The remaining time of the cooldown can be displayed with %remaining time% Additionally, you can store the cooldown in a variable with cooldown storage:, in order to store the cooldown even when the server restarts.
There are also a number of expressions you can use to interact with the cooldowns of commands. You can get the remaining time with remaining time, the elapsed time with elapsed time, and the total time with cooldown time. You can also get the bypass permission with bypass permission.
If you've enabled keep command last usage dates in your config.sk file, you can get the last time the player used the command with last usage date.
The Trigger Section
This section is where all the code the command should run is located. I'm sure you're familiar with how it works from the previous examples, but in case you're still unsure, some more examples of commands will be displayed here. You can see these example commands and more in the /plugins/Skript/scripts/-examples/commands.sk file in your server.
Written by Sovde, parts used with permission from blueyescat's tutorial on SkriptHub.
Last updated