Skript Using "Loops"

  • 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!

acai

Active Member
Oct 23, 2020
89
1
8
Hello! Welcome to my second tutorial.
This is a very simple lesson, but I am using it in a way some people would not.
We will be using loops to count players, entities, and blocks today!
How do I use loops, you may ask? After an event and the correct syntax, you can use a loop.

Let's start with an event, shall we?
I will be using Every 5 seconds for this event.
Code:
every 5 seconds:

Now, let's add the "loop". I will be using "loop all players:", which will loop a command for every player in your server.
Code:
every 5 seconds:
  loop all players:

What should you do next to count the players? First, we must set the variable to 0, with the "on script load:" event. I prefer this to options, because options is more complicated than an event.

Code:
on script load:
  set {pcount} to 0

Next, we must add on to the every 5 seconds event. Now we can add other commands regarding variables.
Code:
every 5 seconds:
  loop all players:
    add 1 to {pcount}

You can repeat this with anything! Blocks, entities, and mobs!
Instead of "mobs", you will use "loop-mob".
Instead of "player", you will use "loop-player".
Instead of "entity", you will use "loop-entity".
And so on, and so on. Basically, any type of entity you'll be able to use outside of loops, just with "loop-" before the type.