Conditions are used with if, else if, and else statements:
if <condition>: # code to run if trueelse if <condition>: # code to run if first is false and this is trueelse: # code to run if all conditions are false
# AND - both must be trueif player has permission "skript.admin" and {_balance} > 100:# OR - at least one must be trueif player is holding a diamond sword or player is holding a diamond axe:# NOT - inverts the conditionif player does not have permission "skript.example.damage":
# Permissionsif player has permission "skript.example.item":# Inventoryif player is holding a diamond pickaxe:if player's inventory contains 10 emeralds:# Stateif player is online:if player is in world "world_nether":if player is flying:
Use conditions directly in events to filter when they trigger:
on inventory click: event-slot is the helmet slot of player inventory action is place all or nothing player has permission "skript.example.helmet" cursor slot of player is custom helmets # All conditions must be true for code to execute cancel the event set {_old helmet} to the helmet of player set the helmet of player to the cursor slot of player set the cursor slot of player to {_old helmet}
Conditions placed directly after an event line act as filters. The event code only runs if all conditions are true.
command /item <items>: permission: skript.example.item executable by: players trigger: if player has permission "skript.example.item.all": give argument to player else: loop argument: if loop-item is not blacklisted: give loop-item to player else: send "<red>%loop-item%<reset> is blacklisted and cannot be spawned." to player
Conditions can be nested for complex decision trees:
command /home <text> [<text>]: permission: skript.example.home executable by: players trigger: if arg-1 is "set": if arg-2 is set: set {homes::%uuid of player%::%arg-2%} to player's location send "Set your home <green>%arg-2%<reset> to <grey>%location of player%<reset>" to player else: send "You must specify a name for this home." to player else if arg-1 is "remove": if arg-2 is set: delete {homes::%uuid of player%::%arg-2%} send "Deleted your home <green>%arg-2%<reset>" to player else: send "You must specify the name of this home." to player else if arg-2 is set: send "Correct usage: /home set/remove <name>" to player else if {homes::%uuid of player%::%arg-1%} is set: teleport player to {homes::%uuid of player%::%arg-1%} else: send "You have no home named <green>%arg-1%<reset>." to player
command /whileexample: permission: skript.example.while trigger: set {_number} to 5 while {_number} is greater than 0: send "The number is %{_number}%" remove a random number between 0 and 2 from {_number} send "Finished counting down." while true is true: # this will run forever add "banana" to {_list::*} if size of {_list::*} is 10: exit loop send "The list has %size of {_list::*}% bananas."
Be careful with while loops. Without an exit condition, they can freeze your server. Always include a way to break out of the loop.
Here’s a real example from the Skript source demonstrating condition usage:
## This example cancels damage for players if they have a specific permission.# If they don't, tell them how much damage they took.#on damage: victim is a player if the victim has permission "skript.example.damage": cancel the event # Stops the default behaviour - the victim taking damage. else: send "Ouch! You took %damage% damage." to the victim add damage to {damage::%uuid of victim%::taken} if the attacker is a player: add damage to {damage::%uuid of attacker%::dealt}