ULX

Author Topic: ULX scoreboard and text color help TTT server  (Read 35248 times)

0 Members and 1 Guest are viewing this topic.

Offline DJ Mikey

  • Newbie
  • *
  • Posts: 17
  • Karma: 0
ULX scoreboard and text color help TTT server
« on: August 26, 2013, 07:46:36 AM »
Hello!
I just recently created a Gmod 13 TTT server, everything is working perfectly fine and this can also be said about the ULX admin tool i installed just a couple of hours ago. I had a couple of questions pertaining to the !xgui that i cant seem to figure out due to most of the "solutions" being extremely outdated.  Please bare with me, i am a "noob" and am pretty new to lua (literally, what files need to be edited ect).  The amount of knowledge my brain has soaked up this week is pretty overwhelming but i am extremely determined!

The gui does not seem to match the gui that i have found searching for a solution to my question. It is outdated and to my knowledge no longer works with the most recent versions of ULX and Ulib. I do not use SVN because my server is hosted off a linux platform. Due to the gui not being the same as the one i have found online, i have no idea how to go about changing font color within the server. I have created the groups id like to use but wish to change the name color and scoreboard color for the text. For example, Super admins red, admins green, VIP blue, Donators yellow.

This fabled gui i keep finding with google and even a newer one that turned up in a search result all have special editing tools for groups that allow text color and even model editing.  I do not get this option.  I have come to learn that it may be because i am running a TTT server, thus Uteam does not work?


Thank you in advance for your time!

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: ULX scoreboard and text color help TTT server
« Reply #1 on: August 26, 2013, 08:06:50 AM »
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline DJ Mikey

  • Newbie
  • *
  • Posts: 17
  • Karma: 0
Re: ULX scoreboard and text color help TTT server
« Reply #2 on: August 26, 2013, 08:21:34 AM »
Awesome thanks for the swift reply!  Im dling both files i take it?  ah nvm could only DL as zip the master file.  So im simply replacing the ULX folder and Ulib folder with the ones i am dling at git?

Offline Stickly Man!

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 1270
  • Karma: 164
  • What even IS software anymore?
    • XGUI
Re: ULX scoreboard and text color help TTT server
« Reply #3 on: August 26, 2013, 10:01:12 AM »
Ah yes, I thought you would be able to download the zips for both, but, the master would contain all of our projects on git which is probably more than you want. Just the "ulx" and "ulib" ones are all you need. And I would delete the old ulx/ulib folders before putting these ones on, just to be safe. Your specific data should be stored elsewhere (gmod/data/ulx, gmod/data/ulib), so it shouldn't reset anything for you.
Join our Team Ulysses community discord! https://discord.gg/gR4Uye6

Offline DJ Mikey

  • Newbie
  • *
  • Posts: 17
  • Karma: 0
Re: ULX scoreboard and text color help TTT server
« Reply #4 on: August 26, 2013, 10:31:37 AM »
Alright, ULX 3.61 is installed and confirmed working on my server.  However, team making is still greyed out, if im not mistaken this is because my server is running the TTT gamemode?  How else would i go about adding colored text for each group and scoreboard tags?  I can only assume Lua editing?  I suppose im lost as far as what .lua's id be editing and with which different code i  have found. 

I appreciate the help and patience!

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: ULX scoreboard and text color help TTT server
« Reply #5 on: August 26, 2013, 12:36:44 PM »
I have a topic related to this, one of my replies should have a download for the files (should be gamemodes/terrortown/gamemode/vgui/ in the archive, more specifically sb_row.lua & sb_main.lua). Take a look at it, and I'll (attempt to) help you out with anything you need.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline DJ Mikey

  • Newbie
  • *
  • Posts: 17
  • Karma: 0
Re: ULX scoreboard and text color help TTT server
« Reply #6 on: August 26, 2013, 01:56:03 PM »
ok i think i know what to do with the sb_row.lua
Im going to wing it here, the code Stickly posted that fixed your issue gets placed in sb_main.lua   What line am i looking for?  If i am wrong i may need a more detailed walk through ):

