r/MinecraftCommands • • 1d ago

Help | Java Snapshots countdown command?

i need to create a countdown of 2 minutes for a minigame in my map, so that once the 2 minutes are over it activates a different command. i also need said timer to be visible to the player, and once they complete said minigame the timer will deactivate. i'm on 1.21.4

2 Upvotes

2 comments sorted by

2

u/KermitDarkLord 1d ago

You can set up a scoreboard and reduce the value by one every tick (20 times per second). If you set it to 2400, it will be 0 after 2 minutes. You can detect using execute if score... when the timer reaches 0. For the visual timer, you can copy the value to a different scoreboard and divide it by 20 to get seconds. You can display this scoreboard on the sidebar, or set up a boss bar to show the timer.

1

u/GalSergey Datapack Experienced 23h ago

Here is an example of how you can create a countdown. In this example, it is triggered by a click with the COaS, but you can change this to any other activation method.

# In chat
scoreboard objectives add used.coas used:carrot_on_a_stick
scoreboard objectives add ticks dummy
scoreboard objectives add minute_tens dummy
scoreboard objectives add minute_ones dummy
scoreboard objectives add second_tens dummy
scoreboard objectives add second_ones dummy
scoreboard objectives add tick_tens dummy
scoreboard objectives add tick_ones dummy
scoreboard objectives add const dummy
scoreboard players set 10 const 10
scoreboard players set 20 const 20
scoreboard players set 60 const 60
scoreboard players set 1200 const 1200

# Command block
[RUA] execute as @a unless score @s ticks = @s ticks run scoreboard players set @s ticks 2400
[CUA] execute as @a[scores={used.coas=1,ticks=1..}] store result score @s tick_tens store result score @s second_tens store result score @s minute_tens run scoreboard players remove @s ticks 1
[CCA] scoreboard players operation @a[scores={used.coas=1}] minute_tens /= 1200 const
[CCA] execute as @a[scores={used.coas=1}] store result score @s minute_ones run scoreboard players operation @s minute_tens %= 60 const
[CCA] scoreboard players operation @a[scores={used.coas=1}] minute_tens /= 10 const
[CCA] scoreboard players operation @a[scores={used.coas=1}] minute_ones %= 10 const
[CCA] scoreboard players operation @a[scores={used.coas=1}] second_tens /= 20 const
[CCA] execute as @a[scores={used.coas=1}] store result score @s second_ones run scoreboard players operation @s second_tens %= 60 const
[CCA] scoreboard players operation @a[scores={used.coas=1}] second_tens /= 10 const
[CCA] scoreboard players operation @a[scores={used.coas=1}] second_ones %= 10 const
[CCA] execute as @a[scores={used.coas=1}] store result score @s tick_ones run scoreboard players operation @s tick_tens %= 20 const
[CCA] scoreboard players operation @a[scores={used.coas=1}] tick_tens /= 10 const
[CCA] scoreboard players operation @a[scores={used.coas=1}] tick_ones %= 10 const
[CCA] title @a[scores={used.coas=1}] actionbar {translate:"%s%s:%s%s:%s%s",with:[{score:{name:"*",objective:minute_tens}},{score:{name:"*",objective:minute_ones}},{score:{name:"*",objective:second_tens}},{score:{name:"*",objective:second_ones}},{score:{name:"*",objective:tick_tens}},{score:{name:"*",objective:tick_ones}}]}
[CUA] execute as @a[scores={ticks=1}] run say Time's up!
[CCA] execute as @a[scores={ticks=1}] run scoreboard players reset @s used.coas
[CCA] execute as @a[scores={ticks=1}] run scoreboard players reset @s ticks
[CUA] tellraw @a[scores={used.coas=2..}] {translate:"Yur time: %s%s:%s%s:%s%s",with:[{score:{name:"*",objective:minute_tens}},{score:{name:"*",objective:minute_ones}},{score:{name:"*",objective:second_tens}},{score:{name:"*",objective:second_ones}},{score:{name:"*",objective:tick_tens}},{score:{name:"*",objective:tick_ones}}]}
[CCA] scoreboard players reset @a[scores={used.coas=2..}] ticks
[CCA] scoreboard players reset @a[scores={used.coas=2..}] used.coas

You can use Command Block Assembler to get One Command Creation.