How to detect two entities at the same coordinate with same name tag? [closed]

Actually, when I'm putting the command

/execute @e[name=Mark] ~ ~ ~ /execute @e[name=Mark] ~ ~ ~ /scoreboard players set @e[name=Mark] detect 1

I'm expecting that if only these two same name entities where together then the scoreboard will be "1". But it doesn't, cause it turns to "1" even if I summon only a single "mark" in my world.


Solution 1:

Nice try! However, you're experiencing this because @e selects all instances of that entity, including itself, which is the same reason why @p executed by a player is himself.


Try making your detection additive.

In a repeater (as in not Redstone Repeater, but the Repeater and Chain Command Blocks) chain, do:

/scoreboard players set @e[name=Mark] detect 0
/execute @e[name=Mark] ~ ~ ~ /execute @e[name=Mark,r=__] ~ ~ ~ /scoreboard players add @e[name=Mark] detect 1

Now, all you need to do to select all the Marks that are nearby (within r=__ blocks) is to test for anyone with a score of at least 1.

/execute @e[score_min_detect=1] ...

Why this works?

This is because if we are to only have one Mark, his score would always be one since he's the only one executing it.

If there are multiple nearby Marks, then the /scoreboard players add will stack and obviously yielding scores greater than 1.

As for why wouldn't this go into infinity? It's because we reset it after every redstone tick:

/scoreboard players set @e[name=Mark] detect 0