Patterns: |
|
Since: | 1.0 |
Conditional sections
if: executed when its condition is true
else if: executed if all previous chained conditionals weren't executed, and its condition is true
else: executed if all previous chained conditionals weren't executed
parse if: a special case of 'if' condition that its code will not be parsed if the condition is not true
else parse if: another special case of 'else if' condition that its code will not be parsed if all previous chained conditionals weren't executed, and its condition is true
if: executed when its condition is true
else if: executed if all previous chained conditionals weren't executed, and its condition is true
else: executed if all previous chained conditionals weren't executed
parse if: a special case of 'if' condition that its code will not be parsed if the condition is not true
else parse if: another special case of 'else if' condition that its code will not be parsed if all previous chained conditionals weren't executed, and its condition is true
Examples:
if player's health is greater than or equal to 4:
send "Your health is okay so far but be careful!"
else if player's health is greater than 2:
send "You need to heal ASAP, your health is very low!"
else: # Less than 2 hearts
send "You are about to DIE if you don't heal NOW. You have only %player's health% heart(s)!"
parse if plugin "SomePluginName" is enabled: # parse if %condition%
# This code will only be executed if the condition used is met otherwise Skript will not parse this section therefore will not give any errors/info about this section
send "Your health is okay so far but be careful!"
else if player's health is greater than 2:
send "You need to heal ASAP, your health is very low!"
else: # Less than 2 hearts
send "You are about to DIE if you don't heal NOW. You have only %player's health% heart(s)!"
parse if plugin "SomePluginName" is enabled: # parse if %condition%
# This code will only be executed if the condition used is met otherwise Skript will not parse this section therefore will not give any errors/info about this section
Patterns: |
|
Since: | 2.10 |
Filters a variable list based on the supplied conditions. Unlike the filter expression, this effect maintains the indices of the filtered list.
It also supports filtering based on meeting any of the given criteria, rather than all, like multi-line if statements.
It also supports filtering based on meeting any of the given criteria, rather than all, like multi-line if statements.
Examples:
set {_a::*} to integers between -10 and 10
filter {_a::*} to match:
input is a number
mod(input, 2) = 0
input > 0
send {_a::*} # sends 2, 4, 6, 8, and 10
filter {_a::*} to match:
input is a number
mod(input, 2) = 0
input > 0
send {_a::*} # sends 2, 4, 6, 8, and 10
Patterns: | |
Since: | 2.10 |
A specialised loop section run for each element in a list. Unlike the basic loop, this is designed for extracting the key & value from pairs. The loop element's key/index and value can be stored in a variable for convenience.
When looping a simple (non-indexed) set of values, e.g. all players, the index will be the loop counter number.
Examples:
for each {_player} in players:
send "Hello %{_player}%!" to {_player}
loop {_item} in {list of items::*}:
broadcast {_item}'s name
for each key {_index} in {list of items::*}:
broadcast {_index}
loop key {_index} and value {_value} in {list of items::*}:
broadcast "%{_index}% = %{_value}%"
for each {_index}, {_value} in {my list::*}:
broadcast "%{_index}% = %{_value}%"
send "Hello %{_player}%!" to {_player}
loop {_item} in {list of items::*}:
broadcast {_item}'s name
for each key {_index} in {list of items::*}:
broadcast {_index}
loop key {_index} and value {_value} in {list of items::*}:
broadcast "%{_index}% = %{_value}%"
for each {_index}, {_value} in {my list::*}:
broadcast "%{_index}% = %{_value}%"
Patterns: |
|
Since: | 1.0 |
Loop sections repeat their code with multiple values.
A loop will loop through all elements of the given expression, e.g. all players, worlds, items, etc. The conditions & effects inside the loop will be executed for every of those elements, which can be accessed with ‘loop-’, e.g.
Loopable Values
All expressions that represent more than one value, e.g. ‘all players’, ‘worlds’, etc., as well as list variables, can be looped. You can also use a list of expressions, e.g.
List Variables
When looping list variables, you can also use
A loop will loop through all elements of the given expression, e.g. all players, worlds, items, etc. The conditions & effects inside the loop will be executed for every of those elements, which can be accessed with ‘loop-
send "hello" to loop-player
. When a condition inside a loop is not fulfilled the loop will start over with the next element of the loop. You can however use stop loop
to exit the loop completely and resume code execution after the end of the loop.Loopable Values
All expressions that represent more than one value, e.g. ‘all players’, ‘worlds’, etc., as well as list variables, can be looped. You can also use a list of expressions, e.g.
loop the victim and the attacker
, to execute the same code for only a few values.List Variables
When looping list variables, you can also use
loop-index
in addition to loop-value
inside the loop. loop-value
is the value of the currently looped variable, and loop-index
is the last part of the variable's name (the part where the list variable has its asterisk *). Examples:
loop all players:
send "Hello %loop-player%!" to loop-player
loop items in player's inventory:
if loop-item is dirt:
set loop-item to air
loop 10 times:
send title "%11 - loop-value%" and subtitle "seconds left until the game begins" to player for 1 second # 10, 9, 8 etc.
wait 1 second
loop {Coins::*}:
set {Coins::%loop-index%} to loop-value + 5 # Same as "add 5 to {Coins::%loop-index%}" where loop-index is the uuid of the player and loop-value is the number of coins for the player
loop shuffled (integers between 0 and 8):
if all:
previous loop-value = 1
loop-value = 4
next loop-value = 8
then:
kill all players
send "Hello %loop-player%!" to loop-player
loop items in player's inventory:
if loop-item is dirt:
set loop-item to air
loop 10 times:
send title "%11 - loop-value%" and subtitle "seconds left until the game begins" to player for 1 second # 10, 9, 8 etc.
wait 1 second
loop {Coins::*}:
set {Coins::%loop-index%} to loop-value + 5 # Same as "add 5 to {Coins::%loop-index%}" where loop-index is the uuid of the player and loop-value is the number of coins for the player
loop shuffled (integers between 0 and 8):
if all:
previous loop-value = 1
loop-value = 4
next loop-value = 8
then:
kill all players
Patterns: |
|
Since: | 2.10 |
Shoots a projectile (or any other entity) from a given entity or location.
Examples:
shoot arrow from all players at speed 2
shoot a pig from all players:
add event-entity to {_projectiles::*}
shoot a pig from all players:
add event-entity to {_projectiles::*}
Patterns: |
|
Since: | 1.0, 2.6.1 (with section), 2.8.6 (dropped items), 2.10 (entity snapshots) |
Requirements: | Minecraft 1.20.2+ (entity snapshots) |
Spawns entities. This can be used as an effect and as a section.
If it is used as a section, the section is run before the entity is added to the world.
You can modify the entity in this section, using for example 'event-entity' or 'cow'.
Do note that other event values, such as 'player', won't work in this section.
If you're spawning a display and want it to be empty on initialization, like not having a block display be stone, set hidden config node 'spawn empty displays' to true.
Note that when spawning an entity via entity snapshots, the code within the section will not run instantaneously as compared to spawning normally (via 'a zombie').
If it is used as a section, the section is run before the entity is added to the world.
You can modify the entity in this section, using for example 'event-entity' or 'cow'.
Do note that other event values, such as 'player', won't work in this section.
If you're spawning a display and want it to be empty on initialization, like not having a block display be stone, set hidden config node 'spawn empty displays' to true.
Note that when spawning an entity via entity snapshots, the code within the section will not run instantaneously as compared to spawning normally (via 'a zombie').
Examples:
spawn 3 creepers at the targeted block
spawn a ghast 5 meters above the player
spawn a zombie at the player:
set name of the zombie to ""
spawn a block display of a ladder[waterlogged=true] at location above player:
set billboard of event-display to center # allows the display to rotate around the center axis
spawn a ghast 5 meters above the player
spawn a zombie at the player:
set name of the zombie to ""
spawn a block display of a ladder[waterlogged=true] at location above player:
set billboard of event-display to center # allows the display to rotate around the center axis
Patterns: |
|
Since: | 2.0, 2.6 (do while) |
While Loop sections are loops that will just keep repeating as long as a condition is met.
Examples:
while size of all players < 5:
send "More players are needed to begin the adventure" to all players
wait 5 seconds
set {_counter} to 1
do while {_counter} > 1: # false but will increase {_counter} by 1 then get out
add 1 to {_counter}
# Be careful when using while loops with conditions that are almost
# always true for a long time without using 'wait %timespan%' inside it,
# otherwise it will probably hang and crash your server.
while player is online:
give player 1 dirt
wait 1 second # without using a delay effect the server will crash
send "More players are needed to begin the adventure" to all players
wait 5 seconds
set {_counter} to 1
do while {_counter} > 1: # false but will increase {_counter} by 1 then get out
add 1 to {_counter}
# Be careful when using while loops with conditions that are almost
# always true for a long time without using 'wait %timespan%' inside it,
# otherwise it will probably hang and crash your server.
while player is online:
give player 1 dirt
wait 1 second # without using a delay effect the server will crash