I recently have been working on a pvp game where the last person alive wins. The problem is, I don't know how I would detect the last player alive. I was thinking I could do it with a scoreboard but I don't know how I would do that. What would be the best way to do it?
I recently have been working on a pvp game where the last person alive wins. The problem is, I don't know how I would detect the last player alive. I was thinking I could do it with a scoreboard but I don't know how I would do that. What would be the best way to do it?
You can count the number of players there are that are considered "alive", and if the number is 1, then there is only one player remaining. This is assuming you are using an objective to track deaths. First, ensure that players start with a score of 0 in that objective:
/scoreboard players add @a DEATHS 0
Image for reference, using 1.9 command blocks:
The following must run in numerical order on a clock.
1. Grab the number of players that are alive. This is a simple /testfor; the "SuccessCount" tag of the command block will be set equal to that number of players. No need to use any extra scoreboards as a result.
/testfor @a[score_DEATHS=0]
2. Check if the /testfor command only returned a value of 1. Change the XYZ coordinates to point to the previous command block.
/testforblock X Y Z minecraft:repeating_command_block -1 {SuccessCount:1}
3. Conditional. If the /testforblock command succeeded, then only 1 player is left alive. You can run commands from here to indicate the end of the game.
/tellraw @a [{"selector":"@a[score_DEATHS=0]"}," has won."]
Oh my gosh thank you so much! I believe I have read one of your posts about the tell raw commands before. Hey, do you know how I would add color to that tell raw command you put? I tried it myself but the formatting is way different from what I do.
And also, how would it detect a winner if all players had died multiple times? Would I have to make it so that whoever has the least amount of deaths would win? Like, whoever has 1 less?
And also, how would it detect a winner if all players had died multiple times? Would I have to make it so that whoever has the least amount of deaths would win? Like, whoever has 1 less?
Is the game time-based or is there a maximum number of times a player can die before being considered "out of the game"?
If a player dies once they are out of the game, and they have to wait for the others to die and for the winner to win. (The last person alive)
I'm not sure I understand; you previously asked:
And also, how would it detect a winner if all players had died multiple times? Would I have to make it so that whoever has the least amount of deaths would win? Like, whoever has 1 less?
If a player dies then they're done playing the game. If a player has not died at all, they would be the winner; if they died even once, regardless of multiple times, they simply cannot win.
For example, if it was the third time they had played and there were 4 players. Their scores were 4 4 4 3. How would it continuously check for a winner if it's set to look for a score of 0?
For example, if it was the third time they had played and there were 4 players. Their scores were 4 4 4 3. How would it continuously check for a winner if it's set to look for a score of 0?
You'll want to create a secondary objective that will have its score reset to 0, because trying to check from a total number of deaths will not be accurate. If a player died a lot compared to others, but won the next round, they won't be seen as a winner because there would be others with lower deaths. You can track multiple objectives with the same objective-type if you want to track both the total and for the current game.
That will work, but how do I reset there scores back to 0? I was thinking doing /scoreboard players reset @a, but that would cause them to not be on the scoreboard. I also can't do /scoreboard players remove because all players will have different scores.
That will work, but how do I reset there scores back to 0? I was thinking doing /scoreboard players reset @a, but that would cause them to not be on the scoreboard. I also can't do /scoreboard players remove because all players will have different scores.
You can target players based on their score:
/scoreboard players set @a[score_DEATHS_min=1] DEATHS 0
I can't test it because I only have 1 person which is me, but it seems to work. Thank you so much Skylinerw. This has helped me a lot. thanks a million!
I have one more question... I have a testfor command running to detect the score at 0. If the players just joined the world, it would detect it and run that. I have a comparator for the output of the testfor command to run a bunch of stuff. How would I reset it so it's not powered if it's resetting everyone's scores to 0?
I recently have been working on a pvp game where the last person alive wins. The problem is, I don't know how I would detect the last player alive. I was thinking I could do it with a scoreboard but I don't know how I would do that. What would be the best way to do it?
Liamswag7
Here's a useful link I found a while back: https://hypixel.net/threads/command-block-players-remaining-in-pvp-map-help.648/
I've used this system every time I make a pvp map, and it works. It's really easy as well!
I don't have a number of players
Liamswag7
You can count the number of players there are that are considered "alive", and if the number is 1, then there is only one player remaining. This is assuming you are using an objective to track deaths. First, ensure that players start with a score of 0 in that objective:
Image for reference, using 1.9 command blocks:
The following must run in numerical order on a clock.
1. Grab the number of players that are alive. This is a simple /testfor; the "SuccessCount" tag of the command block will be set equal to that number of players. No need to use any extra scoreboards as a result.
2. Check if the /testfor command only returned a value of 1. Change the XYZ coordinates to point to the previous command block.
3. Conditional. If the /testforblock command succeeded, then only 1 player is left alive. You can run commands from here to indicate the end of the game.
Minecraft-things: http://skylinerw.com
More Minecraft-things: https://sourceblock.net
Guides for command-related features (eventually moving to Source Block): https://github.com/skylinerw/guides
I primarily hang out in the /r/MinecraftCommands discord, where there's a lot of people that help with commands: https://discord.gg/QAFXFtZ
Their corresponding subreddit: https://www.reddit.com/r/MinecraftCommands/
Oh my gosh thank you so much! I believe I have read one of your posts about the tell raw commands before. Hey, do you know how I would add color to that tell raw command you put? I tried it myself but the formatting is way different from what I do.
Liamswag7
And also, how would it detect a winner if all players had died multiple times? Would I have to make it so that whoever has the least amount of deaths would win? Like, whoever has 1 less?
Liamswag7
/tellraw @a {text:"[TEXT]",color:[COLOR]}
This also works with the "title" command.
Check out my YouTube Channel! https://www.youtube.com/channel/UC5xGeY82ipCffJjAu6_kHMQ
Is the game time-based or is there a maximum number of times a player can die before being considered "out of the game"?
Minecraft-things: http://skylinerw.com
More Minecraft-things: https://sourceblock.net
Guides for command-related features (eventually moving to Source Block): https://github.com/skylinerw/guides
I primarily hang out in the /r/MinecraftCommands discord, where there's a lot of people that help with commands: https://discord.gg/QAFXFtZ
Their corresponding subreddit: https://www.reddit.com/r/MinecraftCommands/
If a player dies once they are out of the game, and they have to wait for the others to die and for the winner to win. (The last person alive)
Liamswag7
This won't work in 1.9, because all NBT tags need to be quoted, i.e. {"text": "[TEXT]", "color": "[COLOR]"}
"Are you falling asleep in the middle of my fascinating explanation?" - Qibli
"I can't even dignify that with a snort." - Winter
"This is important and fascinating!" - Starflight
"You're nonagashabibble." - Squid
I'm not sure I understand; you previously asked:
If a player dies then they're done playing the game. If a player has not died at all, they would be the winner; if they died even once, regardless of multiple times, they simply cannot win.
Minecraft-things: http://skylinerw.com
More Minecraft-things: https://sourceblock.net
Guides for command-related features (eventually moving to Source Block): https://github.com/skylinerw/guides
I primarily hang out in the /r/MinecraftCommands discord, where there's a lot of people that help with commands: https://discord.gg/QAFXFtZ
Their corresponding subreddit: https://www.reddit.com/r/MinecraftCommands/
For example, if it was the third time they had played and there were 4 players. Their scores were 4 4 4 3. How would it continuously check for a winner if it's set to look for a score of 0?
Liamswag7
You'll want to create a secondary objective that will have its score reset to 0, because trying to check from a total number of deaths will not be accurate. If a player died a lot compared to others, but won the next round, they won't be seen as a winner because there would be others with lower deaths. You can track multiple objectives with the same objective-type if you want to track both the total and for the current game.
Minecraft-things: http://skylinerw.com
More Minecraft-things: https://sourceblock.net
Guides for command-related features (eventually moving to Source Block): https://github.com/skylinerw/guides
I primarily hang out in the /r/MinecraftCommands discord, where there's a lot of people that help with commands: https://discord.gg/QAFXFtZ
Their corresponding subreddit: https://www.reddit.com/r/MinecraftCommands/
That will work, but how do I reset there scores back to 0? I was thinking doing /scoreboard players reset @a, but that would cause them to not be on the scoreboard. I also can't do /scoreboard players remove because all players will have different scores.
Liamswag7
You can target players based on their score:
Minecraft-things: http://skylinerw.com
More Minecraft-things: https://sourceblock.net
Guides for command-related features (eventually moving to Source Block): https://github.com/skylinerw/guides
I primarily hang out in the /r/MinecraftCommands discord, where there's a lot of people that help with commands: https://discord.gg/QAFXFtZ
Their corresponding subreddit: https://www.reddit.com/r/MinecraftCommands/
I can't test it because I only have 1 person which is me, but it seems to work. Thank you so much Skylinerw. This has helped me a lot. thanks a million!
Liamswag7
I have one more question... I have a testfor command running to detect the score at 0. If the players just joined the world, it would detect it and run that. I have a comparator for the output of the testfor command to run a bunch of stuff. How would I reset it so it's not powered if it's resetting everyone's scores to 0?
Liamswag7
Where should I put that command block in my set up?
Liamswag7
Exitrida where should I put it? Should I invert the signal?
Liamswag7