SkriptTips and Techniques
Skript - Creating a Command
In this blog post, we'll cover the basics of creating a Skript command.
First off, the Syntax.
Custom commands are the most essential part of Skript. They allow your players to run command that you create that makes your server even more unique.
Just like anything else in Skript, in order to create a command you must follow a general syntax:
command /<command_name> <arguments>:. This is the syntax you'll have to use when creating a custom command.
Following this, we can add some command options, such as permission or description. You don't need to include any of these, but they just allow you to further modify your command.
Full list of command options (click) >
aliases: A list of aliases for your command (seperated by a comma).
executable by: Specifies who can use the command (console, players).
usage: A message sent to the user if they used the command incorrectly.
description: A description for the command.
permission: A permission required to run the command.
permission message: A message sent to the user if they don't have the permission required.
cooldown: A cooldown for the command.
cooldown message: A message sent to the user if the cooldown has not expired.
cooldown bypass: A permission required to bypass the cooldown of a command.
cooldown storage: A variable that the cooldown is stored in, it will stay even after the server restarts.
After we've included our command options, we must add a
trigger: below. The trigger tells Skript that we've finished with our options, and to run the code we type from this point on. Now, we indent and add our custom code. Your code should now look as follows:
command /<command_name> <argument>: permission: permission.use trigger: # code here
Arguments are just user inputs. You can add arguments to a command by specifying what type must be entered by adding it to the command using angled brackets such as
<string>. You can add multiple arguments of different types, such as
command /ban <player> <timespan>:.
In your code, you'll need to access these arguments. In order to do this, you can use
arg-(argument number starting at 1). For example to access the 'player' input in the above command, we would use
arg-1, and to access the timespan, we'd use
arg-2. There are alternatives to getting arguments, however I recommend using what we've just covered.
Currently, our arguments are mandatory and must be entered, however, we can make arguments optional by surrounding it in square brackets:
You can also add a default value for your arguments, meaning if a player does not enter anything for that argument, it will be set to a default value. You can do this by adding
= default value in the argument section. For example
command /command_name <string = "Hello World!">:.
Your Turn! - Test Yourself.
Note: the answer is directly below the instructions. No cheating!
- Make a command named calculate that takes two separate integer arguments, can only be ran by players with the permission
calc.use, has a cooldown of 10 seconds, and then broadcasts the two numbers added.