Minecraft – Execute Command at Entity with Same Score

minecraft-commandsminecraft-java-edition

Assuming that there is only one entity with that same score for that objective

What I'm trying to do is, if certain conditions are met for one entity, it will execute a command at another entity with the same score for that objective (one way). Is that even possible?

Best Answer

I'm a bit late, but I know a solution for your problem, so I thought I'd post it anyway. This is a method that I have used before to execute a command at entities with a similar score. This method works for minecraft 1.12

Let's pretend there are two different types of entities: armorstands and zombies. Each armorstand has a unique score and so have the zombies.

Let's also say there are two scoreboards: standScore and zombieScore.
For this method I need one extra scoreboard. I'll call it math.

Execute some command at armorstands with the same score as a certain zombie:

# set math score for each armor stand to their personal score
execute @e[type=armor_stand] ~ ~ ~ scoreboard players operation @s math = @s standScore

# subtract the score of this certain zombie from all the armorstands
scoreboard players operation * math -= [certain zombie] zombieScore

# all armor stands with the same score as the zombie, now have a score of 0 on the math objective
execute @e[score_math_min=0,score_math=0] ~ ~ ~ [some command]

# make sure that the math objective is cleaned after use to prevent errors in later commands

You can also do this the other way around, but you better use an extra math objective to store all the zombie entities, just to be sure.

This method has one drawback, which is that all the entities have to be inside render distance, because otherwise they don't get targeted by the target selectors.

I hope this helps