4

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.

The redstone circuitry

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?

  • 1
    You should be able to track the number of ticks a player is logged in using the 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. – MBraedley Jun 16 '15 at 1:58
  • This is probably only possible with plugins and server scripts. – TheMinecraftMan757 Jun 16 '15 at 15:40
  • Modifying their score is right-out impossible, since offline players are never valid targets for commands. I believe I have found a system of associating armor stands to players (by assigning a unique score to both), but it's kind of very complicated right now. Also, I can't think of a way to detect which player is offline. – MrLemon Jun 16 '15 at 15:50
1

For this problem, you don't actually need to modify the players score when they are offline (which is possible, but finicky), you should be able to change their score as soon as they log back in.


First, create a scoreboard objective of type stat.leaveGame:

scoreboard objectives add quits stat.leaveGame

You should then have two command blocks on some kind of clock, one activated after another. In the block that is activated first, put this command:

scoreboard players set @a[score_quits_min=1] timer -1

Then, in the one that is activated second:

scoreboard players set @a[score_quits_min=1] quits 0

The quits score increments when the player leaves. So, when they log back on, it will be at 1 and their timer score will be set to -1. Their quits score then has to be set back to 0, so that it can be used for the next logout and also so that timer isn't repeatedly set to -1,

  • TIL stat.leaveGame is a thing that exists for some reason. Very good find! – MrLemon Jun 16 '15 at 20:49
  • Thank you very much! I was unaware that stat.leaveGame was even a thing! by the way, here is the song that replaces mall.ogg in the resource pack. It was made by Notch and implemented in alpha, but was removed shortly after. Took a while to track it down and convert it to .ogg format. youtube.com/watch?v=QhPHB6ovnKE – Connor Mainwaring Jun 17 '15 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.