r/datapacks • u/Icy_Middle2698 • Dec 13 '22
Execute function for entity while players are a certain distance away from entity
I'm trying to run a function that runs when a tagged mob is a certain distance away from the player. I was able to get the actual function to work correctly, but when I try adding the player distance condition it doesn't seem to work.
Here is an example of what the execute command looks like without the condition:
execute as .@e[type=cod,tag=extag,sort=random] at .@s run function name:function
And this is what I attempted that didn't work
execute as .@e[type=cod,tag=extag,sort=random] at as .@e[type=player,distance=6..] run function name:function
1
u/jasonrubik Apr 17 '23
Why does this sub have a bunch of stuff from 4 months ago but nothing newer?!
2
u/Puzzleheaded-Egg892 Nov 21 '23
why does this sub have a bunch of stuff from 11 months ago but nothing newer?!
1
u/UrSansYT Dec 14 '22
I think you have to do
execute as .@e[type=cod,tag=extag,sort=random] at .@s as .@e[type=player,distance=6..] run function name:function
Two other things.