Jump to content

basic skript tutorial with examples


Recommended Posts

So you wanna learn skript.

First thing to start with would be commands, they're simple and easy to use and I will be using them throughout this tutorial.

To get started setup your server and install Skript (preferably the latest version)

After you've done that you're ready to get started, if any other plugins are necessary for certain things I will list that.

 

Commands

The first thing we would want to know is well, what is a command? A command is something we'd put in chat to run out certain skript.

An example command would be "/gamemode creative" which has the command: "/gamemode" and the text argument: "creative".

Now how do we make one in skript?

Well to make a basic command with no arguments we would do

command /ExampleCommand:
    trigger:
        send "You have executed this example command" to player

 

As you may have guessed this send the message "You have executed this example command" to the player.

But what if we want to have arguments, something the player can put into the command.

Maybe we want to make an add command?

command /add <integer> <integer>:
    trigger:
        send "%arg-1+arg-2%" to player

Now we add arguments with <argumentType>  and if we want an  optional argument we use [<argumentType>].

You can find all the argument types here, then search "Types" in the search bar.

Now that we know commands and how to add arguments why don't we make something useful, a /gmc command maybe? To set the player's gamemode to creative much easier, just like essentials.

Maybe we want to give it a permission to? And tell the player's without permission "YOU CANT USE THIS COMMAND" or something like that. 

Let me give you an example on how we would achieve this.

command /gmc:
    permission: tutorial.creative
    permission message: &cYou do not have permission to use this command 
    trigger:
        set player's gamemode to creative 
        send "&aYour gamemode has been set to creative." to player

Now, that is a bit longer there our other skripts and you may notice some new things: "permission" and "permission message"

What "permission" does is assure the player has the right permission to use the command because we wouldn't want your player's using the creative command to dupe their items! 

And "permission message" is the message it will send the player's that do not have the right permission to use the command.

So our user would see "You do not have permission to use this command" in red if they do not have permission.

We then change the player's gamemode with "set player's gamemode", I think that is self explanatory, and I hope you know what send does by now.

Now you know basic commands and arguments and how to give them permissions, why not try to make /gms yourself?

Events

The next thing we can move onto is events, let's start with a basic event, on join.

On join is called when a player joins the game so why don't we try to make a join message?

on join:
    set join message to "%player% has joined this amazing server."

As you can see, we are using "player" again but we have it in percent signs, this is because we're using a VARIABLE in a STRING.

These are in uppercase as they are types. I'll tend to do that as we move on. We put all our VARIABLES that are in STRINGS within percent signs. So if we were to put the DISPLAY NAME of the player, we would do "%player's display name%" instead of "%player%"

There are several events and you can find them all here.

Loops

Now you know how to use basic events and commands and arguments and even types, let's move onto loops.

There are 2 loops, for loop and while loop. The first one I'll show you is a for loop.

command /ForLoop <integer>:
    trigger:
        loop arg-1 times:
            send "hi x%loop-value%" to player

you can see I've used multiple of the techniques I have showed you here to make this command. 

This loop (arg-1) which is whatever the player inputs to the command e.g /ForLoop 5 would loop 5 times the code in the indentation.

Now a while loop, heres an example of that:

on join:
    while player is online:
        send "hi nerd" to player 
        wait 1 second 

This is in the on join event which then runs the "while player is online" which will run all the code, whilst the player is online, as fast as it can.

We have the wait 1 second to prevent it from crashing the server.

Now we've finished with basic loops we can do functions.

Functions

First things first is defining a function, we do that with the keyword function then we put the name of the function followered with parenthesis, function test(): heres an example function

function sayHi(p:player😞
    send "hi" to {_p}

Now to add arguments to a function we put the variable we want to store it in, in my case p and then a colon then the type, in my case PLAYER. we index these functions with {_p} so you will notice I did send "hi" to {_p} instead of player as in functions there is no player.

Now how would we use this? Simple

 

command /hi:
    trigger:
        sayHi(player)

 To see it's a function we see the parenthesis () to call the function and in the parenthesis are the arguments we pass to the function. These are useful to pass data across scopes.

Returning data from functions:

function add(x:integer,y:integer):: integer:
    return {_x} + {_y}
 
command /add:
    trigger:
        "%add(1,2)%"
 

We have :: with the return type that we want then our code with a return at the end this returns whatever data is after the return if it is the specified type. 

This allows us to run code somewhere else and use it in our specified location e.g our command.

 

 

That's all I have time to cover right now,

if there is anything else you'd like me to put examples for or explain then let me know

in the replies or in my dms 🙂

Hope you found this informative, I have written this late at night so please 

don't criticise my errors to much.

Try and help each other in the replies if possible.

  • Like 1
Link to comment
Share on other sites

invision moment

image.png.e912002b1b24868439d9096302efceec.png

also you forgot to put a send or other effect in the last line

image.png.a5a2dbc36d5022ae149687363f973cf9.png

take it as constructive criticism 😉

Edited by UntitledGoose

VIP since January 7th, 2020

Support since September 19th, 2020

Helper since November 3rd, 2020

Moderator since March 8th, 2021

unknown.png

5.png.e14b1bf83edf0ac2edc1bfb822177184.png

image.png.fe30b7b2c0be5a541ba4ed2187b23030.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...