3

I would like to use a bossbar, with value set with execute store result bossbar, to hold the 'mana' value for each player in my datapack (which is held in a scoreboard so it can be manipulated in the background by various functions).

However, I can't find an option for which player's value to set, and can only find a setting for which players the bossbar is visible for. Are bossbar values global or would I need to make one bossbar per player that I want to display a mana amount for?

If bossbar values are global, what alternatives are there for making some type of bar type display? I don't want to use scoreboard numbers because they are ugly. I'm open to particles, resource packs, anything but mods really.

4

You can make one bossbar per mana level, rather than per player. To make a mana system where you can have between 0 and 4 mana you would have to first create the bossbars, set their values, and set their maximal values. You only need to do this once:

bossbar add mana0 "Mana"
bossbar add mana1 "Mana"
bossbar add mana2 "Mana"
bossbar add mana3 "Mana"
bossbar add mana4 "Mana"

bossbar set minecraft:mana0 max 4
bossbar set minecraft:mana1 max 4
bossbar set minecraft:mana2 max 4
bossbar set minecraft:mana3 max 4
bossbar set minecraft:mana4 max 4

bossbar set minecraft:mana0 value 0
bossbar set minecraft:mana1 value 1
bossbar set minecraft:mana2 value 2
bossbar set minecraft:mana3 value 3
bossbar set minecraft:mana4 value 4

You would then repeatedly (each tick) set the players for each bossbar.
I'm assuming that the mana value is held in a scoreboard objective with the objective name mana. If that is not the case for you, then you may have to modify these commands.

bossbar set minecraft:mana0 players @a[scores={mana=..0}]
bossbar set minecraft:mana1 players @a[scores={mana=1}]
bossbar set minecraft:mana2 players @a[scores={mana=2}]
bossbar set minecraft:mana3 players @a[scores={mana=3}]
bossbar set minecraft:mana4 players @a[scores={mana=4..}]
|improve this answer|||||
  • This is a great answer for if you have less than 200 maximum mana, but unfortunately for me it might work less well. Depends on how much lag having that many bossbars would create. I will probably use it anyway though. – Nik3141 Jul 7 '19 at 22:56
  • @Nik3141 You can maybe cheat a little by giving each bossbar a range, so mana1 would maybe be for mana levels 1..4, you would then only need about 50 bossbars for a score of up to 200. – user232393 Jul 7 '19 at 22:59
  • I would maybe recommend to have a scoreboard objective for how many players are currently in the world. If it's only one, then you may use a different, single bossbar, instead of rotating through all of them. – user232393 Jul 7 '19 at 23:01
  • Ok I'll do that. Have some rep for the "one bossbar per mana level, rather than [one bossbar] per player" insight. – Nik3141 Jul 7 '19 at 23:03
  • @Nik3141 I actually had the idea, because I remembered this question: gaming.stackexchange.com/questions/352941 – user232393 Jul 7 '19 at 23:12
4

Bossbar values are global, yes. If you have a limited number of players, you could just make multiple boss bars and display each to just one player. If you could have an arbitrarily high amount of players or don't want to put in that much effort to create boss bars for everyone, then you could use the XP bar instead, using /xp set <selector> <number> points.

|improve this answer|||||
  • Yeah I don't want to use the xp bar because I want xp to have it's normal functionality, and I have an arbitrarily large amount of players. I think I'll create an empty bossbar and create particles 'inside' it based on the amount of mana the player has. I'll make it an answer when I finish it. – Nik3141 Jul 7 '19 at 2:13
  • Oh wait, now I remember: SimplySarc did exactly what you are trying to do! youtube.com/watch?v=SbdLNsWn7aI – Fabian Röling Jul 7 '19 at 2:45
  • I like that idea, but it disables the use of the offhand, which is important in my case: a survival friendly datapack. The solution I put is not pretty, but it works, and hopefully in the future Mojang will add more options to display a scoreboard, or two types of bossbars: global and per person. – Nik3141 Jul 7 '19 at 3:27
2

So what I decided was that I would have the mana bar cycle through every player's mana value one player per tick, so that it would appear to "flicker" with the correct value. It is super ugly, but works when you have less than ten total players. The one I made changes once per tick but one changing every four ticks might be better, because then it would be flashing rather than flickering.

First, I set up an ID system, so whenever a player joins the game, the global ID scoreboard is incremented and the new player gets a new ID value. In this way, every player has a unique id number.

Then, I run this function, which uses recursion to get the next player who is online, once every tick. It adds one to the manaTimer value, resetting it if it reaches the player with the highest ID. Then, if the player with the current manaTimer value's ID is not online (or, stated differently, unless he is online), run the function again, increasing once per repetition, so it ends up at the next player who is online. In this way, if there's one player online it will stay on, if there's two it will flicker at 10hz, if there's 4 it will go at 5hz, etc. ID and manaTimer are fake players in the objective global.

scoreboard players add manaTimer global 1
execute if score manaTimer global >= ID global run scoreboard players set manaTimer global 1
execute as @a unless score @s playerID = manaTimer global run function dark_magic:tick_functions/get_next_player

Then, I have another function running once per tick. It has three commands, which first make the bossbar invisible to everyone, then store the currently displayed player's mana score in the bossbar, and finally make the bossbar visible to that player.

bossbar set minecraft:mana players @s[tag=nobody]
execute as @a if score @s playerID = manaTimer global run execute store result bossbar minecraft:mana value run scoreboard players get @s mana
execute as @a if score @s playerID = manaTimer global run bossbar set minecraft:mana players @s

It's not pretty, but it works. I will probably optimize it so it flickers at different speeds depending on how many people are online.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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