I found one option that I can live with for multiple timers and I can extend it to as many times as I want. It uses several function files but each timer can be tracked and works independently from the other timers. Solution requires just one repeating command block. You can start the timer via a second command block (/function timer1Start for example), call the timer1start function directly in console, or call timer1Start from some other function.
I am creating a build battle feature so there will just be some button the user clicks that will execute another function buildBattle. The buildBattle function in turn will directly call /function timer1Start. With 3 timers I can have 3 different build battles at the same time each on their own timer and each can execute a separate function when complete.
I guess the same could be set up without functions using a bunch of command blocks - but who wants to do that ;)
I created these files:
global:
- timerInit.mcfunction: execute this one time to set up all timers
- TimerTick.mcfunction: put this in a repeating command block that runs every 20 ticks
timer1 files
- timer1start.mcfunction:
- sets active timer to 1 and starts a 15 second timer
- call /function timer1start to start the timer
- timer1tick.mcfunction: anything in here will execute once per second
- timer1done.mcfunction: anything in here will execute once after timer1 expires
timer2 files
- timer2start.mcfunction:
- sets active timer to 2 and starts a 30 second timer
- call /function timer2start to start the timer
- timer2tick.mcfunction: anything in here will execute once per second
- timer2done.mcfunction: anything in here will execute once after timer2 expires
timer3 files
- timer3start.mcfunction: sets active timer to 3 and starts a 45 second timer
- sets active timer to 3 and starts a 45 second timer
- call /function timer3start to start this timer
- timer3tick.mcfunction: anything in here will execute once per second
- timer3done.mcfunction: anything in here will execute once after timer3 expires
timerInit.mcfunction:
scoreboard objectives add timer1 dummy "Timer 1"
scoreboard objectives add timer2 dummy "Timer 2"
scoreboard objectives add timer3 dummy "Timer 3"
scoreboard objectives add activeTimer dummy "activeTimer"
TimerTick.mcfunction:
#update the 3 individual timers
scoreboard players remove timeTracker1 timer1 1
scoreboard players remove timeTracker2 timer2 1
scoreboard players remove timeTracker3 timer3 1
#synch each players timer with the time tracker 'player'
scoreboard players operation @a timer1 = timeTracker1 timer1
scoreboard players operation @a timer2 = timeTracker2 timer2
scoreboard players operation @a timer3 = timeTracker3 timer3
#update all players to show them their active timer in the side bar (optional)
execute @a[scores={activeTimer=1}] ~ ~ ~ scoreboard objectives setdisplay sidebar timer1
execute @a[scores={activeTimer=2}] ~ ~ ~ scoreboard objectives setdisplay sidebar timer2
execute @a[scores={activeTimer=3}] ~ ~ ~ scoreboard objectives setdisplay sidebar timer3
#execute something every second for the timers (for instance show time or some other command)
function timer1Tick
function timer2Tick
function timer3Tick
#execute these functions ONE TIME when the timer expires
execute @p[scores={timer1=-1}] ~ ~ ~ function timer1Done
execute @p[scores={timer2=-1}] ~ ~ ~ function timer2Done
execute @p[scores={timer3=-1}] ~ ~ ~ function timer3Done
timer1start.mcfunction
scoreboard players set @a timer1 15
scoreboard players set timeTracker1 timer1 15
scoreboard players set @a activeTimer 1
timer1tick.mcfunction:
#execute @a[scores={activeTimer=1}] ~ ~ ~ say hello
title @a[scores={timer1=10,activeTimer=1}] actionbar 10 seconds left
title @a[scores={timer1=9,activeTimer=1}] actionbar 9
title @a[scores={timer1=8,activeTimer=1}] actionbar 8
title @a[scores={timer1=7,activeTimer=1}] actionbar 7
title @a[scores={timer1=6,activeTimer=1}] actionbar 6
title @a[scores={timer1=5,activeTimer=1}] actionbar 5
title @a[scores={timer1=4,activeTimer=1}] actionbar 4
title @a[scores={timer1=3,activeTimer=1}] actionbar 3
title @a[scores={timer1=2,activeTimer=1}] actionbar 2
title @a[scores={timer1=1,activeTimer=1}] actionbar 1
title @a[scores={timer1=0,activeTimer=1}] actionbar Times up!
timer1Done.mcfunction
#do something when the timer completes
title @a[scores={timer1=..0}] actionbar timer 1 countdown complete
timer2start.mcfunction
scoreboard players set @a timer2 30
scoreboard players set timeTracker2 timer2 30
scoreboard players set @a activeTimer 2
timer2tick.mcfunction:
#do something when timer 2 executes
timer2Done.mcfunction:
#do something when timer 2 expires
timer3start.mcfunction
scoreboard players set @a timer3 45
scoreboard players set timeTracker3 timer3 45
scoreboard players set @a activeTimer 3
timer3tick.mcfunction:
#do something when timer 3 executes
timer3Done.mcfunction:
#do something when timer 3 expires