Command block tutorial

= Command block learning. =
***{NOTE: it is recommended to understand the sandbox/peaceful commands first then command blocks.}***

## ***Variables.***

Variables can be added by typing /variable set [name] [value]

For the command block to view a variables value. simply type $(Variable name)

To delete a variable, simply say /variable delete [name]

To add a certain value to a variable, type /variable gain [name] [value]

To reduce the value of the variable, say /variable lose [name] [value]

## ***if else then conditions/cycles.***

Self explanatory.

Value1 = [$message / $getRole($player) (commonly for PlayerJoin, buildingPlaced, etc.) / $player / $getGold($player) (buildingInteract commonly) / $(variable name) / etc. ] (common uses)

Operator: == (Exact value) / =~ (If message contains this word) / < (Value 1 is less than Value 2) / > (Value 1 higher than value 2) / != (Value 1 is not equal to Value 2) / >= (Value 1 is greater than or equal to Value 2) / <= (Value 1 is less that or equal to Value 2)

value2: [amount / username / needed role / message entered / etc. ] (common uses)

Then:

----click on the + circle to add stuff when the requirements are met---

        -----You can add a new ifelsethen to make it a cycle-----

Else:

----click on the + circle to add stuff when the values are not the same----

        -----You can add a new ifthenelse to make it a cycle-----

## ***Timers.***

I cant say more. When you add a timer in a trigger or in an if else then cycle it will be viewed and shortcutted by simply being a whole new 3 triggers just for that specific timer you set in.

You can either add a new timer in a timer *(a war crime if you do this, or tds)* or a if else then condition/cycle And a command condition.

**You can make the timer viewable in the sidebar.**

**By the timer:(name):tick just add a command condition, add a command box and type: "/sidebar set [value] [type anything here u like $remaining]".**

## Intro

Having a Gold/Score loop is extremely fast, very efficient and can have lots of usages for more complex situations. However, it is very situational as it is not a all-in-one solution for every problem, and using this method does risk your colony crashing due to the extremely rapid processing of the loop.

For example, using the loop for giving players score every second is not a efficient nor simple way to use it. You'd be easier off using /timer.

A good way for using it could simply be for making a save data mechanic for buildings (one block?), or making a custom command to arrest players.

*Note: This could be outdated due to new commands like getnthletter.*

## Creating a simple arrest mechanic

Let's say you wanted to create a custom command for your moderators that can pull and 'arrest' a player they choose.

First we'll start with the necessary functions to create it:

1. ScoreChanged/GoldChanged - We need this so we can create a 'loop'
2. PlayerMessage - We need this so we can create the custom command AND broadcast to Score/GoldChanged our command.
3. OPTIONAL: PlayerMove - We need this to restrict the player(s) from escaping from you.
4. OPTIONAL: Timer:end - Additionally, if you want to make a player to stop moving during jailtime, we have this.

### PlayerMessage

First, we need a basic structure for our custom command.

```
Value1: $getRole($player) $message
~=
Value2: Moderator /arrest
Then:
+ /variable set input $message
+ /variable set input2 $player
+ /score OR gold set @a [value]

```

Explanation:
What I did here is I used one IfElse and put 2 key things - $getRole($player) & $message.

The point of this is to make the command blocks as efficient as possible while still replicating the same results as doing using 2 IfElses and doing it normally. I also used another variable to store the player's name to ensure that you do not arrest yourself AND to tell the Command Blocks where to move the 'arrested' player(s) when you do the command.

IF YOUR role as a player and YOUR message CONTAINS ROLE: Moderator AND MESSAGE:/arrest, THEN
VARIABLE: input IS your MESSAGE
VARIABLE: input2 IS the PLAYER
SCORE/GOLD set @a (EVERYONE \*) [value]

The reason I did [set] for Gold and Score is just to make some colonies compatible with manipulating GOLD/SCORE. If you are not using GOLD/SCORE for any of your games you do not need to use [set]!

I also recommend using purely random values if you are using score/gold and are using gold/score for buying items or RPGs, like 198981983

If you do not want to do what I have done, here is the regular method:

