Allow for custom TTT Scoreboard ScoreGroups #905

Merged
merged 2 commits into from Apr 18, 2015

Projects

None yet

3 participants

@bmwalters
Contributor

The purpose of this commit is to allow developers to create new player groups on the TTT Scoreboard. Previously, people had to implement hacky overrides. (Two links)
If anyone has a better method of implementing this, please comment. Specifically, I'm not sure about that Initialize hook just to modify the GROUP_COUNT variable/grab ourselves an index.
Details:
Adds two hooks:

  • TTTScoreGroup(ply)
  • TTTScoreGroups(pnl, groupstbl)
    And one function:
  • AddScoreGroup(name)

Returning a number in TTTScoreGroup will set the given player's scoregroup to that number (index in the groupstbl)

The TTTScoreGroups hook is where all of the setup happens:

  1. You must first register a ScoreGroup with AddScoreGroup(name). A global variable of GROUP_..name is set and GROUP_COUNT is incremented automatically.
  2. Then, you create a new "TTTScoreGroup" panel and parent it to the panel passed as the first argument of the hook.
  3. Next you must call SetGroupInfo(name, color, index) on your TTTScoreGroup panel.
  4. Lastly, add an entry to the second argument (table of groups) with the key of your GROUP_ with the value of your panel.

This example is working and explains all of the features.
Example usage:

if not CLIENT then return end

-- fluff
local META_PLAYER = FindMetaTable("Player")
function META_PLAYER:IsInDeathmatch()
    return (self.Deathmatch)
end
hook.Add("OnPlayerChat", "TTTDeathmatch_PlayerChat", function(ply, text, isTeam, isDead)
    if text == "!deathmatch" then
        ply.Deathmatch = not ply.Deathmatch
        chat.AddText("You "..(ply.Deathmatch and "entered" or "left").." TTTDeathmatch!")
        return true
    end
end)
-- end fluff

hook.Add("TTTScoreGroups", "TTTDeathmatch_AddScoreGroup", function(pnl, groupstbl)
    AddScoreGroup("TTTDM")
    local group = vgui.Create("TTTScoreGroup", pnl)
    group:SetGroupInfo("Deathmatch", Color(100, 200, 200), GROUP_TTTDM)
    groupstbl[GROUP_TTTDM] = group
end)

hook.Add("TTTScoreGroup", "TTTDeathmatch_SetScoreGroup", function(ply)
    return (ply:IsInDeathmatch() and GROUP_TTTDM) or nil
end)
@bmwalters bmwalters changed the title from Allow for custom TTT ScoreGroups to Allow for custom TTT Scoreboard ScoreGroups Mar 25, 2015
@robotboy655 robotboy655 added the TTT label Mar 25, 2015
@bmwalters
Contributor

I added a function to improve the addition of groups. The description and example have been updated accordingly. The description is also better in general.

@svdm svdm merged commit 72a7452 into garrynewman:master Apr 18, 2015
@bmwalters bmwalters deleted the unknown repository branch Apr 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment