TransWikia.com

What's a good way to make a health bar using the bossbar command (For multiplayer pursposes)

Arqade Asked by Wicked Grinn on February 7, 2021

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)?

2 Answers

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.

Answered by Anonymous Gamer on February 7, 2021

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 greennbossbar set '+strbossbar+' max 300nbossbar set '+strbossbar+' players @a[scores={death=1..,revive='+strmin+'..'+strmax+'}]nbossbar set '+strbossbar+' style progressnbossbar set '+strbossbar+' value '+strvalue+'nbossbar set '+strbossbar+' visible truenn')
    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/...

Answered by Wicked Grinn on February 7, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP