1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still haven't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. Ride into the sunset with the 32nd Modeling Contest. The contest is optionally paired. Best of luck, people!
    Dismiss Notice
  4. This adventure has come to an end. Congratulate our heroes in the 16th Mini Mapping Contest Results.
    Dismiss Notice
  5. From the gates of hell, the 5th Special Effect Contest Results have emerged.
    Dismiss Notice
  6. Race against the odds and Reforge, Don't Refund. The 14th Techtree Contest has begun!
    Dismiss Notice
  7. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Leaderboards

Discussion in 'Trigger (GUI) Editor Tutorials' started by Archian, Aug 10, 2006.

Thread Status:
Not open for further replies.
  1. Archian

    Archian

    Site Director

    Joined:
    Jan 1, 2006
    Messages:
    2,902
    Resources:
    12
    Skins:
    1
    Tutorials:
    11
    Resources:
    12
    Leaderboards
    By Archian

    Description
    A leaderboard is a table displayed in the top right corner. Each row can contain a name and a value. In most maps this is used for displaying kills wins of your team. In this tutorial I will explain how to setup the leaderboard, how to update the leaderboard and how to remove a leaving player from the board.

    The image below is part of a screenshot of a leaderboard.
    leaderboards.jpg

    Sometimes you need more columns than just the two standard, but that is impossible with leaderboards so you will have to use [THREAD=6402]multiboards[/THREAD]. Multiboards are a lot tougher to work with so I will recommend leaderboards.

    Creating the Leaderboard
    The Event when creating a leaderboard in triggers is very important. Creating the leaderboard with the event below will just not work.
    • Map Initialization

    Use an event like
    • Time - Elapsed game time is 2.00 seconds

    to make it work.
    Adjusting the Elapsed game time to 0.00 seconds will work just like Map Initialization and actually work.

    • Leaderboard
      • Events
        • Time - Elapsed game time is 0.00 seconds
      • Conditions
      • Actions
        • Leaderboard - Create a leaderboard for (All players) titled Score
        • Player Group - Pick every player in (All players) and do (Actions)
          • Loop - Actions
            • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • ((Picked player) controller) Equal to User
                • ((Picked player) slot status) Equal to Is playing
              • Then - Actions
                • Leaderboard - Add (Picked player) to (Last created leaderboard) with label (Name of (Picked player)) and value 0
              • Else - Actions
        • Leaderboard - Show (Last created leaderboard)

    This trigger runs with the event we decided to use. It creats a leaderboard called "Score" and is displayed for all players. Then it loops through each player and if he is playing, he will be added to the board.

    Variable
    We need something to keep track of the kills for each player so we have to use a variable.
    Open the variable editor and create a new variable of the type Integer.
    Call it "PlayerKills" (Because I do).
    Check the Array box to keep track of more than just one value.
    leaderboard.jpg

    Updating the Leaderboard
    The leaderboard does not update by itself. Each time a value should raise, you have to make it raise. That's why we need a trigger that updates the board.
    • Trigger Update
      • Events
        • Unit - A unit Dies
      • Conditions
        • ((Dying unit) belongs to an enemy of (Owner of (Killing unit))) Equal to True
      • Actions
        • Set PlayerKills[(Player number of (Owner of (Killing unit)))] = (PlayerKills[(Player number of (Owner of (Killing unit)))] + 1)
        • Leaderboard - Change the value for (Owner of (Killing unit)) in (Last created leaderboard) to PlayerKills[(Player number of (Owner of (Killing unit)))]
        • Leaderboard - Sort (Last created leaderboard) by Value in Descending order

    This trigger runs every time a unit dies, if the dying unit is an enemy of the killing unit, the PlayerKills variable will raise with one. I put in the condition because I do not want people to make commit teamkills and score by that.

    The Leaving Player
    Having a leaderboard only display the players who are actually still playing is very important. Or at least make it so people easily can keep track of who are playing and who are not. I decided to make a trigger to remove the leavers from the board. The trigger will look like this:
    • Leavers
      • Events
        • Player - Player 1 (Red) leaves the game
        • Player - Player 2 (Blue) leaves the game
        • Player - Player 3 (Teal) leaves the game
      • Conditions
      • Actions
        • Leaderboard - Remove (Triggering player) from (Last created leaderboard)

    This trigger does only act when player 1, 2 or 3 leavers so add one for each available slot.

    The Trigger Functions of Leaderboards
    Here's a overview of the functions which are available for leaderboard triggers.

    Leaderboard - Create
    Creates the leaderboard. Make a main title for the leaderboard.

    Leaderboard - Destroy
    Destroys a leaderboard. Once destroyed, players can no longer see it.

    Leaderboard - Show/Hide
    Shows and hides the leaderboard.

    Leaderboard - Change Title
    Changes the main title of the leaderboard.

    Leaderboard - Change Label Colors
    Changes the color of a players label.

    Leaderboard - Change Value Colors
    Changes the color of a players score.

    Leaderboard - Change Style
    Changes the leaderboard style. You can hide the title, labels, or player values, for all players.

    Leaderboard - Add Player
    Adds a player to the leaderboard.

    Leaderboard - Remove Player
    Removes a player from the leaderboard.

    Leaderboard - Change Player Label
    Changes the label for a player.

    Leaderboard - Change Player Label Color
    Changes the color of a players label.

    Leaderboard - Change Player Value
    Updates the value, or score, for a player.

    Leaderboard - Change Player Value Color
    Changes the color of a players score.

    Leaderboard - Change Player Style
    Changes the leaderboard style. You can hide the labels or player values, for a specific player.
     
    Last edited by a moderator: Oct 26, 2006
Thread Status:
Not open for further replies.