General Tutorial

Give a man a fish, feed him for a day. Teach a man to fish, feed him for a lifetime.

The original goal of Skript was to make a simple way for non-programmers to make their own mini plugins (called scripts). I feel that this purpose has been lost due to the lack of understanding of how to script. This tutorial will teach even the newest person to Skript, how to make this wonderful plugin work on his or her server.

Step 1: Read over the documentation

Njolbrim's website has all of the expressions, conditions and effects that you will ever need on your server. I am not here to go over every single one of these but I will reference them in talking about commands and variables. It is also very helpful when you are programing your own, so that you know the limitations of what you can do, as well as the syntax needed to get your task accomplished. A link to the documentation site can be found on the main page of this plugin, as well as from the link below.

http://njol.ch/projects/skript/doc

Variables, Loops, Commands, Conditionals and Events

During your time scripting for your server, you will undoubtedly use at least one, if not all, of the five things mentioned above. Below I have outlined what each can do, as well as how and when to use them.

Events

Events are called when something happens. So when a player clicks on something, takes damage, dies, or when a mob does something, or even when the environment does something else completely independent of entity interaction. This will allow you to make something happen when something else happens. For example:

on explode:
        cancel event

Note the spacing. Every time there is a colon, then next line down is indented one more. You can either use a tab or 8 spaces. You cannot use tabs and spaces to indent different lines of a script. I prefer to use the tab key because I only need to hit it once per indent. The actual event in the code is pretty simple. When an explosion happens, cancel it. This would be useful if you didn't want TNT, creepers, or even the enderdragon to destroy stuff on your server. Keep in mind that this cancels the actual explosion event, meaning that players will not get hurt either. So this script is very simple when an explosion happens, stop it. You can easily change the outcome to be whatever you want. Another example could be as dramatic as killing all players on the server.

Conditionals

Conditionals are an essential part of any script. They are pieces of code that check to see if a condition is met before executing the rest of the script. An example with permissions is below:

on rightclick:
        player has permission "skript.boom"
        create explosion with force 3 at targeted block

This will create an explosion that is slightly smaller than TNT, but it will only do so if the player has the correct permission. Conditionals can also be used to check things like if the player has an item in his/her inventory, or what a line on a sign says. You can even use multiple conditionals so that an event has to meet all of them before moving on.

on rightclick:
        block is a sign
        line 1 of sign is "[Shop]"
        player has permission "skript.shop"
        player has 2 gold nuggets
        remove 2 gold nuggets from player
        give player 1 bread
        message "<light green>You bought a bread."

In this script the player must right click on a sign with the first line of "[Shop]", have the correct permission, and 2 gold nuggets. Then the effects occur. In this case the player will loose 2 gold nuggets and receive some bread. To learn more visit the website above.

Commands

Every server admin knows about commands, its the way you run your server. Skript allows you to make your own custom commands. These commands are very similar to events, except that you get to define the event. The simple version of this is that the event is activated whenever a player types in the command that you define on the event line. To get a better idea of what I'm talking about, look to the example below:

command /hi:
        permission: skript.hi
        trigger:
                message "hi"

This simple command sends a message to the player who typed the command. The first line is the "event" line. First we say that we want to define a command. then we say what that command is. Then we give it things like a permission and usage. Finally, we add the trigger, which is what we want the command to do assuming the player has permission to do so. You can check the website mentioned above for more info on defining parts of a command like the usage. You can also make more complex commands that can get information, like who you want this command to affect and so forth. Look to the example below to see what I mean:

command /hi <player>:
        permission: skript.hi
        trigger:
                send "hi" to argument

This command will send the same message as before, but this time allows the player typing the command to send it to someone else as well. The reason we use the send effect this time is because the message effect only sends the message to the player in the event, i.e. the player who typed the command. With the send effect we can send a message to someone. The argument is whatever was entered in the command. So if you typed "/hi demon_penguin" then the effect would be replaced with "send "hi" to demon_penguin" thus sending the "hi" message to me. Again you can look to the website to find out more about commands.

Loops

Loops can be used to complete repetitive tasks that would otherwise be much more complicated. For example if you wanted to see if there was a chest near you, you would need to check every block in a certain distance to see if it was a chest. This can be done very easily using a loop:

command /chest:
        trigger:
                loop blocks in radius 3 around player:
                        loop-block is a chest
                        message "There is a chest at %location of loop-block%"

