Simple Kill Tracking Leaderboard

From HIVE
Jump to: navigation, search

Introduction

If you are coming from Starcraft 1, you are probably used to a very simple, easy way to set up leaderboard system, one which required one trigger to set up and never needed a second thought. While simple, this was also very limited in functionality, only allowing certain statistics to be tracked, many of which were never used. If you've taken a look at any of the leaderboard triggers in the Starcraft 2 Editor, you'll find that it is quite a bit more complicated. There are very advanced functions, some of which we don't even know what they do. But don't worry, this tutorial will show you how to set up a very simple, easy to use, and flexible leaderboard system for tracking several statistics.

This leaderboard will track the kills for every player that is currently playing, and will show them as defeated if they leave the game. The system only consists of three, stand-alone triggers (meaning they are very easy to implement into any map), and can be easily modified to track just about any numerical statistic.

1: Global Variables

A few global variables are needed, the names and types of which are indicated below (Name - Type - Value - (Description)):

  • MainLeaderBoard - Leaderboard - <No Leaderboard> - (The actual Leader board variable. We will use this whenever we need to update the leaderboard.)
  • Kills[8] - Integer - 0 - (Stores the amount of kills the players have. The size of the array needs to be equal to the amount of players in the map. In this case, we have 8 players.)

2: Starting the Leaderboard

The first thing that is needed is to start the leaderboard, and display it for every player. It is a relatively simple trigger, but is decently long:

http://omegacode.0sites.org/BBCode/BBCode3.php?ID=98

Start Leader Board
   Events
       Game - Map initialization
   Local Variables
       ForPlayer = 0 <Integer>
   Conditions
   Actions
       Leaderboard - Create a leaderboard with 2 columns and (8 + 1) rows, with the name "Kills", and using (100%, 100%, 100%) color.
       Variable - Set MainLeaderboard = (Last created leaderboard)
       Leaderboard - Set MainLeaderboard item text at column 1 and row 1 to "Player"
       Leaderboard - Set MainLeaderboard item text at column 2 and row 1 to "Kills"
       General - For each integer ForPlayer from 1 to 8 with increment 1, do (Actions)
           Actions
               General - If (Conditions) then do (Actions) else do (Actions)
                   If
                       (Status of player ForPlayer) == Playing
                   Then
                       Leaderboard - Set MainLeaderboard item text at column 1 and row (ForPlayer + 1) to (Text (Name of player ForPlayer) with color (Color((Current player ForPlayer color))))
                       Leaderboard - Set MainLeaderboard item text at column 2 and row (ForPlayer + 1) to "0"
                   Else
                       Leaderboard - Set MainLeaderboard item text at column 1 and row (ForPlayer + 1) to (Text (Name of player ForPlayer) with color (75%, 75%, 75%))
                       Leaderboard - Set MainLeaderboard item text at column 2 and row (ForPlayer + 1) to (Text "Defeated..." with color (75%, 75%, 75%))
       Leaderboard - Turn MainLeaderboard minimize button On for (All players)
       Leaderboard - Show MainLeaderboard minimize button for (All players)

So first things first, we assume that the actual player numbers are from 1-8 (meaning 8 players total). We first create a leaderboard with 9 columns (I left it as 8 + 1, it will always need one extra row, so the formula is the amount of players it will track + 1), and set the global variable MainLeaderboard to the leaderboard we just created, so that we can access it later.

Next, we must state what exactly each variable means be affixing a label to the top of each column, with the first column being the player, and the second column being the amount of kills acquired by the respective player. We will set the item at column 1 and row 1 to "Player", and the item at column 2 and row 1 to "Kills", which will serve as our labels.

Now we must loop through each player (1 - 8) and add in each player to the leaderboard. The basic formula is (Player Number + 1), which compensates for the column labels we created before. The first row will display the players name in the players color and 0 kills if they are in game, and if not, will grey out their name and display that they have been defeat.

Lastly, we turn on the minimize button for the leaderboard, so anyone who is not interested in it can hide it away, and then show it to the players. We now have a static leaderboard, but it doesn't do anything yet besides look pretty. But we'll change that.

3: Setting up the kill tracker

Now we need to set up a trigger that tracks kills. In this example, we will only count kills against Player 15, the enemy unit. If a player kills his own units, or the other players' units, it will not increase his or her kill count.

http://omegacode.0sites.org/BBCode/BBCode3.php?ID=99

UpdateKills
   Events
       Unit - Any Unit dies
   Local Variables
   Conditions
       (Owner of (Triggering unit)) == 15
   Actions
       Variable - Set Kills[(Killing Player)] = (Kills[(Killing Player)] + 1)

This is a very very simple trigger, it fires any time a unit is killed. The first thing it does is check to make sure that the unit that was killed belonged to Player 15, and if it did, it will update the kill count array variable at the killing player's index by 1. Again, very simple.

4: Updating the Leaderboard

The last step needed is to take this value that we have stored and render it to the leaderboard.

http://omegacode.0sites.org/BBCode/BBCode3.php?ID=100

UpdateLeaderBoard
   Events
       Timer - Every 1.0 seconds of Game Time
   Local Variables
       ForPlayer = 0 <Integer>
   Conditions
   Actions
       General - For each integer ForPlayer from 1 to 8 with increment 1, do (Actions)
           Actions
               General - If (Conditions) then do (Actions) else do (Actions)
                   If
                       (Status of player ForPlayer) == Playing
                       (Controller of player ForPlayer) == User
                   Then
                       Leaderboard - Set MainLeaderboard item text at column 1 and row (ForPlayer + 1) to (Name of player ForPlayer)
                       Leaderboard - Set MainLeaderboard item text at column 2 and row (ForPlayer + 1) to (Text(Kills[ForPlayer]))
                   Else
                       Leaderboard - Set MainLeaderboard item text at column 1 and row (ForPlayer + 1) to (Text (Name of player ForPlayer) with color (75%, 75%, 75%))
                       Leaderboard - Set MainLeaderboard item text at column 2 and row (ForPlayer + 1) to (Text "Defeated..." with color (75%, 75%, 75%))

Now, Here's where you'll get to make a bit of a choice. I'm all about efficiency and run-time performance in maps, so this trigger will be updated only once a second. You can implement this so that it is run with the kill counter (so that it is updated on every kill), but I haven't tested if the map will take a performance hit on it. (Mind you, the map that I first implemented this in is basically a Starcraft 2 Stress-Test, where hundreds of units are on screen at a time, so performance is a must.) However, in a standard map, you probably wont notice much, and can update the leaderboard on every kill. It will look a bit nicer this way, as the board will instantly update, instead of seeming to lag for a second and then get a huge update of data.

The rest is almost exactly the same as the set-up trigger, just update each item for it's respective player, and post in his or her number of kills instead of just a plain 0. It's as simple as that.

5: Test

Test your map, and see if it works.

6: Afterword

That should be just about it to this tutorial. You should have a working leaderboard that tracks kills for all of the active players (between 1 and 8), and displays defeat messages for those that are in-active. This is also easily modifiable to work with other values, such as unit counts, resource counts, or pretty much whatever else you can think of.

If there are any questions/errors, please let me know via PM on SEN. I'll update this with images and a demonstration map when I have the chance (and figure out how >.<)

-Shmeeps (With a shout out to Artanis186, who gave me the idea to implement the board in this particular way.)


See Also