1
Execute commands (need help)
so, i am trying to execute these commands
every tick (with a tick command) but the selector will not work even if it is @a
it does work if i execute it from the chat box though
anyone know why?
execute store result bossbar minecraft:elder value run data get entity @e[name="The Elder Guardian",limit=1] Healthexecute as @a if entity @e[type=minecraft:elder_guardian,distance=0..5] run kill @e[type=minecraft:elder_guardian]execute as @a if entity @e[type=minecraft:elder_guardian,distance=0..5] run summon elder_guardian ^5 ^ ^5 {CustomNameVisible:1b,CustomName:'{"text":"The Elder Guardian","italic":false}',Attributes:[{Name:generic.max_health,Base:160},{Name:generic.attack_damage,Base:7}]}
run bossbar set minecraft:elder players @a[distance=0..20]every tick (with a tick command) but the selector will not work even if it is @a
it does work if i execute it from the chat box though
anyone know why?
8
I think the issue is that while you are running the command as @a, that doesn't specify the position of the command to run at, only what players run it. In a data pack, commands that don't have a position set run at 0 0.
To fix it you should just be able to change the as @a to at @a, as you don't need the command to be run as the player. In the future, if you want a command to be run both as and at the player, you would write execute as @a at @s. If you're not sure, the wiki is a great place https://minecraft.wiki/w/Commands/execute#Syntax
Also, I don't think you need to summon a new elder guardian, you should be able to just alter the data of the existing one and combine two of the commands. Might look something like this:
Hope that helps!
To fix it you should just be able to change the as @a to at @a, as you don't need the command to be run as the player. In the future, if you want a command to be run both as and at the player, you would write execute as @a at @s. If you're not sure, the wiki is a great place https://minecraft.wiki/w/Commands/execute#Syntax
Also, I don't think you need to summon a new elder guardian, you should be able to just alter the data of the existing one and combine two of the commands. Might look something like this:
execute at @a as @e[type=minecraft:elder_guardian,distance=..5] run data merge entity @s {yummy data}Hope that helps!
michaelo so i now have another problem, i need to heal it to full health, but i cant put it in the tick command, or it will heal instantly and not take damage, what should i do?
Usually the method to get something to only run once is to apply a tag to the entity, which you can use to exclude it in the selector for the next ticks.
I would personally set it out like this:
In the new function you would run all the commands you have for changing the data and bossbar, and then at the end you would add tag @s add updated. This will stop the entity from being detected in the following ticks, because in the selector in the command above I wrote tag=!updated, where the exclamation mark means any entity without the "updated" tag. The entity won't be picked up because it now does have the "updated" tag.
This is also better for performance because it only needs one command to be run in the tick function!
I would personally set it out like this:
execute at @a as @e[type=minecraft:elder_guardian,tag=!updated,distance=..5] run function <new_function>In the new function you would run all the commands you have for changing the data and bossbar, and then at the end you would add tag @s add updated. This will stop the entity from being detected in the following ticks, because in the selector in the command above I wrote tag=!updated, where the exclamation mark means any entity without the "updated" tag. The entity won't be picked up because it now does have the "updated" tag.
This is also better for performance because it only needs one command to be run in the tick function!
thanks!
Did you do the tick.json tag in the minecraft files. Because if you did you must be getting at least the smallest hint it is working. Put a command easy to identify like /say hi in the tick function and if it works. Come back so we can discuss the issue more if you want.
so first i tried to make it run a seperate function (didnt work)
i did do a say hi tho (it worked)
so i think its the selector i have, but i also wanted to run a seperate function instead of the commands (i just really need the commands to run for this)
here is the datapack(it has some stuff for other things)
www.mediafire.com/file/mn035coyyhl3z6c/Datapack.zip/file
i did do a say hi tho (it worked)
so i think its the selector i have, but i also wanted to run a seperate function instead of the commands (i just really need the commands to run for this)
here is the datapack(it has some stuff for other things)
www.mediafire.com/file/mn035coyyhl3z6c/Datapack.zip/file
it is the distance parameter i am having trouble with
if i execute as @a it should work but it doesn't unless i do it in the chat box
if i execute as @a it should work but it doesn't unless i do it in the chat box
and i need to be able to make these run in a mcfunction
