Paste #12984: Edit of P#12983 - Edit of P#12982 - Edit of P#12981 - Untitled Paste

Date: 2015/01/15 17:52:09 UTC-08:00
Type: Denizen Script

View Raw Paste Download This Paste
Copy Link


# How to make smoothly updating global and player-specific scoreboards using Denizen.
# Most people seem to experience glitching and jittering in the scoreboard when attempting to make an updating scoreboard,
# so I'm going to show you my method that is mostly glitch free.

# we're going to start with creating player specific scoreboards (these will run as the player, 
# allowing you to pull specific tags that fill in differently for each player, such as p@player.location, p@player.health, and many more.)
# First we create a script that loops itself.
looping_scoreboard_script:
  type: task
  script:
  - foreach <server.list_online_players> {
    - run player_specific_scoreboard_script player:<def[value]> instantly
    }
  - run looping_scoreboard_script instantly delay:19t
# You can include an IF statement to ensure that only people who choose to, will be shown their scoreboard.
# I'm using 19 ticks as a delay, to make sure it syncs up with other looping scripts as few times as possible
# (assuming that those looping scripts are using an even, bigger number as delay, such as 20 ticks, 5 seconds, etc..) 
# whist still updating faster than seconds pass.

# Now we'll create the script that runs as each player.
player_specific_scoreboard_script:
  type: task
  script:
  - define ID <player.name><server.current_time_millis>
  - scoreboard add id:<def[ID]>
# We create the new scoreboard, with a unique player specific ID. We're using the server.current_time_millis 
# tag to ensure that each time it loops it'll have a unique ID that can't be identical to the previous one at all.
  - scoreboard add id:<def[ID]> "objective:<&6>Stats" "lines:<&c>Health<&co>" score:15
  - scoreboard add id:<def[ID]> "objective:<&6>Stats" "lines:<&e><player.health.percentage||0><&pc>" score:14
  - scoreboard add id:<def[ID]> "objective:<&6>Stats" "lines:<&c>Location<&co>" score:13
  - scoreboard add id:<def[ID]> "objective:<&6>Stats" "lines:<&e><player.location.simple||nowhere>" score:12
# Note; we are using scores to ensure the position of the line inside the scoreboard. If 2 
# lines have an equal score they will be ordered alphabetically.
  - scoreboard add id:<def[ID]> "objective:<&6>Stats" "lines:<&c>Ping<&co>" score:11
  - scoreboard add id:<def[ID]> "objective:<&6>Stats" "lines:<&e><player.ping||-1>" score:10
  - scoreboard add id:<def[ID]> viewers:<player>
# Now we add the player to the scoreboard.
  - wait 2s
  - scoreboard remove id:<def[ID]>
# Lastly, we remove the scoreboard again, after a short delay.
# This delay has to be longer than the delay on the looping script to ensure smoothness!

#You can ensure this script runs at all times by creating a world script with the 
# 'on server start' event, that runs the looping script.
scoreboard_initiator:
  type: world
  events:
    on server start:
    - run looping_scoreboard_script instantly

# Additional notes: If you're using multiple variables that could return the same result, make 
# the lines unique by using different colour code combinations.
# For example: "lines:<&a><&e><player.health>" and "lines:<&b><&e><player.saturation>"

# The maximum character length of a scoreboard line is 48. This includes colour codes!
# (not including the <>'s.) If you're unsure whether a tag will fill in with a string longer
# than 48 characters, use the substring tag.
# For example: <player.flag[flagname].substring[1,48]>

# To make a global scoreboard instead, make the script with the scoreboard commands loop on it's own,
# and add viewers:<server.list_online_players> instead.
# An example of this script in action: http://i.imgur.com/2tmQxff.png?1