Minecraft Scoreboards

I was thinking how cool it would be to have a mod to keep track of how much diamond everyone mines… I was actually thinking it’d be cool to track levels earned, but that doesn’t appear possible without mods - tracking blocks mined is possible with vanilla server and zero mods.

We figured this out today:

/scoreboard objectives add Diamond stat.mineBlock.minecraft.diamond_ore
/scoreboard players add @a Diamond 0
/scoreboard objectives setdisplay sideBar Diamond

Note: only adds players that are online, so you’ll have to repeat the second line for each offline player that joins. I’m thinking about trying my hand at writing a mod that will automatically add each player as they connect.

Update: So I added a few more things to track to the scoreboard: timePlayed, kills, and deaths. I need to do this for every new player:

/scoreboard players add <playername> Diamond 0
/scoreboard players add <playername> Deaths 0
/scoreboard players add <playername> Kills 0
/scoreboard players add <playername> Timeplayed 0

I then used a Python NBT parsing library to parse the scoreboard.dat file (I’m going to clean up the code a bit and submit a pull request to the examples/ folder, so code is coming) and dump it out in a JSONP file in a web-accessible directory.

Then I hacked up an example sortable table in jQuery, using jQuery to load the data from the JSONP file into a pretty, sorted table.

All that’s required now is to add some error checking and put the script in crontab.

Update: I’ve been unable to track down the guide to writing mods I found but neglected to bookmark - I seem to recall it being something like “Minecraft mods for Adults” or something, but googling that particular search term is horrifying.

Since we use a white list anyway, I wrote a script to whitelist a player and initialize the scoreboards in one shot, which can be run from the console:

#! /bin/bash

scrn="Minecraft server"

# check if argument exists
if [ $# -ne "1" ]
    echo "Usage: $0 <username>"

echo 'Whitelisting: ' $1

read -r -d '' out << EOM
whitelist add $1
scoreboard players add $1 Diamond 0
scoreboard players add $1 Deaths 0
scoreboard players add $1 Kills 0
scoreboard players add $1 Alive 0
scoreboard players add $1 Played 0
say New player whitelisted: $1

screen -S "$scrn" -p 0 -X stuff "$out$(printf \\r)"

Update #2: So I’m not sure if it’s always been this way, or if it’s part of a recent update, but I no longer need to manually add users to the scoreboard. When a user joins, they’ll automatically get added to the scoreboards as they trigger it (so timeplayed will be immediate, deaths will be on the first death, diamond on the first diamond, etc).

So running these commands on the server after the world is started the first time seems plenty:

scoreboard objectives add Diamond stat.mineBlock.minecraft.diamond_ore
scoreboard objectives add Deaths stat.deaths
scoreboard objectives add Kills stat.mobKills
scoreboard objectives add Time stat.playOneMinute
scoreboard objectives add Level level
scoreboard objectives add Alive stat.timeSinceDeath

Another thing I’ve taken to doing is burying command blocks in a wall somewhere to switch the scoreboard on the sidebar, by putting (for example) scoreboard objectives setdisplay sidebar Diamond into the command block, then putting a button on the wall in front of it. I’d originally hoped to put these in a sort of temple near the world spawn, so that users couldn’t smash up the wall hiding them, but unfortunately non-operators can’t interact with redstone mechanics whatsoever inside the protected area - which seems a really stupid limitation.

I’ve also had a few ideas on assembling teams, for example making a button that automatically assigns a user to a team. We had some success with this, but I didn’t document how we managed it. I turned on PVP but turned off PVP for players on the same team, and automatically put everyone onto a Default team, which meant we could play without PVP. Then when users wanted to PVP they could join either a red or blue team and battle in an arena - but restoring them to the default “team” after they left was problematic and relied mostly on the honor system. I think doing something like that on a server would require mods. :(

Horsham, VIC, Australia fwaggle



Filed under:


Horsham, VIC, Australia

Navigation: Older Entry Newer Entry