Skip to main content
Improved formatting
Source Link
pinckerman
  • 43.9k
  • 23
  • 132
  • 195

/scoreboard objectives add IfElse dummy

/scoreboard objectives add IfElse dummy

/scoreboard players set @e[name=IfElse1] IfElse 0 (Armorstand)and(Scoreboard)

/scoreboard players set @e[name=IfElse1] IfElse 0
                    (Armorstand)and(Scoreboard)

/scoreboard players set @e[tag=IfElseAll] IfElse 0

/scoreboard players set @e[tag=IfElseAll] IfElse 0
/testfor @e[type=Player,r=20] 

/testfor @e[type=Player,r=20] (Could add a region tag, to check within a box, or a tag, or anything that could be given to the player to count them as beeing in game.

tag: /testfor @e[type=Player,tag=InGame] or score

/testfor @e[type=Player,tag=InGame]  

score: /testfor @e[type=Player,score_GameStatus_min=1,score_GameStatus=1]

/testfor @e[type=Player,score_GameStatus_min=1,score_GameStatus=1]

/scoreboard players set @e[name=IfElse1] IfElse 1

/scoreboard players set @e[name=IfElse1] IfElse 1
/testfor @e[name=IfElse1,score_IfElse_min=0,score_IfElse=0]

/testfor @e[name=IfElse1,score_IfElse_min=0,score_IfElse=0] (Checking for a miniumum of 0, and a maximum of 0 score for the armorstand "IfElse1" in the scoreboard "IfElse".)

/scoreboard objectives add IfElse dummy

/scoreboard players set @e[name=IfElse1] IfElse 0 (Armorstand)and(Scoreboard)

/scoreboard players set @e[tag=IfElseAll] IfElse 0

/testfor @e[type=Player,r=20] (Could add a region tag, to check within a box, or a tag, or anything that could be given to the player to count them as beeing in game.

tag: /testfor @e[type=Player,tag=InGame] or score: /testfor @e[type=Player,score_GameStatus_min=1,score_GameStatus=1]

/scoreboard players set @e[name=IfElse1] IfElse 1

/testfor @e[name=IfElse1,score_IfElse_min=0,score_IfElse=0] (Checking for a miniumum of 0, and a maximum of 0 score for the armorstand "IfElse1" in the scoreboard "IfElse".)

/scoreboard objectives add IfElse dummy
/scoreboard players set @e[name=IfElse1] IfElse 0
                    (Armorstand)and(Scoreboard)
/scoreboard players set @e[tag=IfElseAll] IfElse 0
/testfor @e[type=Player,r=20] 

(Could add a region tag, to check within a box, or a tag, or anything that could be given to the player to count them as beeing in game.

tag:

/testfor @e[type=Player,tag=InGame]  

score:

/testfor @e[type=Player,score_GameStatus_min=1,score_GameStatus=1]
/scoreboard players set @e[name=IfElse1] IfElse 1
/testfor @e[name=IfElse1,score_IfElse_min=0,score_IfElse=0]

(Checking for a miniumum of 0, and a maximum of 0 score for the armorstand "IfElse1" in the scoreboard "IfElse".)

Source Link

Make an if else statement. For example. Start by creating a scoreboard.

/scoreboard objectives add IfElse dummy

With this scoreboard you will detect if something succedeed or not. You will be using the score 0 for when something didnt happend(A testfor failed.) and the score 1 if something suceeded.

Laying down a clock, were you put your first command block to repeating, on a piece of redstone. Now for a score to be carried you need a Armorstand. So summon an armorstand that has the name "IfElse1" or something.

Now, for the first block in your command block line you want to set the amorstand(s) scores to 0, so that every time the clock finishes testing for scores/change them, they will be put back to normal. (Score 0)

/scoreboard players set @e[name=IfElse1] IfElse 0 (Armorstand)and(Scoreboard)

If your going to be using sereval IfElse statements in your contraption i suggest giving it a tag, so that you can target and reset all your IfElse(x) armorstands easily only using one command block. So something like this:

/scoreboard players set @e[tag=IfElseAll] IfElse 0

So you could put this as your first command instead.

Next is were you wanna testfor the opposite of what you actually want to find out and get an output from, to know if something issnt true, you first need to find out what kind of output you will get from doing a check. So something like this

/testfor @e[type=Player,r=20] (Could add a region tag, to check within a box, or a tag, or anything that could be given to the player to count them as beeing in game.

Example:

tag: /testfor @e[type=Player,tag=InGame] or score: /testfor @e[type=Player,score_GameStatus_min=1,score_GameStatus=1]

Next you want to have a conditional command block. This commandblock will get an output if the test was successfull, or not be activated at all if it wassnt. Meaning this is were you would put your output from there beeing players in the game. But were trying to find the opposite, so you put the following.

/scoreboard players set @e[name=IfElse1] IfElse 1

This will change the armorstands default score(0). To 1. Indicating that there is players in the game. But if that is not the case. The score will remain(0). (If you would like an output from there beeing players in the game. you may put more conditional command blocks. But remember, if one fails the chain does not activate all the way.)

Now after your testing for players, you know know if theres players or not in your game, determined by the state of the score "No players(0)" "Players(1)". Now to get an output from there not beeing players in the game, do another testfor command in the same chain "that is not conditional".

/testfor @e[name=IfElse1,score_IfElse_min=0,score_IfElse=0] (Checking for a miniumum of 0, and a maximum of 0 score for the armorstand "IfElse1" in the scoreboard "IfElse".)

Now make another conditional command block chain, with whatever outputs you might want. For there beeing no players in the game.

And you should be all set.

No comparators, or redstone needed.