The percent signs indicate that there is a value that will replace that part of the text. In this case there will be an x, y, and z value instead of %location of loop-block% The "loop-block" part of the code refers to whatever block the loop is checking. The loop will look at every block within a 3 block radius of the player and then run the code we have indented under it. And because we are using a command to trigger the loop, we can add arguments and allow the player to choose how far the loop will search.

command /chest <integer=3>:
        trigger:
                loop blocks in radius argument around player:
                        loop-block is a chest
                        message "There is a chest at %location of loop-block%"

Here we also set a default value for the command, just in case the player didn't enter one. In the loop expression we see the number has been replaced with "argument" This means that whatever number you typed in the command will be put here instead. If a number was not entered in this command, then 3 will be used because it was set to be the default value. If you would like to see exactly how far a radius value is, then you can use this script to make a sphere out of blocks so you can visibly see the size.

command /sphere <integer=3>:
        trigger:
                loop blocks in radius argument around player:
                        loop-block is air
                        set loop-block to stone
                set {clear.block} to location of player
                set {clear.radius} to argument

command /clear:
        trigger:
                loop blocks in radius {clear.radius} around {clear.block}:
                        loop-block is stone
                        set loop-block to air

The /clear command is so that you can easily delete the sphere that you made. Also because you will be at the center of the sphere, you will need a way to teleport yourself out. These commands may cause a small amount of damage to your server if used close to the ground. Please use them while flying to get the full effect. The parts of code with the curly brackets {} are called variables. You will learn about them in the next section. If you want to learn more about loops you can check the website that was mentioned above.

Variables

Variables are used to store information under a name. Think of it like a box with a label on it. When you want to get the info you put in that box, you just go look for the one with the right label on it. Skript does the same thing with variables, which are the computers equivalent of a box. You save information like this:

set {variable.name.goes.here} to true

Values for variables can be true/false, a location (x,y,z) or a plain old number. The reason for this is so that we can get this information later. So maybe we want to check if a command was performed by this player before. We would do it like so:

command /sethome:
        trigger:
                set {home} to location of player

command /home:
        trigger:
                teleport player to {home}

Every time a variable is used in a script you must must put it in curly brackets {} to tell Skript that you are using a variable. Above is a very simple home script. We store the location of the player in a box called {home} When the player types a different command like "/home" we go back to that variable to get the location out so we know where to teleport the player too. This does not clear the value out of the box, it's more like reading it, then putting it back. When programming, you always need to think about what the user/player could do wrong. For example the player though that they sethome back in their base, but forgot to do so. What happens if they try and use /home and there is no where to teleport them to? That is when you use an if statement. This statement checks if something is the way it is supposed to be, and if it's not, then it will do something different than the rest of the script. There is no default error messages that will be sent to the player, so you will need to make your own.

command /sethome:
        trigger:
                set {home} to location of player

command /home:
        trigger:
                if {home} is not set:
                        message "<red>You need to set a home first!"
                        stop trigger
                teleport player to {home}

Now if a player tries to do /home they will get an error message and then the rest of the trigger will stop. If you forget to stop the trigger, then the rest of the events not indented under the if statement will continue as normal. Also if the if statement is false, then none of the code indented under it will be read and the player will not get an error message. The main problem with our current Skript is that if one person sets their home location under the {home} variable, then anyone who uses /home will be sent to that persons home, and if someone sets their home after another player, it will override the other location and only save the newest one. The way to fix this is use expressions. These are things that will be inserted depending on who is triggering the event. In the case of the command event, it is whomever typed the command. So in order to set a different home per player we can actually put the player's name in the variable itself. It looks like this:

command /sethome:
        trigger:
                set {home.%player%} to location of player

command /home:
        trigger:
                if {home.%player%} is not set:
                        message "<red>You need to set a home first!"
                        stop trigger
                teleport player to {home.%player%}

Now the player's name who set their home is in the variable. So when it checks if the variable is set, it will check {home.demon_penguin} for me and {home.whateveryouruseernameis} for everyone else. With this script every player will have their own home location.

Closing Notes:

Remember that all of the stuff you learned under command section about if statements and stuff like that can be used in any trigger. This includes any event. And as a final reminder if you wan to learn more about what effects you can do and things like that, check out the documentation website above.

If you have any questions about what I have said here, or have any kind of issue with a script, to ask on the help forum. http://dev.bukkit.org/server-mods/skript/forum/help/

-Demon