How to execute at the same height as an entity?
You almost had it, you just have to make a huge, flat box that takes the y coordinate of the entity, but ignores x and z. Like this:
/execute at @e[type=area_effect_cloud] run scoreboard players set @a[x=-30000000,z=-30000000,dx=60000000,dz=60000000,dy=1] stunned 1
Notice that I use values for dx
, dy
and dz
, but only offset x
and z
, not y
, that way the game takes the y coordinate of the entity.
If you have a fixed y coordinate, you can also use this for a tiny bit of less lag:
/execute positioned <coordinates> run scoreboard players set @a[x=-30000000,z=-30000000,dx=60000000,dz=60000000,dy=1] stunned 1
And if "stunned" is only ever 1 or 0, you can use tags (archive) instead.