Execute on all players within stored distance

I want to execute a command on all players withhin a distance from an armorstand (Let's call him "A"). The distance is stored in the scoreboard "Distance" for that armorstand ("Distance" of A is e.g. 13). This means that `execute as @e[name=A] at @s as @a[distance=..13] ...` doesn't do the trick, because the 13 is a constant here and I don't really want a command for every possible distance from 1 to 100.

I had the idea to store the distance of all players to that armorstand in their "Distance"-score and then compare the 2 scores for every player. But I don't know a way to store the distance in an scoreboard or to get it with a command.

Is there a way to do this?

• What do you mean by "doesn't do the trick....from 1 to 100"? Also, by "comparing distance, do you want to find the nearest player? Commented Sep 9, 2020 at 11:53
• @fasterthanlight I would need one command for every possible distance, which I don't want if avoidable. But I also want to be able to change the distance for the armorstand without changing the code. Commented Sep 9, 2020 at 12:27
• Have you tried taking a scoreboard variable and tweaking it with seperate commands, and taking that value as the max distance? Commented Sep 9, 2020 at 12:57
• @fasterthanlight This pretty much exactly the question. How do I take that value as the max distance? Commented Sep 9, 2020 at 13:11
• Ok, so you want nothing else but that, right? Commented Sep 9, 2020 at 13:12

• Take first entity with as `@e[tag=a]`, Take the second entity with `at @e[sort=nearest,limit=1]`
``````execute store result score @s math_in run data get entity @s Pos[0] 100
• To compute the square root, he states to use the `Newton-Raphson, 4 iterations approach`. I don't have the math skills to quickly understand that method, but the results the datapack give are correct. To get the full list of commands, download his datapack.