777
This series of tutorials will teach you how to create your very own data packs, assuming you know absolutely nothing about commands. Although data packs could just contain files that replace built-in assets like resource packs, these posts will focus on adding new features and mechanics to the game. In every part I assume you've read the previous parts.
This is Part 1 of 2, focused on the casual use of the scoreboard by server administrators for example.
All possible criteria can be found here. Note the "dummy" criteria, this is an objective that does not change scores by itself and is perfect to keep track of variables in your data pack. Also notice the tiny mention indicating that all statistics can be used as scoreboard objectives as well. Every time a statistic of a player would increase, so would the score of the player in that objective of the same type.
You can remove an objective using:
The player parameter can be any of the following:
Imagine being an admin on a server hosting a PvP event. Add health bars to the tab list and a kill counter as sidebar. Make sure to use some fancy coloured text as display name. Also create a secondary objective filled with custom text to promote your (imaginary) server. Use the score values to order the pieces of text. Then simply create a redstone clock to switch every couple seconds between the kills and the server promotion sidebar.
Subscribe if you want to get notified of new posts.
Introduction
The main purpose of the scoreboard is to generate numbers, which can be used to target players in commands. Think about health, armor, hunger bars, amount of jumps, xp, amount of chests opened, amount of deaths and even how many times you tuned a noteblock. Those numbers are stored in objectives and are player specific.This is Part 1 of 2, focused on the casual use of the scoreboard by server administrators for example.
Objectives
You can add an objective using:/scoreboard objectives add <name> <criteria> [display]
/scoreboard objectives add deaths deathCount {"text":"Player Deaths","color":"red"}
Keep in mind that names must be unique and as a data pack creator, you should take extra care of this. A good way of making your objectives unique is by prefixing the name with an abbreviation of your username and datapack name. The uniqueness of datapacks in general is also discussed in this blog. For example, I could prefix all my objectives in a fireworks datapack with "bcfw_", where bc stands for Bertiecrafter. The display name only appears in listings and displays, but is not used in commands. It uses the same JSON format as /tellraw, which is explained in this blog.All possible criteria can be found here. Note the "dummy" criteria, this is an objective that does not change scores by itself and is perfect to keep track of variables in your data pack. Also notice the tiny mention indicating that all statistics can be used as scoreboard objectives as well. Every time a statistic of a player would increase, so would the score of the player in that objective of the same type.
You can remove an objective using:
/scoreboard objectives remove <name>
/scoreboard objectives remove deaths
You can modify the objective display name using:/scoreboard objectives modify <name> displayname <new display name>
/scoreboard objectives modify deaths displayname {"text":"Player Daths","color":"red","bold":true}
You can list all objectives using:/scoreboard objectives list
You can put the objective on display using:/scoreboard objectives setdisplay <displayType> [objective]
/scoreboard objectives setdisplay sidebar deaths
Every type can only display one objective, but one objective can be displayed at multiple locations. You can display the score below a player's nametag using "belowName". Use unicode emojis like ❤ in the display name to make the appearance fancier ("20 ❤" instead of "20 health"). You could also display the scores in the tab list using "list" or display them in a list on the side of the screen using "sidebar". Finally, use "sidebar.team.<color>" to only display the specified objective for people in a team of that color. The /team command won't be covered in this tutorial. In order to clear a display slot, simply don't specify an objective in the command above.Players
Most commands are obvious:/scoreboard players add <player> <objective> <amount> - Adds amount to the player's score
/scoreboard players remove <player> <objective> <amount> - Removes amount from the player's score
/scoreboard players set <player> <objective> <amount> - Sets the player's score to amount
/scoreboard players get <player> <objective> - Gets the player's score for the specified objective
/scoreboard players reset <player> [objective] - Clears all or objective specific scores for that player
/scoreboard players list [player] - Lists all tracked players or objectives + scores for a certain player
The player parameter can be any of the following:
- A target selector, which is explained in the previous blog. This means that any entity can be on the scoreboard, not just players.
- Any other string of text. This is great for custom displays on the sidebar. Make sure to add at least one character not allowed in usernames (this excludes a-z, 0-9 and _), because otherwise a player with that name could join and modify the score based on objective type and other mechanics in your data pack.
- A hidden entry, created by prefixing any string by a hashtag. This is the recommended choice for settings, global variables and constants that are internally used by datapacks. They can never be updated without commands, because player names can't start with a hashtag. Note that they won't appear in any of the locations used by the setdisplay subcommand.
- Simply an asterisk to indicate any of the tracked scores. In contrast to @e, this does include offline players and fake/hidden entries and does not include entities who don't have a score on the scoreboard.
The Health Criteria
The "health" criteria uses specialized rendering. If you put a health objective in the "list" display slot, the scores are displayed as actual health bars by default. You can enable or disable this for any objective using this command:/scoreboard objectives modify <objective> rendertype (hearts|integer)
Challenge Yourself
After every tutorial, I'll include a section where you are challenged to apply what you've learned. I recommend you playing with what you've learned, it helps you getting familiar with new concepts and be able to find solutions to problems. You don't have to do exactly what's written below, you can always challenge yourself in a different way.Imagine being an admin on a server hosting a PvP event. Add health bars to the tab list and a kill counter as sidebar. Make sure to use some fancy coloured text as display name. Also create a secondary objective filled with custom text to promote your (imaginary) server. Use the score values to order the pieces of text. Then simply create a redstone clock to switch every couple seconds between the kills and the server promotion sidebar.
What's next?
Next up we're going to look at the complex side of the scoreboard for use in data packs.Subscribe if you want to get notified of new posts.
Tags |
tools/tracking
4475343
6
function-data-packs-for-dummies-6-the-scoreboard-where-numbers-are-created-stored-and-juggled
Create an account or sign in to comment.
Just a quick (probably long) question.
I wanted to implement random score values to my object and was wondering if there was anyway of achiveing this with java, as the wiki tells me this command only applies to BE edition sadly.
The idea being that when a player mines an ore for example (that being the statistic object) they generate a random score between 1-100 instead of just gaining one score, and if the number is within a certain range (i.e. 1-60) an execute if command could proceed and the block would be broken, loot would drop and eventually the ore would respawn. however, if the random score generated was 61-100 it would count as a fail and instead the score would reset and nothing would happen to the ore (essential the ore would respawn immediately and no loot would drop)
Im essentially trying to add rng % chances (60% success/ 40% fail rate ,etc), is this at all possible in java and if so could you enlighten me with your vast knowledge XD
{
"condition": "value_check",
"value": {
"type": "uniform",
"min": 1,
"max": 100
},
"range": {
"min": 1,
"max": 60
}
}
#function file:
scoreboard players set #value myObj 0
execute if predicate ... run scoreboard players set #value myObj 1
execute if score #value myObj matches 0 run <any command that runs on fail (40%)>
execute if score #value myObj matches 1 run <any command that runs on success (60%)>
# Note that you cannot simply repeat "if predicate" twice, since it would generate 2 different random values.
Players
Most commands are obvious:/scoreboard players add <player> <objective> <amount> - Adds amount to the player's score
/scoreboard players remove <player> <objective> <amount> - Removes amount from the player's score
/scoreboard players set <player> <objective> <amount> - Sets the player's score to amount
/scoreboard players get <player> <objective> - Gets the player's score for the specified objective
/scoreboard players reset <player> [objective] - Clears all or objective specific scores for that player
/scoreboard players list [player] - Lists all tracked players or objectives + scores for a certain player
With that said, I do see something here that could be clarified further:
Fake player names in dummy objectives can still cause conflicts with other players if you aren't careful. Lets say that I have some game that uses a fake player named "Timer". "Timer" will start at 10000 ticks and count down until the game is over. I also want to keep track of every players score for doing something, and I'm using the same dummy objective to pull this off. Now if a player named Timer joins, he can extend the length of the game just by increasing his score! The game could also see the player "Timer"s score equal to the time left in the game, or something else entirely depending on how things are set up!
So how do you get around this problem? Well, instead you can specifically choose to pick a fake player with special characters that you can't use in a normal MC username. For example, I know that there are no players with the username "Timer:", because you can't use a colon when picking a username. Can refer to this link to see acceptable characters for a MC username: https://help.minecraft.net/hc/en-us/articles/360034636712-Minecraft-Usernames
That aside, really good job with these blogs! I might start recommending them to people alongside the Minecraft Wiki now. :)
But i don't know how to detect when people type in chat can you help?