1

Creating a PVP minigame on Java Edition 1.19.3. Red vs Blue. After 10 minutes the game ends. I have everything else setup and fully functioning. The only problem I am having is having the system determine which team has a higher score (more kills) than the other team to then trigger the specific title screen. Is there a better way to do this?

This is the latest version of my code:

/execute if score [team=BLUE] Kills = [team=RED] Kills run summon minecraft:arrow 14 123 -176 
/execute if score [team=RED] Kills > [team=BLUE] Kills run summon minecraft:arrow 12 123 -176
/execute if score [team=BLUE] Kills > [team=RED] Kills run summon minecraft:arrow 10 123 -176

(The arrow triggers the title sequence for the specific team result)

I've tried variations of the target such as:

/execute if score BLUE Kills > RED Kills run summon minecraft:arrow 10 123 -176

There's aren't any errors showing as a result of the code so I don't understand where it is specifically incorrect.

Other things I've tried:

/execute if score #red_kills kills matches 50 run title @a title {"text":"Game Over","color":"red"}

I read both of: https://minecraft.wiki/w/Commands/execute https://www.digminecraft.com/game_commands/execute_command.php

But I still can't understand why the code doesn't function. I assume it's because of the target "BLUE/RED" and the execute command doesn't like targetting multiple entities like with:

"/execute if score @a"

"Only one entity is allowed, but the provided sector allows more than one"

2
  • So you are trying to detect all team kills at once? How do you track player kills? Have you already set up a system that collects the individual player kills into one score? My idea would be to add all players' scores to a team score, then use that score to determine the winners. The team score would need a player who can be just a 'fake' player, just any name you'd like. That 'fake' player would then be used in your command. Let me know if you get it to work. Feb 24, 2023 at 18:15
  • That's exactly the correct approach it seems like: BunnyMerz gave a great answer that does exactly that. After implementing that into the system it works great and completed the minigame.
    – user300373
    Feb 24, 2023 at 19:13

1 Answer 1

0

First, a response to your tries: When you type RED or BLUE, it looks for the players with that exact name. Since they don't exist, the if command is false, thus doing nothing, rather than an error.

You'll want to add up everyone's score into another one and then compare them. To do this, you'll want to execute as every player in a team and add that to a fake player's score (basically giving a score to a player with a name that is impossible to have, such as special characters $ or #). You'll also want to clear this score to 0 before or after the commands, so that it doesn't affect other games' scores. Here is a non-tested code for this soulution:

/scoreboard players set $BlueTeam Kills 0
/scoreboard players set $RedTeam Kills 0
/execute as @a[team=BLUE] run scoreboard players operation $BlueTeam Kills += @s Kills
/execute as @a[team=RED] run scoreboard players operation $RedTeam Kills += @s Kills

And now you can do whatever you want with those scores, just like your question's examples:

/execute if score $BlueTeam Kills = $RedTeam Kills run ...

A small note here, I would not use physical things (such as summoning arrows) to trigger other commands. Instead, you can just write more commands with that exact same if statement at the start of every next command, it would be a bit tedious, but avoids failure with such summon commands. You could even look into datapacks which are just as easy as command blocks, but gives you an option of running functions and easier copy-paste.

2
  • Absolutely spot on answer. I was at the edge of my knowledge with that one and this completed the puzzle and added a lot of future possibilities for me. But: Is there any way to hide it from the sidebar? ($BlueTeam, etc)
    – user300373
    Feb 24, 2023 at 19:08
  • You can use other scoreboards, rather than Kills itself. Notice that in the operations subcommand, it asks for both the source and target's scoreboard. Something like this: /execute as @a[team=BLUE] run scoreboard players operation $BlueTeam [[Something else here]] += @s Kills. Just don't forget to also change the conditional scoreboard.
    – BunnyMerz
    Feb 24, 2023 at 19:22

You must log in to answer this question.