Again thank you for your time.
« Last Edit: August 26, 2013, 02:18:52 PM by DJ Mikey »

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: ULX scoreboard and text color help TTT server
« Reply #7 on: August 26, 2013, 10:35:19 PM »
I forgot to post the link (sorry about that), but I found the original post that I got this from. My edited one is a bit more complicated, but if you wish you can look up "Scoreboard Help" (thread) on the forums. Although, this should still work for you, unless you want specific ranks for each player: http://www.zombiemaster.org/smf/index.php?topic=11877.0

I recommend following the steps from reply #11. He makes the scoreboard look nicer.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline DJ Mikey

  • Newbie
  • *
  • Posts: 17
  • Karma: 0
Re: ULX scoreboard and text color help TTT server
« Reply #8 on: August 27, 2013, 02:17:49 AM »
ah i see, that post 11 is only for making the scoreboard look better, so all i need to do is replace my files with what is in the original thread and i should be all set.  Thank you very much, ill do this asap and confirm whether it worked or not here.

Ok i may have done something wrong, it does not appear to be working.  What im trying to do is create special colors for 3 different groups, Vip, Super admin, Admin. 
I have added the sb_row.lua and sb_main.lua to my terrortown/gamemode/vgui folder, yet see nothing.  I even went and added the superadmin and vip groups to the sb_row.lua with the corresponding color id like it to be.v  I also do not see scoreboard ranks.

I also got this error

Warning: vgui.Create failed to create the VGUI component (TTTScorePlayerRow)

[ERROR] gamemodes/terrortown/gamemode/vgui/sb_team.lua:85: attempt to index local 'row' (a nil value)
  1. AddPlayerRow - gamemodes/terrortown/gamemode/vgui/sb_team.lua:85
   2. UpdateScoreboard - gamemodes/terrortown/gamemode/vgui/sb_main.lua:270
    3. Init - gamemodes/terrortown/gamemode/vgui/sb_main.lua:140
     4. Create - lua/includes/extensions/client/panel/scriptedpanels.lua:153
      5. ScoreboardCreate - gamemodes/terrortown/gamemode/cl_scoreboard.lua:27
       6. unknown - gamemodes/terrortown/gamemode/cl_scoreboard.lua:34

Disconnect: "Too many Lua Errors! Sorry!".
Disconnect: "Too many Lua Errors! Sorry!".





Ok im going to give this a shot. 
Here is what the lines look like defualt

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

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

   --ADD NAMECOLOURS HERE--
   if ply:SteamID() == "STEAM_0:0:1963640" then
      return namecolor.dev
   elseif ply:IsAdmin() and GetGlobalBool("ttt_highlight_admins", true) then
      return namecolor.admin
   elseif ply:IsUserGroup("superadmin") then
      return namecolor.test
   end
   return namecolor.default

in order for me to add vip and admin im siply making this changes?

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

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

   --ADD NAMECOLOURS HERE--
   if ply:SteamID() == "STEAM_0:0:000000" then
      return namecolor.vip
   elseif ply:IsAdmin() and GetGlobalBool("ttt_highlight_admins", true) then
      return namecolor.admin
   elseif ply:IsUserGroup("superadmin") then
       return namecolor.test

   end
   return namecolor.default

How would add more steam ids to the "vip" section.

Edit: i have reverted back to my back up sb_main and sb_row files for the time being.  I intend to have alot of people on my server tonight and do not wish to break anything before this event.  I have all these snipits of code but have no idea where to put it.  I cant imagine sb_row.lua is the only file i need to be editing.
« Last Edit: August 27, 2013, 07:08:26 AM by DJ Mikey »

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: ULX scoreboard and text color help TTT server
« Reply #9 on: August 27, 2013, 10:49:53 PM »
This should work for the names:
Code: [Select]
local namecolor = {
   default = COLOR_WHITE,
   admin = Color(225, 255, 255, 255),
   dev = Color(255, 255, 255, 255),
   vip = Color(240, 255, 10, 255),
};
 
function GM:TTTScoreboardColorForPlayer(ply)
   if not IsValid(ply) then return namecolor.default end
 
   --ADD NAMECOLOURS HERE--
