TTT - Scoreboard ranks column/row

Hi everyone!
I’ve searched all over, and i cant find any way to add a new row in the scoreboard that reveals your Evolved Mod/ULX ranks.
Im hosting a dedicated server, and installed/tried different admin mods.
I know you dont like LUA noobs very much around here, but at least I’ve made som costum TTT weapons :smile:

What I’m trying to acomplish is something like this:

Im willing to install any admin mod if it allows me to do this.
I know that the F2B server got this working. They Run ULX admin mod, and i also noticed that the server runs a “uteam.lua” (module?) even though this is already integrated in ULX.
So they have probably made the UTeam add a column or something. (but I thought UTeam only worked with sandbox?) Hope that that helps a bit :smile:

Any help will be very welcome!
-Zaph

I wanted this a few days ago and after a quick google found this:
http://forum.facepunch.com/showthread.php?t=1101202

It’s a bit messy to get working and requires a little work from yourself but I’m sure you can get it to work. :slight_smile:
Result: http://puu.sh/1vjri (I chose not to have the ‘rank’ text, I think it’s included in the thread I posted though)

You mean this?



---- 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("Label", self)
   self.cols[1]:SetText(GetTranslation("sb_ping"))
     
   self.cols[2] = vgui.Create("Label", self)
   self.cols[2]:SetText(GetTranslation("sb_deaths"))
     
   self.cols[3] = vgui.Create("Label", self)
   self.cols[3]:SetText(GetTranslation("sb_score"))
     
   self.cols[5] = vgui.Create("Label", self) 
   self.cols[5]:SetText("")  
  
   if KARMA.IsEnabled() then
      self.cols[4] = vgui.Create("Label", self)
      self.cols[4]:SetText(GetTranslation("sb_karma"))
   end
  
   for _, c in ipairs(self.cols) do
      c:SetMouseInputEnabled(false)
   end
  
   self.tag = vgui.Create("Label", 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("Label", self)
   self.nick:SetMouseInputEnabled(false)
  
   self:SetCursor( "hand" )
end
  
  
local namecolor = {
   default = COLOR_WHITE,
   superadmin = Color(255,0,0,255),
   admin = Color(220, 180, 0, 255),
   dev = Color(100, 240, 105, 255),
   respected = Color(255,255,145),
   asshole = Color(145,75,123)
};
  
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 ValidEntity(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: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 self.cols[4] then
      self.cols[4]:SetText(math.Round(ply:GetBaseKarma()))
   end
  
   self.nick:SetText(ply:Nick())
   self.nick:SizeToContents()
   self.nick:SetFGColor(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:SetFGColor(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 ply:IsUserGroup( "superadmin" ) then
        self.cols[5]:SetText( "Super Admin" )
        self.cols[5]:SetFGColor(namecolor.superadmin)
    elseif ply:IsUserGroup( "admin" ) then
        self.cols[5]:SetText( "Admin" )   
        self.cols[5]:SetFGColor(namecolor.admin)
    elseif ply:IsUserGroup( "guest" ) then
        self.cols[5]:SetText( "" )
    elseif ply:IsUserGroup( "Asshole" ) then
        self.cols[5]:SetText( "Asshole" )
        self.cols[5]:SetFGColor(namecolor.asshole)
    elseif ply:IsUserGroup( "guest2" ) then
        self.cols[5]:SetText( "Respected" )
        self.cols[5]:SetFGColor(namecolor.respected)
    end
end
  
  
function PANEL:ApplySchemeSettings()
   for k,v in pairs(self.cols) do
      v:SetFont("treb_small")
      v:SetFGColor(COLOR_WHITE)
   end
  
   self.nick:SetFont("treb_small")
   self.nick:SetFGColor(ColorForPlayer(self.Player))
  
   local ptag = self.Player and self.Player.sb_tag
   self.tag:SetFGColor(ptag and ptag.color or COLOR_WHITE)
   self.tag:SetFont("treb_small")
  
   self.sresult:SetImage("gui/silkicons/magnifier")
   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() - (80*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()
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()
   -- sboard_panel:PerformLayout()
end
  
  
function PANEL:DoRightClick()
end
  
  
vgui.Register( "TTTScorePlayerRow", PANEL, "Button" )


I must tell you. I have 0 experience with lua, except copy/paste and editing values that are already there :confused: Dont think i can get that monster working all by my self.

And is this for Evolve only? Or will this work with ULX as well, when fixed? And IF i get it working, do i save this as sb_row.lua in the /lua/autorun directory?

[editline]28th November 2012[/editline]

I replaced the original sb_row.lua (serverside) in the gamemodes errortown\gamemode\vgui folder, and I got 2 errors.


[ERROR] gamemodes/terrortown/gamemode/vgui/sb_row.lua:96: attempt to call global 'ValidEntity' (a nil value)
  1. unknown - gamemodes/terrortown/gamemode/vgui/sb_row.lua:96

This is line 96:

   if not ValidEntity(self.Player) then return end

and


[ERROR] gamemodes/terrortown/gamemode/vgui/sb_row.lua:206: attempt to call method 'SetFont' (a nil value)
  1. unknown - gamemodes/terrortown/gamemode/vgui/sb_row.lua:206

This is line 206:

      v:SetFont("treb_small")

There were no Errors when launching the server. The error occured when i joined my server and hit TAB. I could see the SB for half a second, and the i got lua kicked.

Any ideas?

for ValidEntity change it to IsValid.

I believe this one is outdated. You have to make it so it works with the latest SVN for TTT since BadKing added a icon for muting players in the scoreboard. Just look at what’s changed and fix them accordingly. And I believe SetFGColor has changed to SetTextColor

Thank you for guiding me in the right direction!
I will begin this task tomorrow, got to sleep (have a math final in the morning)

Will report back tomorrow!

Ok so i tried to redo this to work with Gmod13.

This is the original file from BadKing



---- 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[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 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
      v:SizeToContents()
      v:SetPos(self:GetWide() - (50*k) - v:GetWide()/2, (SB_ROW_HEIGHT - v:GetTall()) / 2)
   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" )



And this is what mine looks like ATM:



---- 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[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"))
   

[QUOTE]

   self.cols[5] = vgui.Create("Label", self) 
   self.cols[5]:SetText("")

[/QUOTE]

   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



[QUOTE]
local namecolor = {
   default = COLOR_WHITE,
   superadmin = Color(255,0,0,255),
   admin = Color(220, 180, 0, 255),
   moderator = Color(100, 240, 105, 255),
   respected = Color(255,255,145),
   regular = Color(145,75,123)
};

[/QUOTE]

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 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


[QUOTE]
   if ply:IsUserGroup( "superadmin" ) then
        self.cols[5]:SetText( "Head Admin" )
        self.cols[5]:SetTextColor(namecolor.superadmin)
    elseif ply:IsUserGroup( "admin" ) then
        self.cols[5]:SetText( "Admin" )   
        self.cols[5]:SetTextColor(namecolor.admin)
    elseif ply:IsUserGroup( "guest" ) then
        self.cols[5]:SetText( "" )
    elseif ply:IsUserGroup( "moderator" ) then
        self.cols[5]:SetText( "Moderator" )
        self.cols[5]:SetTextColor(namecolor.asshole)
    elseif ply:IsUserGroup( "guest2" ) then
        self.cols[5]:SetText( "Regular" )
        self.cols[5]:SetTextColor(namecolor.respected)
    end   
end

[/QUOTE]


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()

[QUOTE]
   for k,v in ipairs(self.cols) do
        if k == 5 then
            v:SizeToContents()
            v:SetPos(self:GetWide() - (80*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
[/QUOTE]


   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" )



And these are the errors i get when trying to join my server:




[ERROR] gamemodes/terrortown/gamemode/vgui/sb_row.lua:204: attempt to call method 'SetTextColor' (a nil value)
  1. UpdatePlayerData - gamemodes/terrortown/gamemode/vgui/sb_row.lua:204
   2. SetPlayer - gamemodes/terrortown/gamemode/vgui/sb_row.lua:152
    3. AddPlayerRow - gamemodes/terrortown/gamemode/vgui/sb_team.lua:85
     4. UpdateScoreboard - gamemodes/terrortown/gamemode/vgui/sb_main.lua:268
      5. Init - gamemodes/terrortown/gamemode/vgui/sb_main.lua:138
       6. Create - lua/includes/extensions/client/panel/scriptedpanels.lua:153
        7. ScoreboardCreate - gamemodes/terrortown/gamemode/cl_scoreboard.lua:27
         8. unknown - gamemodes/terrortown/gamemode/cl_scoreboard.lua:34



[ERROR] gamemodes/terrortown/gamemode/vgui/sb_row.lua:221: attempt to call method 'SetFont' (a nil value)
  1. unknown - gamemodes/terrortown/gamemode/vgui/sb_row.lua:221



[ERROR] gamemodes/terrortown/gamemode/vgui/sb_row.lua:221: attempt to call method 'SetFont' (a nil value)
  1. unknown - gamemodes/terrortown/gamemode/vgui/sb_row.lua:221


After “fixing” it i got even more errors :stuck_out_tongue: Need some pro-tips here!
And why do i suddenly get lots of errors from other files like sb_main and sb_team ? :S

Just do this
Go to your terrortown/gamemode/vgui/sb_row.lua

Add this below function PANEL:Init()
[lua] self.cols[5] = vgui.Create(“DLabel”, self)
self.cols[5]:SetText(“Rank”)[/lua]

Add this below function PANEL:UpdatePlayerData()
[lua]
if ply:IsUserGroup(“superadmin”) then
self.cols[5]:SetText(“SUPERADMIN”)
self.cols[5]:SetTextColor(Color(255,0,0,255))
end
[/lua]

Go to your terrortown/gamemode/vgui/sb_main.lua

Find under function PANEL:Init()
[lua] self.cols[3] = vgui.Create( “DLabel”, self )
self.cols[3]:SetText( GetTranslation(“sb_score”) )[/lua]

Add this under that
[lua] self.cols[5] = vgui.Create( “DLabel”, self )
self.cols[5]:SetText(“Rank”)[/lua]

All you really had to do is look at how the other ones were set and just follow how it’s being created. :/.
Be sure to do this on the latest svn for terrortown that hasn’t been edited.

Thank you for a most helpfull awnser! :slight_smile:

This is what i tried to do. I used the lates sb_row fro badking, but still got all the errors :confused:

I will try this as soon as i get home :smiley:

I love you!
Works perfectly. Thank you!

[ERROR] gamemodes/terrortown/gamemode/vgui/sb_main.lua:78: attempt to index field ‘cols’ (a nil value)

  1. Init - gamemodes/terrortown/gamemode/vgui/sb_main.lua:78
  2. Create - lua/includes/extensions/client/panel/scriptedpanels.lua:153
    3. ScoreboardCreate - gamemodes/terrortown/gamemode/cl_scoreboard.lua:27
    4. unknown - gamemodes/terrortown/gamemode/cl_scoreboard.lua:34

[ERROR] gamemodes/terrortown/gamemode/vgui/sb_main.lua:247: attempt to index field ‘hostdesc’ (a nil value)

  1. unknown - gamemodes/terrortown/gamemode/vgui/sb_main.lua:247

[ERROR] gamemodes/terrortown/gamemode/vgui/sb_main.lua:184: attempt to index field ‘ply_groups’ (a nil value)

  1. unknown - gamemodes/terrortown/gamemode/vgui/sb_main.lua:184

[ERROR] gamemodes/terrortown/gamemode/vgui/sb_main.lua:184: attempt to index field ‘ply_groups’ (a nil value)

  1. unknown - gamemodes/terrortown/gamemode/vgui/sb_main.lua:184

Thanks, This works fine. But How can I add it for more groups.

Kind Regards.

if ply:IsUserGroup(“superadmin”) then
self.cols[5]:SetText(“SUPERADMIN”)
self.cols[5]:SetTextColor(Color(255,0,0,255))
end

I know it’s super hard to read LUA but just give it another shot :slight_smile:

I already made it say “Owner” for me but everyone else just has “Rank” I need to add mod admin etc.

[LUA]
if ply:IsUserGroup(“guest”) then
self.cols[5]:SetText("")
self.cols[5]:SetTextColor(Color(255,0,0,255))
end
[/LUA]

That’s for Guests (Why don’t you try)

Afraid to say that this code was a mess and it took me a while to sort it out… but i did

You can replace the titles and colours and whatnot from 163-201

Have any questions feel free to ask.

(this is the exact code i am using on my sever and it works fine)

Hello im having a problem with mine, i put the code in and its showing ranks ok but they are very far right of the score board

Click link to see what i mean

does anyone know how to correct this ?

i used this code

bump :slight_smile:

I would love it if someone could help him move it in the middle, Would be a lot of help.

in your sb_row.lua you should see this function

[lua]function PANEL:LayoutColumns()
for k,v in ipairs(self.cols) do
v:SizeToContents()
v:SetPos(self:GetWide() - (50*k) - v:GetWide()/2, (SB_ROW_HEIGHT - v:GetTall()) / 2)
end
[/lua]

Change it like this
[lua]function PANEL:LayoutColumns()
for k,v in ipairs(self.cols) do
v:SizeToContents()
v:SetPos(self:GetWide() - (50k) - v:GetWide()/2, (SB_ROW_HEIGHT - v:GetTall()) / 2)
if v == self.cols[5] then
v:SetPos(self:GetWide() - (85
k) - v:GetWide()/2, (SB_ROW_HEIGHT - v:GetTall()) / 2)
end
end[/lua]

Then in your sb_main.lua file
[lua]function PANEL:PerformLayout()



for k,v in ipairs(self.cols) do
v:SizeToContents()
v:SetPos( w - (50*k) - v:GetWide()/2 - 8, cy)
end
end
[/lua]

Edit so it looks like
[lua]
for k,v in ipairs(self.cols) do
v:SizeToContents()
v:SetPos( w - (50k) - v:GetWide()/2 - 8, cy)
if v == self.cols[5] then
v:SetPos( w - 85
k) - v:GetWide()/2 - 8, cy)
end
end
[/lua]
Just change around the “85” if you want to move it to the left more or right more.
You increase the number to move it to the left more and you decrease the number to move it to the right more.

That did not work, well it did but it didnt move the “rank” only moved the title