TransWikia.com

Execute on all players within stored distance

Arqade Asked by IceFreez3r on December 5, 2020

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?

One Answer

I found a solution on YouTube:

.

Here is essentially what he is doing:

  • Take first entity with as @e[tag=a], Take the second entity with at @e[sort=nearest,limit=1]
  • Read and store the Position of both entities with
execute store result score @s math_in run data get entity @s Pos[0] 100
  • Compute the lengths x2-x1, y2-y1, z2-z1, square and add them
  • 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.

Correct answer by IceFreez3r on December 5, 2020

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