if ply:SteamID() == "STEAM_0:0:1963640" then --Change Steam ID
return namecolor.vip
elseif ply:SteamID() == "STEAM_0:1:00110011" then --Change SteamID
return namecolor.vip
elseif ply:SteamID() == "STEAM_0:1:11111111" then --Change SteamID
return namecolor.vip
elseif ply:IsAdmin() and GetGlobalBool("ttt_highlight_admins", true) then
return namecolor.admin
elseif ply:IsUserGroup("superadmin") then
return namecolor.admin
   end
   return namecolor.default
end

Alternatively, you could do this:

Code: [Select]
local namecolor = {
   default = COLOR_WHITE,
   admin = Color(225, 255, 255, 255),
   dev = Color(255, 255, 255, 255),
   vipcolor = Color(240, 255, 10, 255),
};

local Vip = {
["STEAM_0:11223344"] = true, --Test1
["STEAM_0:44332211"] = true, --Test2
["STEAM_0:12345678"] = true, --Test3
}

function GM:TTTScoreboardColorForPlayer(ply)
if not IsValid(ply) then return namecolor.default end
local vip = Vip[ply:SteamID()]
   --ADD NAMECOLOURS HERE--
if vip then
return namecolor.vipcolor
elseif ply:IsAdmin() and GetGlobalBool("ttt_highlight_admins", true) then
return namecolor.admin
elseif ply:IsUserGroup("superadmin") then
return namecolor.admin
   end
   return namecolor.default
end
Inside "local Vip" change the Steam IDs inside the quotes, or add more depending on what you want. This way, you don't have to do the whole "ply:SteamID() == "STEAM_0:0:0000000"" in the function, you just add under that. I personally like this method, because it looks more clean, but you decide what you want to use.

This only modifies the names though, if you want to add ranks in it's own row in the scoreboard, you need to look at the function called "PANEL:UpdatePlayerData". Should be in line 180 (or close to that)
« Last Edit: August 27, 2013, 10:52:10 PM by Decicus »
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline DJ Mikey

  • Newbie
  • *
  • Posts: 17
  • Karma: 0
Re: ULX scoreboard and text color help TTT server
« Reply #10 on: August 28, 2013, 12:00:53 PM »
ok, i entered this code.  Still nothin.  Im going to recap on what my status is.

The link you posted with the sb_row.lua and sb_main.lua is what im using.
i used the code you just posted above this post in the sb_row.lua

after i reset the server, my scoreboard has a "rank" colum, this is good!  but... the rank "vip" "admin" "user" do not show.  Super admin showed in a light gray text but the min in admin underlayed with the current karma.  In other words it did not fit.  Also, the players name color is not changed at all.

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: ULX scoreboard and text color help TTT server
« Reply #11 on: August 28, 2013, 12:46:00 PM »
I'm not sure about the namecolor, because I don't use it myself. Although, your scoreboard might be messed up because you're using the original code. I'd advise you to use the one in reply #11 from this post: http://www.zombiemaster.org/smf/index.php?topic=11877.0

I have absolutely no experience with the original code or the namecolors, but I want to take a look at your full code, so if you could post it here (preferably with the use of 'Code' BB tags to make it look more clean), that would be nice. I'm using the "fix" from reply #11, and mine works fine. Not quite sure what your issue is.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline DJ Mikey

  • Newbie
  • *
  • Posts: 17
  • Karma: 0
Re: ULX scoreboard and text color help TTT server
« Reply #12 on: August 28, 2013, 06:58:16 PM »
sb_row.lua

Code: [Select]
---- 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"))
   
  self.cols[5] = vgui.Create("DLabel", self)
  self.cols[5]:SetText("Rank")
 
   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
 
----EDIT THESE TO ADD MORE COLOURS----
----Example: test = COLOR_BLUE----
---Make sure to put a comma after each line until the end (Last one doesn't have one---
 
local namecolor = {
   default = COLOR_WHITE,
   admin = Color(220, 180, 0, 255),
   dev = Color(100, 240, 105, 255),
   vip = Color(0, 255, 0, 255)
};
 
function GM:TTTScoreboardColorForPlayer(ply)
   if not IsValid(ply) then return namecolor.default end
 
   --ADD NAMECOLOURS HERE--
   if ply:SteamID() == "STEAM_0:0:1963640" then
      return namecolor.vip
   elseif ply:IsAdmin() and GetGlobalBool("ttt_highlight_admins", true) then
      return namecolor.admin
   elseif ply:IsUserGroup("superadmin") then
                return namecolor.dev
   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!\n")
      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))
   
   
        if ply:IsUserGroup("superadmin") then
                self.cols[5]:SetText("Super Admin")
                self.cols[5]:SetTextColor(namecolor.test)
        elseif ply:IsUserGroup("admin") then
                self.cols[5]:SetText("Admin")
                self.cols[5]:SetTextColor(Color(220, 180, 0, 255))
