Tutorial by: Blueyescat


Creating commands is very easy in Skript.

The basic pattern of a command definition is as follows:

command /<command name> <arguments>:
  aliases:
  executable by:
  usage:
  description:
  permission:
  permission message:
  cooldown: <timespan>
  cooldown message:
  cooldown bypass:
  cooldown storage: <variable>
  trigger:
    <the code to run>

Note: All entries are optional, and trigger is a section.

Command Name (Required)

Command name is the basically the command. You can use any character in the command name except the space character. If you use the space character in the command name, the text after the space character becomes the arguments. The slash character (/) before the command name is optional (that doesn't mean you can execute the command without slash).

Arguments (Optional)

You can write any text for arguments.
You can make parts of the arguments optional by putting them into [square brackets].

Type Arguments
You can also limit the type of an argument by using the pattern: <type = default value>
For example an argument that you must enter a player name or an item.

An example command:

command /kill <entity types> [in [the] radius <number = 20>]:

This can be used like /kill zombies, /kill creepers and animals in radius 100 or /kill monsters in the radius 6. The radius will default to 20 if isn't entered.

Aliases

Basically sub-commands of the command. Separated using commas.
Example: /alias1, alias2, /alias1 (The slash character is optional)

Executable By

Specifies what can use the command. So console and players.
Examples: console, players, the console and players

Usage

The message to be send if the command isn't used correctly. Like when you don't enter required parts, or when you don't use the required type for a type argument.

Description

The description of the command. Other plugins can get/show this.

The message: Correct usage: <the usage message>

If this entry isn't specified, the usage message will be the code you used to create the command.
You can edit the "Correct usage:" message from the english.lang file in Skript's JAR file only.

Permission

The required permission to execute the command. A message will be send if the executor doesn't have the specified permission.

Permission Message

You can edit the default no permission message using this entry.

Cooldown

Basically, cooldown time to use the command again. Example: cooldown: 10 seconds
Please note that command cooldowns will be reset when the server stops. To avoid that, use the command storage entry.

The cooldown can be canceled using this effect in the code of the command.

Cooldown Message

You can edit the default cooldown error message using this entry. You can use the cooldown info expression to custom the message.

Cooldown Permission

Permission to bypass the cooldown.

Cooldown Storage

A variable to store the cooldown to be able to use long cooldowns, that won't be reset when the server stops.

The Code to Run

Basically, the code to run if the command is executed successfully. This must be in the trigger section.

Getting the Entered Arguments

The syntaxes below is used to get an entered argument in the code.

[the] last arg[ument][s]
[the] arg[ument][s](-| )%number%
[the] (1st|2nd|3rd|4-90th) arg[ument][s]
[the] arg[ument][s]
[the] %type%( |-)arg[ument][( |-)%number%]
[the] arg[ument]( |-)%type%[( |-)%number%]

Examples:

the last argument
arg-1
argument 6
13th arguments
the argument
the player argument
arg-item type-3


The return type of this expression will be the type of the argument. For example you can do give arg-1 to player-argument.



An Example Command

command /cake:
    aliases: /getcake, /receivecake, cakes, /iwantcake
    description: Recieve a cake, but you can only do this once per day!
    permission: cake.is_a_lie
    executable by: players
    cooldown: a day
    cooldown storage: {cake::%player's uuid%}
    cooldown message: One cake is enough for you today! Try again %remaining time% later.
    cooldown bypass: cake.eater
    trigger:
        if the player has space for a cake:
            give a cake to the player
        else:
            send "You do not have enough space in your inventory to hold the cake!"
            cancel the cooldown

Did you find Blueyescat's tutorial helpful?


You must be logged in to comment

  • Oct. 18, 2018, 1:01 p.m. - IT_CHI  

    yes its very helpful and very easy to understand

    1 |