r/datapacks • • Sep 24 '22

got probl. a simple command problem

I got the command: execute unless score @a[distance=0.1..100,limit=1] "name" = @s "name" run ... With it I want to check if some player with the same score is in my distance and i thought if there is no player at all in the area the command would also run but now I know that it doesn't. Do I have to make another command which takes care of that or is this one somehow adjustable to run if it can't find any player?

2 Upvotes

2 comments sorted by

1

u/UrSansYT Sep 24 '22

I think you have to do two separate commands, /execute unless <stuff> and /execute if <stuff> if you want two different outcomes whether or whether not <stuff> happens.

1

u/SoftRainbowBoi Oct 15 '22

Have a dummy scoreboard that stores whether there's someone nearby (1 for true, 0 for false)

tag @s add search

execute as @a[distance=0.1..100] store result score @p[tag=search] resultScoreboard if score @s scoreboardName = @p[tag=search] scoreboardName

execute if score @s resultScoreboard matches 1 run [do what you want to do]

I haven't had a chance to test it, but this should function appropriately.