Skript Custom Commands For Dummies. (Part 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!

Purple Pixel

Member
Sep 23, 2020
40
4
8
26
(In this tutorial I am using 2 spaces to indent.)

Custom Commands:

Custom commands can come in many different ways. From simple commands to very complicated ones. For beginners, this is usually how you would want to layout your skript command.
Code:
command /example:
  permission:
  trigger:
There are many things that we can add to this command however, one thing to keep in mind is that in all custom commands you are probably going to see "trigger:". This is because whatever is in the trigger section is the code that is going to be run.

Next, let's talk about some things we can do with the actual code. I am going to give an example.
Code:
command /example:
  trigger:
    send "Hello!" to player
So we have a skript/script now. However, it is available to all players. Let's say we want only people with a certain permission to be able to run it. This is where "permission:" comes in. Usually for whatever permissions plugin you use, you can just simply put the permission as "server.admin" for example. I recommend using the LuckPerms plugin. However, it is up to you to decide.
Code:
command /example:
  permission: server.admin
  trigger:
    send "Hello!" to player
If you do use luckperms you can just run the command "/lp user/group groupname/username permission set server.admin true". For permissions, you can also just say "op" if you want only server operators to have access to it.

Another thing that I suggest for custom commands you add a "permission message:" to your script. It will tell players that they do not have access to the command instead of them just running the command and nothing happens.
Code:
command /example:
  permission: server.admin
  permission message: You do not have permission to run that command!
  trigger:
    send "Hello!" to player

Ok. So now you have the real basics down. However, you want to do more. Here are just some of the examples of what you could do.
Code:
command /example:
  permission: server.admin
  permission message:
  trigger:
    give player wooden pickaxe named "Cool Pickaxe"
Code:
command /example:
  permission: op
  permission message: Only server operators can run that command!
  trigger:
    execute command "/title @a title {""text"":""Hello Player!"",""color"":""gold""}"
Code:
command /disco:
  permission: player.disco
  permission message: You cannot execute that command!
  trigger:
    loop 5 times:
      wait 1 second
      execute command "/title @a title {""text"":""\o>"",""color"":""gold""}"
      wait  1 second
      execute command "/title @a title {""text"":""<o/"",""color"":""gold""}"

So now you can do some stuff with it and you got some inspiration. Well, let me introduce something else to you, arguments. Arguments play a HUGE part in skript. Most times arguments look like this.
Code:
command /example [<string>] [<player>]:
You can refer to these arguments inside your code in many ways. When you are executing a command in your code or putting an argument inside quotes, you usually want to put "%arg-1%" depending on which argument you are referring to it could also be "%arg-3%" or "%arg-2%". Example:
Code:
command /pickaxe [<player>]:
  permission: server.player
  trigger:
    execute command "/give %arg-1% wooden_pickaxe"
However, if you want to use this outside of a command or quotes use the following example.
Code:
command /pickaxe [<player>]:
  permission: server.player
  trigger:
    give arg-1 wooden pickaxe
In part 2 of this tutorial, I will talk more in depth about these concepts. I will also introduce loops and if statements.
(Hopefully this helped)