1

Execute commands (need help)

TrulyOmega 1/20/24 12:25 am history
435
1/20/2024 7:16 pm
so, i am trying to execute these commands

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?
Posted by
TrulyOmega
Level 1 : New Explorer
1

  Have something to say?

JoinSign in

8

michaelo
01/20/2024 9:57 am
Level 36 : Artisan Taco Chef
history
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:

execute at @a as @e[​type=minecraft:elder_guardian,distance=..5] run data merge entity @s {yummy data}
Hope that helps!
2
TrulyOmega
01/20/2024 4:53 pm
Level 1 : New Explorer
history
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?
1
michaelo
01/20/2024 7:16 pm
Level 36 : Artisan Taco Chef
history
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:

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!
1
TrulyOmega
01/20/2024 11:58 am
Level 1 : New Explorer
thanks!
1
mega7
01/20/2024 2:50 am
Level 49 : Master Muffin Engineer
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.
2
TrulyOmega
01/20/2024 9:14 am
Level 1 : New Explorer
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
1
TrulyOmega
01/20/2024 9:15 am
Level 1 : New Explorer
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
1
TrulyOmega
01/20/2024 12:37 am
Level 1 : New Explorer
and i need to be able to make these run in a mcfunction
1

Welcome