#setting up a health bar using custom name nbt
1 messages · Page 1 of 1 (latest)
<@&1201956957406109788>
💬 While you wait, take this time to provide more context and details.
✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run /resolve
well you can just prepend the name to your health bar
Sorry, we forgot to ping you, so I ping in this message
in a function, I am running this:
data modify entity @s CustomName set string entity @s Health
data modify entity @s CustomNameVisible set value 1b```
that runs every tick and I can't get it to display health + entity's name
[35mexecute [34mstore result score [36m@s [0mhealth [34mrun [35mdata [34mget entity [36m@s [0mHealth
[35mdata [34mmodify entity [36m@s [0mCustomName [34mset string entity [36m@s [0mHealth
[35mdata [34mmodify entity [36m@s [0mCustomNameVisible [34mset value [32m1b
do you want to display the name and the health in the name of the bossbar?
I didn't plan to have it run through a boss bar, but that is a good point
what do you want to do precisely?
I want the health of the mob and then the mobs name, preferably above it's head 20/20 mob_name kinda like that, if not, I would just like it's current health beside the mob's name
Oh, so not in the bossbar
not sure if they work for entities but have you tried scoreboards?
Oh I suppose it would be more opti than a storage
the health criteria scoreboard doesn't work for entities, so the one I put in here is just a dummy scoreboard
no I mean for the displaying part
Oh, like above name
you can make them display in the name, at least for players
I'm not sure if non players can have that
yeah me niether but it's worth a shot
ill test
what I have so far is the health, as you can see, but can't get the name
It would take the spot for everyone though, wouldn't it?
Like, their couldn't be a different scoreboard in display below_name
Could another scoreboard take the display?
I think it's per world and not per entity
no only one scoreboard can take a special display
yep
so it would lock the spot
how do we even put a non player on a non read only scorebaord
normal?
how is normal 😭
just use a selector to the entity
with what subcommand
execute as @e store result score @s <objective> run data get entity @s Health
*@e
is that necessary if it's already a health scoreboard
it will only track players then
that is what the first line of the function does lol
do health criteria not work in entities?
the function is being targeted to entites already
yes, are we helping you here?
does it work? (probs doesn't)
health criteria doesn't work on non-player entities
no it doesn't work
@true zinc CustomName takes json components (https://minecraft.wiki/w/Raw_JSON_text_format)
so you can set it to something like "{\"selector\":{\"selector\":\"@s\"}}" (not tested)
which should make a string containing the entity's name
then you can also display a space and a score to follow it
i have it set up like this now, but it still doesn't work
scoreboard players display name @s health "@s"
data modify entity @s CustomName set value "{\"score\":{\"objective\": \"health\",\"name\": \"@s\"}}"
data modify entity @s CustomNameVisible set value 1b```
data modify entity @s CustomName set value "{ \"score\": \"\",\"color\":\"#956620\"}" I tweaked it and now it is giving me a expected a map-like
<@&1166082198152159386> <@&1202694677766348840>
Please note that you still might not immediately get a response since all helpers are human beings and volunteers (and also might be sleeping right now)
what doesn't work about this?
I want the health to display preferably before the name, but this entirely replaces the name, but it isn't displaying anything
hmm ok
if you modify the entities' name every tick like thi, I think it should work ```ansi
[35mexecute [34mstore result score [36m@s [0mhealth [34mrun [35mdata [34mget entity [36m@s [0mHealth
[35mdata [34mmodify entity [36m@s [0mCustomName [34mset value [32m"[{"score":{"objective": "health","name": "@s"}},{"selector":"@s"}]"
testing it in a sec
idk if this works tho
since the name of the entity contains the name
there still is a sencond option tho
but it's less performant
the name just becomes @s
hmm yea
is there a way to store the name of the entity in the entity itself?
or does it need to be every entity?
hmmm
otherwise you could just store it's name and then modify it's actual name with the score infront
I think there would be a problem with this because there will be multiple entities
if you store the name in the entity itself you can just display it directly
wait
I have an idea but I'm going to test it first
would it be easier to have a text display above or below the entity name if the entities are standing still? because they will almost definitely be standing still
did ur thing not work?
nope i tried maby if you set the display mode of a scoreboard to display below name maby it would also work for entities but nope 😦
scoreboard players display name @s health "@s"
data modify entity @s CustomName set value "[{\"score\":{\"objective\": \"health\",\"name\": \"@s\"}},{\"selector\":\"@s\"}]"
data modify entity @s CustomNameVisible set value 1b``` this is what I had wrote in the function that runs every tick
thats not haw that works
huh
[35mscoreboard [34mobjectives setdisplay [0mbelow_name health
thats what I tried
I still dont know what is wrong with my function
also, how do you get the text to be like that?
ok
do u know what is wrong with it?
well in your function your first setting the entity's health into a score then you're setting the displayname of that score to @s literaly the text then you're displaying the number of the score with the entity's name after it which does not work since it would create an infinite loop and then you're setting the name always visible
so yea the commands work but it does not really make sense
what?
second line
yap
?
it will become @s
yap because it's an infinite loop and the game doesn't like that so to prevent a crash it just puts @s there
[35mdata [34mmodify entity [36m@s [0mCustomName [34mset string entity [36m@s [0mHealth
``` somehow this was working better
what the second line for
if you remove it it should work
No if I remove the second line, it changes to @s
try
[35mexecute [34mstore result score [36m@s [0mhealth [34mrun [35mdata [34mget entity [36m@s [0mHealth
[35mdata [34mmodify entity [36m@s [0mCustomName [34mset value [32m"[\"\",{\"selector\":\"@s\",\"color\":\"aqua\"},{\"text\":\" [\",\"color\":\"gold\"},{\"score\":{\"name\":\"@s\",\"objective\":\"health\"}},{\"text\":\"]\",\"color\":\"gold\"}]"
[35mdata [34mmodify entity [36m@s [0mCustomNameVisible [34mset value [32m1b
nope {\"selector\":\"@s\",\"color\":\"aqua\"} doesn't work
you cannot use a selector inside an entity's name
if the selector points to that entity
so no ideas on how?
yea just a text display
[35mexecute [34mstore result score [36m@s [0mhealth [34mrun [35mdata [34mget entity [36m@s [0mHealth
[35mdata [34mmodify entity [36m@s [0mCustomNameVisible [34mset value [32m1b
[35mexecute [34mas [36m@s [34mat [36m@s [34munless entity [36m@e[33m[[37mtag[34m=[32mhealth_display[34m,[37mdistance[34m=[35m..[32m2[33m] [34mrun [35msummon [0mtext_display [32m^ ^1.5 ^ [33m{[37mTags[34m:[35m[[37mhealth_display[35m][34m,[37mtext[34m:[32m'{"color":"red","score":{"name":"@e[tag=enemy,distance=..2]","objective":"health"}}'[33m}
``` the text display shows nothing
I found a problem with text displays. if I have multiple enemys, the scoreboard only updates with the one that was damaged last
would it be easier to raycast and see which entity the player is looking at and then store that in a bossbar?
I think I figured it out
If your question is resolved, that's great to hear! Make sure to run /resolve or click the Resolve Question button. Otherwise, feel free to continue asking for help! :D