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: &lt;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, /alias3 (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.

The message: Correct usage: &lt;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.

Description

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

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 add some useful info like remaining time to the message.

Cooldown Bypass

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 usages:

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. So you can do give arg-1 to player-argument.




Examples

A really simple give item command
command /give <item> [to] <player=%player%>:
    aliases: /i, /item
    trigger:
        # we made the 2nd argument to default to the executor player,
        # but if the command is used in the console, there is no player, so the arg-2 is not set!
        # no need to a 'if executor is console' check because the 2nd argument will always use the executor player if possible, if it is not set, means used in the console.
        if arg-2 is not set:
            send "&cThe console can't have items! Please specify a player to give the item."
            stop
        # since there is only one argument with the 'item' type, we can just use `item-argument`
        give item-argument to arg-2
        send "&aGiven &6%item-argument% &ato &6%arg-2%&a."

# /i 64 barriers
# /give dirt Notch
# /give a stone to Notch
A command with many properties including cooldown
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

    2 |     
  • Aug. 27, 2019, 4:02 p.m. - PawPawDude  

    This category -- commands and arguments and their usage -- desperately needs more working examples. This is one of the most vague areas of Skript being poorly supported with solid examples, especially how to use arguments, syntactically. The examples given here by @Blueyescat are excellent, but sorely needing more elaboration and examples of use. The core problem with Skript is the variety of ways a thing can be expressed. Though the intent must've been to make Skript a "natural language" device, it only made things more complicated and unclear about what any given syntax might be. Thus, the lack of a central repository of usage examples of all functions creates a major hurdle for new users.

    |     
    Aug. 28, 2019, 10 a.m. - Blueyescat Moderator  

    Hi, i'm not sure about what do you actually mean. but i will try to add detailed examples for using arguments.

    |     
    Aug. 28, 2019, 10:20 a.m. - Blueyescat Moderator  

    Done, thanks for the review.

    |     
  • June 6, 2021, 2:53 a.m. - PogJaws  

    how do you do an ad reward system? like when someone does /ad {server name} they join back that server and get an item

    |     
    June 26, 2021, 11:35 p.m. - AgentGamerPro  

    This isn't Minehut

    |     
    July 21, 2021, 12:21 a.m. - NenadKingPRO  

    What's the problem with asking for help for a Minehut server? this is a site where you can share your scripts/teach people how to use skript. I'm here to learn scripting for my own Minehut server too, and I'm assuming he's here for the same thing.

    |     
  • Oct. 21, 2022, 8:56 p.m. - Lemon  

    Hey i do not know what ive done wrong:

    on command "/credits":
    make player execute command "/credits"
    execute console command "/say Test"
    cancel the event

    im trying to make a credits command but whenever i do it, it keeps repeating so ive added the "cancel the event" but now its saying its invalid

    |     
    Jan. 5, 2023, 7:53 p.m. - 1_x409  

    You forgot "trigger:"

    |     
    April 10, 2023, 4:41 a.m. - Tyler the creator  

    So what you are doing is making the player run the command then the
    make player execute command "/credits"
    has the code run the script again but it wont cancel if it gets ran before being able to hit cancel, the event would be triggered by well a trigger so the fixed code could be something along the lines of:

    command /credits:
    description: a sample credits command
    trigger:
    execute console command "say Test"

        if I were you I would make it something such as this:
    
        options:
    prefix: &4[&cYour Prefix here&4]&r
    

    command /dailycredits:
    cooldown: 24 hours
    cooldown message: {@prefix} Hey there you already claimed your daily credits check back in %remaining time%
    cooldown storage: {credits::%player's uuid%}
    trigger:
    send "{@prefix} You claimed your tokens for today, check back in one day!"

    |     
  • Nov. 2, 2023, 3:36 p.m. - i7modeee  

    That was GREAT i really enjoyed readin this, thanks!

    |     
  • Jan. 31, 2024, 10:41 a.m. - bumbyboo.  

    so helpful

    |     
  • April 13, 2024, 10:35 p.m. - Nenemchocolito  

    Wonderful tutorial!

    |