```
Value1: $message
~=
Value2: /arrest
Then:
+ Value1: $getRole($player)
+ =
+ Value2: Moderator
+ Then
+ + /variable set input $message
+ + /variable set input2 $player
+ + /score OR gold set @a [value]

```

Explanation:

In this version I did basically the same as before, but it uses 2 IfElses. Same function, different structure.

### ScoreChanged/GoldChanged

Once you have done the Command Blocks for PlayerMessage we will move on to checking if the players are 'arrested'.

```
# Value1: $current
Value2: [Value you have set for PlayerMessage]
Then:
+ Value1: $getRole($input2)
+ =
+ Value2: $getRole($player)
+ Then: (do nothing)
+ Else:
+ - Value1: $input
+ - ~=
+ - Value2: $player
+ - Then:
+ - + /role $player Arrested
+ - + /tp $player $getRow($input2) $getCol($input2)
+ - + /score set $player $previous
+ - + /variable set this_arrested_$player $input2 (OPTIONAL)
+ - + /effect give $player paralyze
+ - + (Add any additional commands you want here!)

```

Explanation:

What I did here is that I checked if the Score value is EQUAL to what the custom command's score set everyone to.
For example:
The custom message does /score set @a 198981983, so I expect ScoreChanged to notice it and use the IfElse to check if my score is 198981983.
This should be TRUE, so I next check if $input2's role, also known as the person who activated the command, is NOT the same as your role (to make sure you do not arrest other Moderators).

The variable $this\_arrested\_$player is to identify who arrested you. This is an OPTIONAL variable if you want to make a "$this\_arrested\_$player arrested you", and is vital for the OPTIONAL PlayerMove.

Lastly, I check if $input (the list of players to arrest) CONTAINS your name. If it does, THEN I arrest the player. If not, nothing happens.
This is not 100% SAFE, so there will be a more safer version if you have multiple roles with Moderator/Admin powers below:

```
Value2: [Value you have set for PlayerMessage]
Then:
+ Value1: [roles] (Format: Moderator Admin SuperAdmin ModInTraining etc)
+ ~=
+ Value2: $getRole($player)
+ Then: (do nothing)
+ Else:
+ - Value1: $input
+ - ~=
+ - Value2: $player
+ - Then:
+ - + /role $player Arrested
+ - + /tp $player $getRow($input2) $getCol($input2)
+ - + /score set $player $previous
+ - + /effect give $player paralyze
+ - + /variable set this_arrested_$player $input2 (OPTIONAL)
+ - + (Add any additional commands you want here!)

```

Explanation: This is basically the same as before, but it is more safer as it makes sure multiple roles of importance/value are immune to being arrested.

There are other methods for Arresting people other than roles, but if you need it, feel free to tell me (might not respond).

### PlayerMove

**OPTIONAL**
If you want the custom arrest command to tp the arrested player(s) back to you when they move, have a look at these command blocks:

```
PlayerMove
Value1: $this_arrested_$player
!=
Value2: undefined
Then:
+ /tp $player $getRow($this_arrested$player) $getCol($this_arrested_$player)

```

Explanation:
I use the variables that were defined before in ScoreChanged so I can TP the arrested players everytime they try to escape. This is still a very simple ifelse and does not include you moving teleporting the arrested player(s), but if you want a more in-depth explanation, feel free to tell tell me (I may not respond still).

### Timer:end

If you want the arrested player(s) to simply stay frozen:

```
# Value1: $name
Value2: [name of timer]
Then:
+ /effect clear @a[role=Arrested] paralyze
+ /effect give @a[role=Arrested] paralyze
+ /timer start $name 1

```

This simply takes advantage of the role you've given the arrested players and gave them paralyze, and reruns the timer (using the name) forever.
Be sure to run the timer in PlayerJoined or else it won't work!

#### Conclusion

If you've read and done all I've said, you should've have gotten some knowledge of how I took advantage of ScoreChanged/GoldChanged to create a custom command that targets all players by saying '/arrest bob [other names]'.

Honestly, I'm not a qualified teacher overall but I have some expertise in Command Blocks, but nonetheless, I think you will learn something by reading my explanation. Thank you for reading my tutorial, I struggled to make one due to the glitchy editor, so I might do it in my blogs, even if no one reads it.

Tutorial #1