#setting up a health bar using custom name nbt

1 messages · Page 1 of 1 (latest)

true zinc
#

I have got the health bar for a non-player entity, I want it to contain the name of the entity or the custom name i've already given it. ping with response. if u need the commands, tell me

steady wyvernBOT
#

<@&1201956957406109788>

Someone will come and help soon!

💬 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

lavish jacinth
#

well you can just prepend the name to your health bar

drowsy hemlock
#

Yep

#

I think you will have to use macros, but it shouldn't be very hard

drowsy hemlock
true zinc
#

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

north streamBOT
#
execute store result score @s health run data get entity @s Health
data modify entity @s CustomName set string entity @s Health
data modify entity @s CustomNameVisible set value 1b
drowsy hemlock
true zinc
#

I didn't plan to have it run through a boss bar, but that is a good point

drowsy hemlock
#

what do you want to do precisely?

true zinc
#

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

drowsy hemlock
#

Oh, so not in the bossbar

lavish jacinth
#

not sure if they work for entities but have you tried scoreboards?

drowsy hemlock
#

Oh I suppose it would be more opti than a storage

true zinc
lavish jacinth
#

no I mean for the displaying part

drowsy hemlock
#

Oh, like above name

lavish jacinth
#

you can make them display in the name, at least for players

drowsy hemlock
#

I'm not sure if non players can have that

lavish jacinth
#

yeah me niether but it's worth a shot

drowsy hemlock
#

ill test

true zinc
#

what I have so far is the health, as you can see, but can't get the name

drowsy hemlock
#

Like, their couldn't be a different scoreboard in display below_name

lavish jacinth
#

what?

#

it only display on entities with a scoreboard entry

drowsy hemlock
#

Could another scoreboard take the display?

#

I think it's per world and not per entity

lavish jacinth
#

no only one scoreboard can take a special display

drowsy hemlock
#

yep

#

so it would lock the spot

#

how do we even put a non player on a non read only scorebaord

lavish jacinth
#

normal?

drowsy hemlock
#

how is normal 😭

lavish jacinth
#

just use a selector to the entity

drowsy hemlock
#

with what subcommand

lavish jacinth
#

execute as @e store result score @s <objective> run data get entity @s Health

#

*@e

drowsy hemlock
#

is that necessary if it's already a health scoreboard

lavish jacinth
#

it will only track players then

true zinc
drowsy hemlock
true zinc
#

the function is being targeted to entites already

lavish jacinth
drowsy hemlock
#

well i didn't know that

#

Anyways hmm

lavish jacinth
#

does it work? (probs doesn't)

true zinc
#

health criteria doesn't work on non-player entities

drowsy hemlock
lavish jacinth
#

@true zinc CustomName takes json components (https://minecraft.wiki/w/Raw_JSON_text_format)

Minecraft Wiki

Raw JSON text is the format Minecraft uses to send and display rich text to players. It can also be sent by players themselves using commands and data packs. Raw JSON text is written in JSON, a human-readable data 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

true zinc
#

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```
true zinc
#

data modify entity @s CustomName set value "{ \"score\": \"\",\"color\":\"#956620\"}" I tweaked it and now it is giving me a expected a map-like

steady wyvernBOT
# steady wyvern <@&1201956957406109788>

<@&1166082198152159386> <@&1202694677766348840>

🙇 Helpers Arise!

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)

upbeat smelt
#

what do you want to do?

#

show the health number after the entity name?

upbeat smelt
true zinc
#

I want the health to display preferably before the name, but this entirely replaces the name, but it isn't displaying anything

upbeat smelt
#

hmm ok

north streamBOT
#

if you modify the entities' name every tick like thi, I think it should work ```ansi
execute store result score @s health run data get entity @s Health
data modify entity @s CustomName set value "[{"score":{"objective": "health","name": "@s"}},{"selector":"@s"}]"

true zinc
#

testing it in a sec

upbeat smelt
#

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

true zinc
#

the name just becomes @s

upbeat smelt
#

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?

true zinc
#

hmmm

upbeat smelt
#

otherwise you could just store it's name and then modify it's actual name with the score infront

true zinc
upbeat smelt
#

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

true zinc
#

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

upbeat smelt
#

maby but lemme first try this

#

hmm yea the text display will be the way to go

true zinc
#

did ur thing not work?

upbeat smelt
#

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 😦

true zinc
#
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
upbeat smelt
#

thats not haw that works

true zinc
#

huh

north streamBOT
#
scoreboard objectives setdisplay below_name health
upbeat smelt
#

thats what I tried

true zinc
#

I still dont know what is wrong with my function

#

also, how do you get the text to be like that?

upbeat smelt
#

and then enter and type what you want

#

and then close with ```

true zinc
#

ok

true zinc
upbeat smelt
#

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

true zinc
#

right

#

if I remove that it just becomes @s as the name again

upbeat smelt
#

what?

true zinc
#

second line

upbeat smelt
#

yap

true zinc
#

?

upbeat smelt
true zinc
#

why is what I wonder

#

is it because of the {selector} part

upbeat smelt
north streamBOT
#
data modify entity @s CustomName set string entity @s Health
``` somehow this was working better
lavish jacinth
#

if you remove it it should work

true zinc
#

No if I remove the second line, it changes to @s

north streamBOT
#

try

execute store result score @s health run data get entity @s Health
data modify entity @s CustomName set value "[\"\",{\"selector\":\"@s\",\"color\":\"aqua\"},{\"text\":\" [\",\"color\":\"gold\"},{\"score\":{\"name\":\"@s\",\"objective\":\"health\"}},{\"text\":\"]\",\"color\":\"gold\"}]"
data modify entity @s CustomNameVisible set value 1b
upbeat smelt
#

you cannot use a selector inside an entity's name

#

if the selector points to that entity

true zinc
#

so no ideas on how?

upbeat smelt
#

yea just a text display

north streamBOT
#
execute store result score @s health run data get entity @s Health
data modify entity @s CustomNameVisible set value 1b
execute as @s at @s unless entity @e[tag=health_display,distance=..2] run summon text_display ^ ^1.5 ^ {Tags:[health_display],text:'{"color":"red","score":{"name":"@e[tag=enemy,distance=..2]","objective":"health"}}'}
``` the text display shows nothing
true zinc
#

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?

true zinc
#

I think I figured it out

steady wyvernBOT
# true zinc I think I figured it out
🎗️ Is your question resolved?

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