-
Notifications
You must be signed in to change notification settings - Fork 4
Creating Scoreboards
Alexander edited this page Mar 13, 2019
·
2 revisions
Here we have an example that will give all players a scoreboard and update it with a player counter Note Java and bedrock sorts scoreboard lines differently
function PlayerJoinEvent(event){
var player = event.getPlayer();
player.sendMessage("Welcome to the Server!");
//Here we set a simple variable to be the amount of players online.
var online = server.getOnlinePlayers().size();
//Here we set another simple variable to be our max players amount
var maxPlayers = server.getMaxPlayers();
//here we create our scoreboard
var sc = scoreboard.create();
//here we create an display / objective
var dp = scoreboard.newDisplay(sc, "Test Scoreboard");
//here we add some lines to our display / objective
scoreboard.setLine(dp, "Hello "+player.getName(), 2);
scoreboard.setLine(dp, "There is currently", 1);
scoreboard.setLine(dp, online + " out of " + maxPlayers, 0);
//here we set our player's scoreboard to our new one
scoreboard.set(player, sc);
}
manager.createLoopTask("scoreboardUpdate", 5*20);
function scoreboardUpdate(){
//Loading all online players into a array that we later can loop
var players = server.getOnlinePlayers();
//Here we loop our players array where the player variable will be players[i]
for(var i in players){
//Here we make it simpler to understand with making a variable to be players[i]
var player = players[i];
//Here we set a simple variable to be the amount of players online.
var online = server.getOnlinePlayers().size();
//Here we set another simple variable to be our max players amount
var maxPlayers = server.getMaxPlayers();
//here we create our scoreboard
var sc = scoreboard.create();
//here we create an display / objective
var dp = scoreboard.newDisplay(sc, "Test Scoreboard");
//here we add some lines to our display / objective
scoreboard.setLine(dp, "Hello "+player.getName(), 2);
scoreboard.setLine(dp, "There is currently", 1);
scoreboard.setLine(dp, online + " out of " + maxPlayers, 0);
//here we set our player's scoreboard to our new one
scoreboard.set(player, sc);
}
}