--      elseif ply:IsUserGroup("admin") then
--              self.cols[5]:SetText("Admin")
--              self.cols[5]:SetTextColor(Color(220, 180, 0, 255))
--  Delete the -- and change the settings to your liking. DO NOT DELETE THE 'end'
        end
 
   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" )

sb_main.lua

Code: [Select]
---- VGUI panel version of the scoreboard, based on TEAM GARRY's sandbox mode
---- scoreboard.
 
local surface = surface
local draw = draw
local math = math
local string = string
local vgui = vgui
 
local GetTranslation = LANG.GetTranslation
local GetPTranslation = LANG.GetParamTranslation
 
include("sb_team.lua")
 
surface.CreateFont("cool_small", {font = "coolvetica",
                                  size = 20,
                                  weight = 400})
surface.CreateFont("cool_large", {font = "coolvetica",
                                  size = 24,
                                  weight = 400})
surface.CreateFont("treb_small", {font = "Trebuchet18",
                                  size = 14,
                                  weight = 700})
 
local logo = surface.GetTextureID("VGUI/ttt/score_logo")
 
local PANEL = {}
 
local max = math.max
local floor = math.floor
local function UntilMapChange()
   local rounds_left = max(0, GetGlobalInt("ttt_rounds_left", 6))
   local time_left = floor(max(0, ((GetGlobalInt("ttt_time_limit_minutes") or 60) * 60) - CurTime()))
 
   local h = floor(time_left / 3600)
   time_left = time_left - floor(h * 3600)
   local m = floor(time_left / 60)
   time_left = time_left - floor(m * 60)
   local s = floor(time_left)
 
   return rounds_left, string.format("%02i:%02i:%02i", h, m, s)
end
 
 
GROUP_TERROR = 1
GROUP_NOTFOUND = 2
GROUP_FOUND = 3
GROUP_SPEC = 4
 
GROUP_COUNT = 4
 
function ScoreGroup(p)
   if not IsValid(p) then return -1 end -- will not match any group panel
 
   if DetectiveMode() then
      if p:IsSpec() and (not p:Alive()) then
         if p:GetNWBool("body_found", false) then
            return GROUP_FOUND
         else
            local client = LocalPlayer()
            -- To terrorists, missing players show as alive
            if client:IsSpec() or
               client:IsActiveTraitor() or
               ((GAMEMODE.round_state != ROUND_ACTIVE) and client:IsTerror()) then
               return GROUP_NOTFOUND
            else
               return GROUP_TERROR
            end
         end
      end
   end
 
   return p:IsTerror() and GROUP_TERROR or GROUP_SPEC
end
 
