TransWikia.com

How to detect if multiple players have the same scores?

Arqade Asked on September 4, 2021

This is my command, it should only activate if all players have avance score on 0:

/execute if entity @a[scores={avance=0}]

I thought that with @a it would only be true if ALL players have that condition, but the command block output says “Test Passed, count 1”
and that screws up the whole circuit as it depends on the command output being “Test Passed” only when all players have the same score on 0 to work.

2 Answers

There are multiple solutions, the easiest is to check if no player does not fulfill the condition:

/execute unless entity @a[scores={avance=1..}] unless entity @a[scores={avance=..-1}]

You can also add limit=1 to both of these selectors to improve performance. Thanks to vdvman1 for this tip.

Correct answer by Fabian Röling on September 4, 2021

scoreboard objectives add test dummy "Test"
execute as @a run scoreboard players add $c test 1
execute as @a if score @s avance matches 0 run scoreboard players add $m test 1

First, count players. And then, count players that avance score is 0

execute if score $m test = $c test run say Same!

Finally, if players count is same as players that avance is 0, say Same!

Answered by Minco on September 4, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP