1. Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Commands

Apr 1, 2018
Commands
  • Skript Commands

    Creating custom commands



    Creating custom commands is not difficult with Skript, but remember that Skript is not suitable for creating aliases of other plugins' commands, only for creating completely new commands, as arguments are parsed differently than how most other plugins do it.

    The basic syntax of a custom command definition is a follows:

    Code (Skript):
    1. command /commandname <arguments>: #Arguments are explained below
    2.     description: A description of what this command does
    3.     usage: How to use the command, e.g. /commandname <arguments>    #If omitted this defaults to something similar to how the command was defined above.
    4.     permission: required.permission.to.use.this.command   #If omitted this command can be used by everyone regardless of permissions.
    5.     permission message: Message to send if the player doesn't have the required permission to use this command    #If omitted this defaults to "You don't have the required permission to use this command"
    6.     executable by: players/console/players and console    #If omitted this command can be executed by players and the console.
    7.     aliases: /c, /comname.    #A list of aliases of the command which are usually abbreviations of the command
    8.     trigger:
    9.         # put conditions and effects here that will be checked/executed when the command is used.
    10.  
    A command's arguments look like <argtype> or <argtype = default value>, e.g. <item> or <item=water bucket>. The default value can also be an expression, in which case it has to be put into percent signs: <item=%tool%>.

    Arguments can also be mixed with text, e.g. a /give command definition can look like the following: command /give <items> to <player>: This command could then be used like /give a diamond to Njol.


    You can make parts of the arguments of a command optional by putting them into [square brackets], e.g. a command that finds mobs of a certain type within a given radius can look like command /find <entity type> [in radius <integer=100>]. This command can be used like /find creepers or /find zombies in radius 20, where the radius will default to 100 if omitted.



    In the likely case that this was confusing here's a simple example command:


    Code (Skript):
    1. #A simple ID command to get the id of the held item
    2. command /id <item=%tool%>:
    3.     description: Find the ID of the item you're holding, or any given one.
    4.     usage: /id [type]
    5.     executable by: players
    6.     trigger:
    7.         message "The ID of %arg 1% is %id of arg 1%"
    8.  
    Custom commands can be defined anywhere in a script file; the command basically replaces the event a trigger would normally need. If a command is related to some triggers I recommend to put the command into the same file as the triggers, otherwise put it into whatever file fits best. You could e.g. create a big file that contains all standalone commands, or create a separate file for every command.



    The following is an example of a combined trigger/command script which allows you to spawn a healer villager that can heal players for gold:

    Code (Skript):
    1. command /healer:
    2. permission: healer.create
    3. description: spawns a healer villager which can heal players
    4. trigger:
    5.     spawn a priest
    6.     set {%spawned villager%.healer} to true
    7.  
    8. on rightclick on a priest:
    9.     player has permission "healer.use"
    10.     player is holding a gold ingot
    11.     {%clicked villager%.healer} is true
    12.     player's health is below 10
    13.     heal the player by 5 hearts
    14.     remove 1 gold ingot from the player