function PANEL:Init()
 
   self.hostdesc = vgui.Create("DLabel", self)
   self.hostdesc:SetText(GetTranslation("sb_playing"))
   self.hostdesc:SetContentAlignment(9)
 
   self.hostname = vgui.Create( "DLabel", self )
   self.hostname:SetText( GetHostName() )
   self.hostname:SetContentAlignment(6)
 
   self.mapchange = vgui.Create("DLabel", self)
   self.mapchange:SetText("Map changes in 00 rounds or in 00:00:00")
   self.mapchange:SetContentAlignment(9)
 
   self.mapchange.Think = function (sf)
                             local r, t = UntilMapChange()
 
                             sf:SetText(GetPTranslation("sb_mapchange",
                                                        {num = r, time = t}))
                             sf:SizeToContents()
                          end
 
 
   self.ply_frame = vgui.Create( "TTTPlayerFrame", self )
 
   self.ply_groups = {}
 
   local t = vgui.Create("TTTScoreGroup", self.ply_frame:GetCanvas())
   t:SetGroupInfo(GetTranslation("terrorists"), Color(0,200,0,100), GROUP_TERROR)
   self.ply_groups[GROUP_TERROR] = t
 
   t = vgui.Create("TTTScoreGroup", self.ply_frame:GetCanvas())
   t:SetGroupInfo(GetTranslation("spectators"), Color(200, 200, 0, 100), GROUP_SPEC)
   self.ply_groups[GROUP_SPEC] = t
 
   if DetectiveMode() then
      t = vgui.Create("TTTScoreGroup", self.ply_frame:GetCanvas())
      t:SetGroupInfo(GetTranslation("sb_mia"), Color(130, 190, 130, 100), GROUP_NOTFOUND)
      self.ply_groups[GROUP_NOTFOUND] = t
 
      t = vgui.Create("TTTScoreGroup", self.ply_frame:GetCanvas())
      t:SetGroupInfo(GetTranslation("sb_confirmed"), Color(130, 170, 10, 100), GROUP_FOUND)
      self.ply_groups[GROUP_FOUND] = t
   end
 
   -- the various score column headers
   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") )
 
   self.cols[5] = vgui.Create( "DLabel", self )
   self.cols[5]:SetText("Rank")
   
   if KARMA.IsEnabled() then
      self.cols[4] = vgui.Create("DLabel", self)
      self.cols[4]:SetText(GetTranslation("sb_karma"))
   end
 
   self:UpdateScoreboard()
   self:StartUpdateTimer()
end
 
function PANEL:StartUpdateTimer()
   if not timer.Exists("TTTScoreboardUpdater") then
      timer.Create( "TTTScoreboardUpdater", 0.3, 0,
                    function()
                       local pnl = GAMEMODE:GetScoreboardPanel()
                       if IsValid(pnl) then
                          pnl:UpdateScoreboard()
                       end
                    end)
   end
end
 
local colors = {
   bg = Color(30,30,30, 235),
   bar = Color(220,180,0,255)
};
 
local y_logo_off = 72
 
function PANEL:Paint()
   -- Logo sticks out, so always offset bg
   draw.RoundedBox( 8, 0, y_logo_off, self:GetWide(), self:GetTall() - y_logo_off, colors.bg)
 
   -- Server name is outlined by orange/gold area
   draw.RoundedBox( 8, 0, y_logo_off + 25, self:GetWide(), 32, colors.bar)
 
   -- TTT Logo
   surface.SetTexture( logo )
   surface.SetDrawColor( 255, 255, 255, 255 )
   surface.DrawTexturedRect( 5, 0, 256, 256 )
 
end
 
function PANEL:PerformLayout()
   -- position groups and find their total size
   local gy = 0
   -- can't just use pairs (undefined ordering) or ipairs (group 2 and 3 might not exist)
   for i=1, GROUP_COUNT do
      local group = self.ply_groups[i]
      if ValidPanel(group) then
         if group:HasRows() then
            group:SetVisible(true)
            group:SetPos(0, gy)
            group:SetSize(self.ply_frame:GetWide(), group:GetTall())
            group:InvalidateLayout()
            gy = gy + group:GetTall() + 5
         else
            group:SetVisible(false)
         end
      end
   end
 
   self.ply_frame:GetCanvas():SetSize(self.ply_frame:GetCanvas():GetWide(), gy)
 
   local h = y_logo_off + 110 + self.ply_frame:GetCanvas():GetTall()
 
   -- if we will have to clamp our height, enable the mouse so player can scroll
   local scrolling = h > ScrH() * 0.95
