2

I want to use the bossbar command to create a health bar for the players (each seeing ONLY their own health). So I came to the conclusion that there are two main ways to do so:

  1. This is the best but is single player only:

    • Create scoreboard called "health" linked to the player's health
    • Create bossbar called "health"
    • Run command /execute as @a store result bossbar minecraft:health value run scoreboard players get @s health

    This way the bossbar will always be equal in value to your health, but as mentioned, it doesn't work on more than one player. However, it uses only 1 command block.

  2. This one is a pain to do but runs on multiplayer:

    • Create scoreboard called "health" linked to the player's health
    • Create bossbars equal to the amount of health you need it for (in this case the standard 20 HP)
    • Give each bossbar a respective value from 1-20
    • Use the command /execute as @a[scores={health=x}] run bossbar set healthx players @s (x being the amoun of health the bossbar is linked to.)

    It's a complete pain as it needs lots of bossbars and 1 command block per health value.

So I wonder, is it possible to have a simple solution (like n°1) that works on multiplayer (like n°2)?

5
  • Health is a floating point number, so you would need to use a range like 0.5..0.99999. Other than that, good idea, I don't know anything better. Commented Jun 17, 2019 at 14:34
  • 1
    You can maybe use a datapack with a function that would run all the commands for every health value. This would still require a lot of bossbars, but it would only require one command block (I don´t use a lot of datapacks, so it may not even work like that, but I´m pretty sure it does)
    – user232393
    Commented Jun 18, 2019 at 20:19
  • @user232393 At the time I didn't know how to use datapcks, but now I know so I'd just use datapacks now yeah, seems like the best option for now. Commented Apr 2, 2020 at 15:57
  • @user232393 Except for a few very rare edge cases, you don't need any command blocks anymore since datapacks exist. Commented Apr 2, 2020 at 21:33
  • Yeah, since I use datapacks I only use command blocks for quick fixes or testing stuff. mainly stuff that doesn't take long to make and doesn't lag command-wise. Commented Apr 3, 2020 at 1:53

2 Answers 2

1

It is not the result I hoped to come to, but I have eventually just started using the "lots of different bossbars" method. Since I use datapacks this isn't a huge issue anymore in terms of lag. I still need to create hundreds of commands at times, but I made a pythonscript that does it for me and creates a text file with all commands in it. So it only takes a few minutes at max instead of hours. I created a revival system for a hardcore-like multiplayer yesterday and I used 300 bossbars for it (5 minutes revive time, 1 bossbar per second). It runs without problems or lag and was generated using the script.

Script: (this is exactly what I used for mine, I didn't have time to generalise it first)

bossbar = 1001
value = 1
revivemin = 1
revivemax = 20
x = 1
time = 300

fullstring = ""

while (x <= 300):
    strbossbar = str(bossbar)
    strtime = str(time)
    strmin = str(revivemin)
    strmax = str(revivemax)
    strvalue = str(value)
    fullstring = fullstring+('bossbar add '+strbossbar+' {"text":"Revive ('+strtime+'s)","color":"green"}\nbossbar set '+strbossbar+' color green\nbossbar set '+strbossbar+' max 300\nbossbar set '+strbossbar+' players @a[scores={death=1..,revive='+strmin+'..'+strmax+'}]\nbossbar set '+strbossbar+' style progress\nbossbar set '+strbossbar+' value '+strvalue+'\nbossbar set '+strbossbar+' visible true\n\n')
    x += 1
    bossbar += 1
    value += 1
    revivemin += 20
    revivemax += 20
    time -= 1
f = open("output.txt", "x")
f.write(fullstring)
f.close()

Edit: This version has another good side to it compared to the value method as you can give every different bar each own name making it quicker to see your exact health/mana/...

0

You can actually do the same as the multiplayer, but insert a [name=(insert player name)]

/execute as @a[name=McName] store result bossbar minecraft:health value run scoreboard players get @s health

You are however gonna have to set everyone's up with their own command block, having only 1 command with everyone's own bar is not gonna work unless datapacks or mods are added.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.