1
Command Help (/scoreboard)
So I am making a game and successfully created a /scoreboard timer that loops through three phases and counts down using 10 tick intervals (One second) and want to know if I can interrupt the timer during only a certain phase if a score is high enough. I know that is simple with the /testfor command, but the score that needs to be reached is variable on the amount of players in Survival mode.
Think of it like the Voting phase in Town of Salem. If enough votes are reached, Defense phase begins. If more players are dead, less votes are needed. If time runs out before enough votes are gathered, Night phase begins.
For this solution, a long process would be to testfor how many players are in survival, and connect that to multiple command blocks for how much score would be needed, and each one of them branches out to interrupting the one timer. I need a shorter and simpler way of doing this.
If there is no shorter way, I request review of my method in case it is flawed.
Think of it like the Voting phase in Town of Salem. If enough votes are reached, Defense phase begins. If more players are dead, less votes are needed. If time runs out before enough votes are gathered, Night phase begins.
For this solution, a long process would be to testfor how many players are in survival, and connect that to multiple command blocks for how much score would be needed, and each one of them branches out to interrupting the one timer. I need a shorter and simpler way of doing this.
If there is no shorter way, I request review of my method in case it is flawed.
1
There is indeed a shorter way, using the marvel that is command stats. Unfortunately they're somewhat complicated to explain, but I'll do my best. They may seem long and pointlessly complicated at first, however the major benefit to them is that they're almost infinitely expandable, and you can easily adjust the % of players required to be in survival before an action is taken.
The first thing to do is going to be creating our fake player and giving him a score to load him into the scoreboard. For now my objective will be called 'toyStory' and and a player called '#woody', and I will be using that throughout. You can change it to whatever you'd like:
Now that we've set up, we can run the stat's command:
Now if you check #woody's score on the objective toyStory, you will see his score matches the number of players in survival (assuming you've done it right). Next we're going to do something similar, but we're going to retrieve the number of player online:
We now have the number of players in survival saved on #woody's score, and the total number of player's saved on #buzz's score. Now I'm not exactly sure how Town of Salem works, but for the purposes of demonstration I'm going to assume that if 50% of the players vote to go to defense, the the game goes into the defense phase. To accomplish that, we're going to divide these two scores with the following command:
The total amount of people in the game should not matter, this will work with 4 or 40 or even 4,000 players.
If you didn't understand all or part of this: feel free to ask me any other questions you have, either over a pm or on this forum. There are also plenty of videos with tutorials for stats on youtube, I think Dragnoz put up a pretty good one a while back.
The first thing to do is going to be creating our fake player and giving him a score to load him into the scoreboard. For now my objective will be called 'toyStory' and and a player called '#woody', and I will be using that throughout. You can change it to whatever you'd like:
scoreboard players set #woody toyStory 0Now that we've set up, we can run the stat's command:
stats block x y z set SuccessCount #woody toyStoryWhat goes in for x y z you ask? Instead of x y z, put in the coordinates of the next command block (either with absolutes or ~'s):testfor @a[m=0]Now if you check #woody's score on the objective toyStory, you will see his score matches the number of players in survival (assuming you've done it right). Next we're going to do something similar, but we're going to retrieve the number of player online:
scoreboard players set #buzz toyStory 0
stats block x y z set SuccessCount #buzz toyStory
testfor @aIf you have some way of keeping track of players that are in the game vs. players that are just hanging around on the server, you'll want to include that in the last /testfor.We now have the number of players in survival saved on #woody's score, and the total number of player's saved on #buzz's score. Now I'm not exactly sure how Town of Salem works, but for the purposes of demonstration I'm going to assume that if 50% of the players vote to go to defense, the the game goes into the defense phase. To accomplish that, we're going to divide these two scores with the following command:
scoreboard players operation #buzz toyStory /= #woody toyStoryThis command divides the scores and gets rid of any decimal, and saves the result into #buzz's score. This means that if after this command #buzz has a score that is less than 2, then over half the people in the game are currently in survival. You can test for this with the following command:scoreboard players test #buzz toyStory * 2Just use a comparator as an output like you would a normal testfor. If the number you want is not exactly 50% like I assumed it was, you can change the two to whatever you'd like to fit your needs.The total amount of people in the game should not matter, this will work with 4 or 40 or even 4,000 players.
If you didn't understand all or part of this: feel free to ask me any other questions you have, either over a pm or on this forum. There are also plenty of videos with tutorials for stats on youtube, I think Dragnoz put up a pretty good one a while back.