--   gui.EnableScreenClicker(scrolling)
   self.ply_frame:SetScroll(scrolling)
 
   h = math.Clamp(h, 110 + y_logo_off, ScrH() * 0.95)
 
   local w = math.max(ScrW() * 0.6, 640)
 
   self:SetSize(w, h)
   self:SetPos( (ScrW() - w) / 2, math.min(72, (ScrH() - h) / 4))
 
   self.ply_frame:SetPos(8, y_logo_off + 109)
   self.ply_frame:SetSize(self:GetWide() - 16, self:GetTall() - 109 - y_logo_off - 5)
 
   -- server stuff
   self.hostdesc:SizeToContents()
   self.hostdesc:SetPos(w - self.hostdesc:GetWide() - 8, y_logo_off + 5)
 
   local hw = w - 180 - 8
   self.hostname:SetSize(hw, 32)
   self.hostname:SetPos(w - self.hostname:GetWide() - 8, y_logo_off + 27)
 
   surface.SetFont("cool_large")
   local hname = self.hostname:GetValue()
   local tw, _ = surface.GetTextSize(hname)
   while tw > hw do
      hname = string.sub(hname, 1, -6) .. "..."
      tw, th = surface.GetTextSize(hname)
   end
 
   self.hostname:SetText(hname)
 
   self.mapchange:SizeToContents()
   self.mapchange:SetPos(w - self.mapchange:GetWide() - 8, y_logo_off + 60)
 
   -- score columns
   local cy = y_logo_off + 90
   for k,v in ipairs(self.cols) do
      v:SizeToContents()
      v:SetPos( w - (50*k) - v:GetWide()/2 - 8, cy)
   end
end
 
function PANEL:ApplySchemeSettings()
   self.hostdesc:SetFont("cool_small")
   self.hostname:SetFont("cool_large")
   self.mapchange:SetFont("treb_small")
 
   self.hostdesc:SetTextColor(COLOR_WHITE)
   self.hostname:SetTextColor(COLOR_BLACK)
   self.mapchange:SetTextColor(COLOR_WHITE)
 
   for k,v in pairs(self.cols) do
      v:SetFont("treb_small")
      v:SetTextColor(COLOR_WHITE)
   end
end
 
function PANEL:UpdateScoreboard( force )
   if not force and not self:IsVisible() then return end
 
   local layout = false
 
   -- Put players where they belong. Groups will dump them as soon as they don't
   -- anymore.
   for k, p in pairs(player.GetAll()) do
      if IsValid(p) then
         local group = ScoreGroup(p)
         if self.ply_groups[group] and not self.ply_groups[group]:HasPlayerRow(p) then
            self.ply_groups[group]:AddPlayerRow(p)
            layout = true
         end
      end
   end
 
   for k, group in pairs(self.ply_groups) do
      if ValidPanel(group) then
         group:SetVisible( group:HasRows() )
         group:UpdatePlayerData()
      end
   end
 
   if layout then
      self:PerformLayout()
   else
      self:InvalidateLayout()
   end
end
 
vgui.Register( "TTTScoreboard", PANEL, "Panel" )
 
---- PlayerFrame is defined in sandbox and is basically a little scrolling
---- hack. Just putting it here (slightly modified) because it's tiny.
 
local PANEL = {}
function PANEL:Init()
   self.pnlCanvas  = vgui.Create( "Panel", self )
   self.YOffset = 0
 
   self.scroll = vgui.Create("DVScrollBar", self)
end
 
function PANEL:GetCanvas() return self.pnlCanvas end
 
function PANEL:OnMouseWheeled( dlta )
   self.scroll:AddScroll(dlta * -2)
 
   self:InvalidateLayout()
end
 
function PANEL:SetScroll(st)
   self.scroll:SetEnabled(st)
end
 
function PANEL:PerformLayout()
   self.pnlCanvas:SetVisible(self:IsVisible())
 
   -- scrollbar
   self.scroll:SetPos(self:GetWide() - 16, 0)
   self.scroll:SetSize(16, self:GetTall())
 
   local was_on = self.scroll.Enabled
   self.scroll:SetUp(self:GetTall(), self.pnlCanvas:GetTall())
   self.scroll:SetEnabled(was_on) -- setup mangles enabled state
 
   self.YOffset = self.scroll:GetOffset()
 
   self.pnlCanvas:SetPos( 0, self.YOffset )
   self.pnlCanvas:SetSize( self:GetWide() - (self.scroll.Enabled and 16 or 0), self.pnlCanvas:GetTall() )
end
vgui.Register( "TTTPlayerFrame", PANEL, "Panel" )

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: ULX scoreboard and text color help TTT server
« Reply #13 on: August 29, 2013, 06:16:17 AM »
I'll take a look at it when I have time, and see what I can find out of.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline DJ Mikey

  • Newbie
  • *
  • Posts: 17
  • Karma: 0
Re: ULX scoreboard and text color help TTT server
« Reply #14 on: August 29, 2013, 08:37:15 AM »
thank you!