I have some redstone circuitry in place (see attached image), involving a hopper clock, command blocks, and the scoreboard. The basic purpose is to play a sound with /playsound
, and then once a certain time has elapsed (490 ticks of the hopper clock, or ~245 seconds), play the music again if the player is in range.
Scoreboard Objectives: timer
(dummy)
Command Block #1 (closest to the hopper clock):
scoreboard players add @a[r=100] timer 1
Command Block #2 (adjacent to the first one):
scoreboard players set @a[score_timer_min=490] timer 0
Command Block #3 (use the process of elimination):
playsound records.mall @a[score_timer=0] ~ ~10 ~ 2.0
mall.ogg
is not, in fact, my favorite choice. I selected it because the actual music being played is very nearly the exact length of what mall.ogg
is replaced with in my resource pack.
The system works perfectly, with one exception. When a player relogs, or logs out and then logs back in at a later time, the music (obviously) does not resume playing, and does not start again until the timer reaches 490 and resets to 0. The way to fix it (from what I see) would be to detect when a player is not logged in, and set their timer score to -1. When they logged back in, they would hear the music begin one second after.
Is there a way to detect a player's absence and then modify their score, even though they are not online?
stat.playOneMinute
scoreboard stat. This stat should only increment when a player is online. Set the scoreboard objective with/scoreboard objectives add TimePlayed stat.playOneMinute
, and then use a 20Hz clock to check the objective. Every minute is 1200 ticks, so for a similar time, you're looking at a score of 4800.