TTT - Easy Scoreboard Ranks

I’ve been meaning to make a thread for a while, essentially this is just a script I wrote to make adding ranks/colors to the scoreboard easy.
The hope was that people would stop making threads about “Help me with scoreboard pls”.

Download
GitHub

The config options are self explanatory, but if you’re confused read the github readme and make a post here.

Testing when I get Home!

Any reason you don’t do it like



EZS.Ranks = {
    superadmin = {
        name = "S. Admin",
        color = Color(255, 0, 0)
    },
    moderator = {
        name = "Moderator",
        color = Color(0, 0, 255)
    }
}


Just seems like a better table layout.

I was trying to make it as straightforward as possible to someone with no lua knowledge.
Just figured it would be easier to understand

Hi I was wondering if I could set it so that it doesn’t goes so wide apart? The difference in width is too big between 5 and 6. It would be great if I could get it as soon as possible :smiley:

Going to test this out soon.

Do stop by my server relax! I am adding you to the Donator (for helping me) rank!

IP: nightflaregaming.no-ip.org

show me a picture with what you have and what you want

It would be much easier if you just came to my server instead and see for yourself :D. However it is not up today :(. I already sent you a friend request to tell ya more details.

It would also be great if you came so that I can add you to the “Donator” rank! :DDDDDDD

WHy not post here, that way anyone who wants the same can easily see and do the same.

Please, stop advertising your server, if you want the author to join your server for a rank, PM him, instead of including the ip to your served in each reply. I know you’re trying to be nice, but advertising your server on someone else’s thread, just to gain one more user to the two user server is quite disrespectful.

Okay then understood. I wasn’t really advertising however, I really wanted to add in him to the server as a donor that’s all. No harm intended. Simply giving him the ip to the server so that he could join for more info about my problem. (PS: I tried adding him as friend to discuss with him but he wouldn’t accept :c)

Didn’t notice I added my ip twice :stuck_out_tongue: Imma remove one of it.

[editline]19th February 2014[/editline]

So I went to dig up for the initial “method” as to how I thought it was done and I changed the format a little and there :D. (Managed to do it after about an hour)

Here is how I wanted it be (focus on the coordinates of the “Owner” Tag)

Here is how it is currently (Notice how the “Rank” and “Owner” tag are so far apart)

Here is the code I used for “sb_row.lua”.


 ---- Scoreboard player score row, based on sandbox version

include("sb_info.lua")


local GetTranslation = LANG.GetTranslation
local GetPTranslation = LANG.GetParamTranslation


SB_ROW_HEIGHT = 24 --16

local PANEL = {}

function PANEL:Init()
   -- cannot create info card until player state is known
   self.info = nil

   self.open = false

   self.cols = {}
   self.cols[1] = vgui.Create("DLabel", self)
   self.cols[1]:SetText(GetTranslation("sb_ping"))
   
   self.cols[5] = vgui.Create("DLabel", self)
   self.cols[5]:SetText("")

   self.cols[2] = vgui.Create("DLabel", self)
   self.cols[2]:SetText(GetTranslation("sb_deaths"))

   self.cols[3] = vgui.Create("DLabel", self)
   self.cols[3]:SetText(GetTranslation("sb_score"))

   if KARMA.IsEnabled() then
      self.cols[4] = vgui.Create("DLabel", self)
      self.cols[4]:SetText(GetTranslation("sb_karma"))
   end

   for _, c in ipairs(self.cols) do
      c:SetMouseInputEnabled(false)
   end

   self.tag = vgui.Create("DLabel", self)
   self.tag:SetText("")
   self.tag:SetMouseInputEnabled(false)

   self.sresult = vgui.Create("DImage", self)
   self.sresult:SetSize(16,16)
   self.sresult:SetMouseInputEnabled(false)

   self.avatar = vgui.Create( "AvatarImage", self )
   self.avatar:SetSize(SB_ROW_HEIGHT, SB_ROW_HEIGHT)
   self.avatar:SetMouseInputEnabled(false)

   self.nick = vgui.Create("DLabel", self)
   self.nick:SetMouseInputEnabled(false)

   self.voice = vgui.Create("DImageButton", self)
   self.voice:SetSize(16,16)

   self:SetCursor( "hand" )
end


local namecolor = {
   default = COLOR_WHITE,
   admin = Color(220, 180, 0, 255),
   dev = Color(100, 240, 105, 255)
};

function GM:TTTScoreboardColorForPlayer(ply)
   if not IsValid(ply) then return namecolor.default end

   if ply:SteamID() == "STEAM_0:0:1963640" then
      return namecolor.dev
   elseif ply:IsAdmin() and GetGlobalBool("ttt_highlight_admins", true) then
      return namecolor.admin
   end
   return namecolor.default
end

local function ColorForPlayer(ply)
   if IsValid(ply) then
      local c = hook.Call("TTTScoreboardColorForPlayer", GAMEMODE, ply)

      -- verify that we got a proper color
      if c and type(c) == "table" and c.r and c.b and c.g and c.a then
         return c
      else
         ErrorNoHalt("TTTScoreboardColorForPlayer hook returned something that isn't a color!
")
      end
   end
   return namecolor.default
end

function PANEL:Paint()
   if not IsValid(self.Player) then return end

--   if ( self.Player:GetFriendStatus() == "friend" ) then
--      color = Color( 236, 181, 113, 255 )
--   end

   local ply = self.Player

   if ply:IsTraitor() then
      surface.SetDrawColor(255, 0, 0, 30)
      surface.DrawRect(0, 0, self:GetWide(), SB_ROW_HEIGHT)
   elseif ply:IsDetective() then
      surface.SetDrawColor(0, 0, 255, 30)
      surface.DrawRect(0, 0, self:GetWide(), SB_ROW_HEIGHT)
   end


   if ply == LocalPlayer() then
      surface.SetDrawColor( 200, 200, 200, math.Clamp(math.sin(RealTime() * 2) * 50, 0, 100))
      surface.DrawRect(0, 0, self:GetWide(), SB_ROW_HEIGHT )
   end

   return true
end

function PANEL:SetPlayer(ply)
   self.Player = ply
   self.avatar:SetPlayer(ply)

   if not self.info then
      local g = ScoreGroup(ply)
      if g == GROUP_TERROR and ply != LocalPlayer() then
         self.info = vgui.Create("TTTScorePlayerInfoTags", self)
         self.info:SetPlayer(ply)

         self:InvalidateLayout()
      elseif g == GROUP_FOUND or g == GROUP_NOTFOUND then
         self.info = vgui.Create("TTTScorePlayerInfoSearch", self)
         self.info:SetPlayer(ply)
         self:InvalidateLayout()
      end
   else
      self.info:SetPlayer(ply)

      self:InvalidateLayout()
   end

   self.voice.DoClick = function()
                           if IsValid(ply) and ply != LocalPlayer() then
                              ply:SetMuted(not ply:IsMuted())
                           end
                        end

   self:UpdatePlayerData()
end

function PANEL:GetPlayer() return self.Player end

function PANEL:UpdatePlayerData()
   if not IsValid(self.Player) then return end

   local ply = self.Player
   self.cols[1]:SetText(ply:Ping())
   self.cols[2]:SetText(ply:Deaths())
   self.cols[3]:SetText(ply:Frags())

   if ply:IsUserGroup("Owner") then
self.cols[5]:SetText("Owner")
self.cols[5]:SetTextColor(Color(252,192,13,252))
end

   if ply:IsUserGroup("admin") then
self.cols[5]:SetText("Admin")
self.cols[5]:SetTextColor(Color(0,239,255,255))
end

   if ply:IsUserGroup("headadmin") then
self.cols[5]:SetText("H.Admin")
self.cols[5]:SetTextColor(Color(0,239,255,255))
end

   if ply:IsUserGroup("superadmin") then
self.cols[5]:SetText("S.Admin")
self.cols[5]:SetTextColor(Color(0,239,255,255))
end

   if ply:IsUserGroup("superadmind") then
self.cols[5]:SetText("S.Admin")
self.cols[5]:SetTextColor(Color(0,239,255,255))
end

   if ply:IsUserGroup("trialadmin") then
self.cols[5]:SetText("T.Admin")
self.cols[5]:SetTextColor(Color(0,239,255,255))
end

   if ply:IsUserGroup("trusted") then
self.cols[5]:SetText("Trusted")
self.cols[5]:SetTextColor(Color(0,255,0,255))
end

   if ply:IsUserGroup("donator") then
self.cols[5]:SetText("Donator")
self.cols[5]:SetTextColor(Color(172,41,229,172))
end


   if self.cols[4] then
      self.cols[4]:SetText(math.Round(ply:GetBaseKarma()))
   end

   self.nick:SetText(ply:Nick())
   self.nick:SizeToContents()
   self.nick:SetTextColor(ColorForPlayer(ply))

   local ptag = ply.sb_tag
   if ScoreGroup(ply) != GROUP_TERROR then
      ptag = nil
   end

   self.tag:SetText(ptag and GetTranslation(ptag.txt) or "")
   self.tag:SetTextColor(ptag and ptag.color or COLOR_WHITE)

   self.sresult:SetVisible(ply.search_result != nil)

   -- more blue if a detective searched them
   if ply.search_result and (LocalPlayer():IsDetective() or (not ply.search_result.show)) then
      self.sresult:SetImageColor(Color(200, 200, 255))
   end

   -- cols are likely to need re-centering
   self:LayoutColumns()

   if self.info then
      self.info:UpdatePlayerData()
   end

   if self.Player != LocalPlayer() then
      local muted = self.Player:IsMuted()
      self.voice:SetImage(muted and "icon16/sound_mute.png" or "icon16/sound.png")
   else
      self.voice:Hide()
   end
end

function PANEL:ApplySchemeSettings()
   for k,v in pairs(self.cols) do
      v:SetFont("treb_small")
      v:SetTextColor(COLOR_WHITE)
   end

   self.nick:SetFont("treb_small")
   self.nick:SetTextColor(ColorForPlayer(self.Player))

   local ptag = self.Player and self.Player.sb_tag
   self.tag:SetTextColor(ptag and ptag.color or COLOR_WHITE)
   self.tag:SetFont("treb_small")

   self.sresult:SetImage("icon16/magnifier.png")
   self.sresult:SetImageColor(Color(170, 170, 170, 150))
end

function PANEL:LayoutColumns()
   for k,v in ipairs(self.cols) do
if k == 5 then
			v:SizeToContents()
			v:SetPos(self:GetWide() - (55*k) - v:GetWide()/2, (SB_ROW_HEIGHT - v:GetTall()) / 2)
		else
			v:SizeToContents()
			v:SetPos(self:GetWide() - (50*k) - v:GetWide()/2, (SB_ROW_HEIGHT - v:GetTall()) / 2)
		end
   end

   self.tag:SizeToContents()
   self.tag:SetPos(self:GetWide() - (50 * 6) - self.tag:GetWide()/2, (SB_ROW_HEIGHT - self.tag:GetTall()) / 2)

   self.sresult:SetPos(self:GetWide() - (50*6) - 8, (SB_ROW_HEIGHT - 16) / 2)
end

function PANEL:PerformLayout()
   self.avatar:SetPos(0,0)
   self.avatar:SetSize(SB_ROW_HEIGHT,SB_ROW_HEIGHT)

   if not self.open then
      self:SetSize(self:GetWide(), SB_ROW_HEIGHT)

      if self.info then self.info:SetVisible(false) end
   elseif self.info then
      self:SetSize(self:GetWide(), 100 + SB_ROW_HEIGHT)

      self.info:SetVisible(true)
      self.info:SetPos(5, SB_ROW_HEIGHT + 5)
      self.info:SetSize(self:GetWide(), 100)
      self.info:PerformLayout()

      self:SetSize(self:GetWide(), SB_ROW_HEIGHT + self.info:GetTall())
   end

   self.nick:SizeToContents()

   self.nick:SetPos(SB_ROW_HEIGHT + 10, (SB_ROW_HEIGHT - self.nick:GetTall()) / 2)

   self:LayoutColumns()

   self.voice:SetVisible(not self.open)
   self.voice:SetSize(16, 16)
   self.voice:DockMargin(4, 4, 4, 4)
   self.voice:Dock(RIGHT)
end

function PANEL:DoClick(x, y)
   self:SetOpen(not self.open)
end

function PANEL:SetOpen(o)
   if self.open then
      surface.PlaySound("ui/buttonclickrelease.wav")
   else
      surface.PlaySound("ui/buttonclick.wav")
   end

   self.open = o

   self:PerformLayout()
   self:GetParent():PerformLayout()
   sboard_panel:PerformLayout()
end

function PANEL:DoRightClick()
end

vgui.Register( "TTTScorePlayerRow", PANEL, "Button" ) 

If you look carefully, to change the coordinates of the image you change the "k" at line 260-265. The default value is 50k but I set it to 55*k because “Head Admin” rank (I wanted to add a screenshot for it but it would take too long :c) was overlapping the “Karma” tab. However, it only moved the “Ranks” tab and not the rank itself.

I was hoping if the author could set it that way which is more specific as the value the author gave was “big” numbers in a sense it moved the rank and the rank itself a lot.

If anyone knows how to code this differently it would be great :D.

Thanks in advance~

You shouldn’t include the ip anyway… Just PM him it. I doubt the author would even play tbh.

did you even download the addon?
you don’t need to edit sb_row at all
you just change EZS.RankPos to 5 to align it

also - updated to add support for evolve

I am one my phone at the moment so I cant access the files but anyways. Does this support ScrW and ScrH ? Because a lot of my clients are reporting the text of the ranks in people’s names and I had to remove it.

Send me the file when you can and I’ll take a look

Just out of curiosity, do you have any affiliation with efhunterzone, rejax?

Nope?

I don’t see why u have to be so rude about it. And besides, I can’t be grateful that he helped me and I want to properly thank him? Are you saying that because you weren’t taught proper manners?

And didn’t I tell you that I tried PMing him but he didn’t accept my friend request? Did you even fucking read?

If you not going to be helping me then please shut the fuck up and read only.

[editline]20th February 2014[/editline]

Yes of course! I putted in in the lua/autorun/client/

I was just telling you that the past method I tried which was editing sv_row.lua allowed one to be able to adjust the coordinates of the “Rank” tab and the rank itself more accurately while however yours is not as accurate (no insulting your addon or what not). I was wondering if you could improve it.

Where have I been rude? Have I swarm to get the point out? No. Have I insulted you? No.
Have you swarm to get the point out? Yes. Have you been insulting? Yes.
It appears if anyone doesn’t have manners or anyone who wasn’t taught proper manners, it’s you.
You don’t need to add someone as a friend to PM someone on Facepunch, so I don’t even know what you’ve been trying to do, clearly something that has put you in a bad mood.

The reply you have given indicates clearly that your temper is very short and bad, and has instantly given me the impression your server isn’t good in any form, due to a bad tempered owner.

If you’re that “grateful” for this Addon release, you wouldn’t ask for it to be improved.