How can I make a short timer using only command blocks in 1.9? [duplicate]
Using only MC command blocks (I am using 1.9) how can I create a short timer?
It needs to be command block-only because I am trying to make a 1-block command; I want to make it night time and give the player a night-vision effect for ten seconds, but after the ten seconds I want to revert it back to day-time. I haven't yet figured out how to achieve this final part, of setting it back to day after ten seconds.
So far I have got the command:
summon FallingSand ~ ~1 ~ {
Block: command_block,
Time: 1,
TileEntityData: {
Command: /time set 18000
},
Passengers: [
{
id: FallingSand,
Block: chain_command_block,
Time: 1,
TileEntityData: {
Command: /effect @a 16 10 1 true
},
Passengers: [
{
id: FallingSand,
Block: redstone_block,
Time: 1
}
]
}
]
}
Sorry for the hierarchical mess, but basically, the above code spawns this structure:
Which does exactly what I want it to do: the top command block, just underneath the redstone, gives night vision for 10 seconds, and the bottom command block sets the time to midnight (18000.)
How can I add a bit to this setup to make it wait roughly ten seconds before setting the time back to day?
Best Answer
You can make a scoreboard:
/scoreboard objectives add time dummy
Create a entity which counts for you:
/summon ArmorStand ~ ~1 ~ {CustomName:"timeCounter",CustomNameVisible:1}
Make it it invisible and a marker if you want:
/summon ArmorStand ~ ~1 ~ {CustomName:"timeCounter",CustomNameVisible:0,Marker:1b,Invisible:1,Invulnerable:1,NoBasePlate:1,NoGravity:1}
Then a repeating command block which increases this scoreboard every tick (20 ticks = 1 second):
/scoreboard players add @e[CustomName:"timeCounter"] time 1
Put your commands into an execute:
/execute @e[score_time_min=200] ~ ~ ~ effect @a 16 10 1 true
/execute @e[score_time_min=200] ~ ~ ~ time set day
Change the 200 to whatever seconds you want * 20:
Sorry, I first understood your question wrong, just remove the reset.
Pictures about "How can I make a short timer using only command blocks in 1.9? [duplicate]"
![How can I make a short timer using only command blocks in 1.9? [duplicate] - Crop hacker silhouette typing on computer keyboard while hacking system How can I make a short timer using only command blocks in 1.9? [duplicate] - Crop hacker silhouette typing on computer keyboard while hacking system](/assets/images/how_can_i_make_a_short_timer_using_only_command_blocks_in_19_duplicate_1.jpeg)
![How can I make a short timer using only command blocks in 1.9? [duplicate] - Black and white of casual female photographer in summer clothes standing against mirror in light room and taking photo with camera How can I make a short timer using only command blocks in 1.9? [duplicate] - Black and white of casual female photographer in summer clothes standing against mirror in light room and taking photo with camera](/assets/images/how_can_i_make_a_short_timer_using_only_command_blocks_in_19_duplicate_2.jpeg)
![How can I make a short timer using only command blocks in 1.9? [duplicate] - From above of crop anonymous male hacker typing on netbook with data on screen while sitting at desk How can I make a short timer using only command blocks in 1.9? [duplicate] - From above of crop anonymous male hacker typing on netbook with data on screen while sitting at desk](/assets/images/how_can_i_make_a_short_timer_using_only_command_blocks_in_19_duplicate_3.jpeg)
How do you use a command block to make a timer?
Set the command block somewhere and add redstone repeaters and make sure to time the repeaters to somewhere around 29-30 seconds (if it's not that accurate) and you can just activate a single repeater by right-clicking a lever fast 2 times at the command block.Timer Tutorial in Minecraft! (no mods or addons) Command Block Creation
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Yan Krukov, Anete Lusina, Evgenia Basyrova, Sora Shimazaki


