I am hoping to make a command that will do something when the /testfor command brings up 0 of a specified entity. For example:
/testfor @e[x,y,z,r,type=Zombie,count=0]
Do the following:
Make the command block that is lowest
testfor @e[r=[radius], type=VillagerGolem]
(Replace [radius]
with your test radius (Also, remove the []
))
And make the upper one whatever you would like to do when there is no Iron Golem in that radius.
Use a scoreboard counter that have 1 added to it per entity that matches the requirements
Setup:
/scoreboard objectives add Counter dummy
/summon ArmorStand <X> <Y> <Z> {CustomName:Counter}
Clock (20 Hz):
/scoreboard players set @e[type=ArmorStand,name=Counter] Counter 0
/execute @e[type=VillagerGolem,x=<X>,y=<Y>,z=<Z>,r=<Range>] ~ ~ ~ scoreboard players add @e[type=ArmorStand,name=Counter] Counter 1
/execute @e[type=ArmorStand,name=Counter,score_counter=0] ~ ~ ~ <Desiered Command>
Technical Stuff:
Setup:
First a scoreboard objective called Counter is created. Then a armorstand called Counter is summoned.
Loop:
The score is first reset, then for every Iron Golem in range 1 is added to the ArmorStand's score. Lastly the execute command will only run on any armor stand called Counter with a score of 0.
If you change the score_counter of the last command, you can change how many Iron Golems you want before the command is ran.
/testfor @e[type=VillagerGolem,x=<X>,y=<Y>,z=<Z>,r=<Range>]
and /stats block X Y Z set SuccessCount @e[type=ArmorStand,name=Counter] Counter
where X Y Z are the coordinates of the first command block.
Using 2 command blocks, 1 comparator, 1 building block, 1 redstone torch. You can accomplish this thus:
testfor @e[r=radius, type=VillagerGolem]
your command
You will still need to put a clock on it. Mine is underneath the golem :)
As a side note, you don't want to use the c=0
because that is not saying find if there are 0 but rather it's saying when you match, match 0. So in your case, that has no real effect.
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]
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.
testfor @e[r=10000, type=zombie]
and then detect the signal from the commandblock, negate it (test for NOT entites) and send that signal to what ever you want it to do....