Hi Guys, I'm looking for a way to permanently detect if the closest of a certain entity (for example skeleton) is anywhere below the players current y position (x and z don't matter) to give the player a special tag in this situation.
create a scoreboard objective named "PosY" of type "dummy", then
make a line of command blocks like I did in the included picture and paste these in them:
1.
execute as @a at @s run execute store result score @e[type=minecraft:skeleton,distance=..50,limit=1,sort=nearest] PosY run data get entity @e[type=minecraft:skeleton,limit=1,sort=nearest] Pos[1]
2.
execute as @a run execute store result score @s PosY run data get entity @s Pos[1]
3.
execute as @a at @s run execute as @e[type=minecraft:skeleton,distance=..50,limit=1,sort=nearest] run scoreboard players operation @s PosY -= @p PosY
4.
execute as @a at @s if entity @e[type=minecraft:skeleton,distance=..50,scores={PosY=..-1}] run tag @s add SpecialTag
5.
execute as @a at @s unless entity @e[type=minecraft:skeleton,distance=..50,scores={PosY=..-1}] run tag @s remove SpecialTag
the 5th command automatically removes the tag from the player if the entity is no longer below the player: If you want the tag to stay, just skip that command.
Be sure to adjust the values in the commands to your needs (entity_type, distance, and SpecialTag)
EDIT: sorry i forgot to include the picture, here it is
Great, thank you! That works so far and really helped me a lot!
In the meantime, I was also able to find out how to successfully customize your commands a little bit in order to use this also in several different situations. (For example to also check for other entities above the player by using {PosY=2..}.
But I'm still not understanding completely what is happening there. (I have not much experience with scoreboard stuff.)
Could you briefly describe which part is doing what in the first 4 steps? Or alternatively, give me a link where to investigate the mechanisms myself?
Thanks! Already great help so far!
Edit: I know how to use everything about execute and selectors, just the more advanced scoreboard commands are unclear to me.
The first command is storing the y pos of the nearest skeleton to the objective PosY
The second command is strong the players y pos in the players PosY object,
The third command is subtracting the skeletons PosY from the players PosY, example: if the player is at y=10 and the skeleton is at y=5 that will result in 5-10=-5, and now -5 is stored in the skeletons PosY object
The fourth command is testing the skeletons PosY value to see if the result of the subtraction is negative (-1 or below -1) and if it is, that means the entity is under the player.
Now let's turn this around and say that the player is at y=5 and the skeleton is at y=10, this results in 10-5=5 and now when the fourth command tests the result it will not give the player the tag because the value is positive (bigger than -1)
I hope you understand how it works now. If the value is negative the entity is below the player and if the value is positive the entity is above the player.
Hi Guys, I'm looking for a way to permanently detect if the closest of a certain entity (for example skeleton) is anywhere below the players current y position (x and z don't matter) to give the player a special tag in this situation.
Thanks!
create a scoreboard objective named "PosY" of type "dummy", then
make a line of command blocks like I did in the included picture and paste these in them:
the 5th command automatically removes the tag from the player if the entity is no longer below the player: If you want the tag to stay, just skip that command.
Be sure to adjust the values in the commands to your needs (entity_type, distance, and SpecialTag)
EDIT: sorry i forgot to include the picture, here it is
Command block engineer // Developer // #TeamTrees
Great, thank you! That works so far and really helped me a lot!
In the meantime, I was also able to find out how to successfully customize your commands a little bit in order to use this also in several different situations. (For example to also check for other entities above the player by using {PosY=2..}.
But I'm still not understanding completely what is happening there. (I have not much experience with scoreboard stuff.)
Could you briefly describe which part is doing what in the first 4 steps? Or alternatively, give me a link where to investigate the mechanisms myself?
Thanks! Already great help so far!
Edit: I know how to use everything about execute and selectors, just the more advanced scoreboard commands are unclear to me.
The first command is storing the y pos of the nearest skeleton to the objective PosY
The second command is strong the players y pos in the players PosY object,
The third command is subtracting the skeletons PosY from the players PosY, example: if the player is at y=10 and the skeleton is at y=5 that will result in 5-10=-5, and now -5 is stored in the skeletons PosY object
The fourth command is testing the skeletons PosY value to see if the result of the subtraction is negative (-1 or below -1) and if it is, that means the entity is under the player.
Now let's turn this around and say that the player is at y=5 and the skeleton is at y=10, this results in 10-5=5 and now when the fourth command tests the result it will not give the player the tag because the value is positive (bigger than -1)
I hope you understand how it works now. If the value is negative the entity is below the player and if the value is positive the entity is above the player.
Command block engineer // Developer // #TeamTrees
OK, I get it. Thank you very much!