• TTT Scoreboard Help
    2 replies, posted
[IMG]http://i.imgur.com/1XAbHtb.png[/IMG] Recently my server's been spamming me errors: [CODE][ERROR] gamemodes/terrortown/gamemode/vgui/sb_team.lua:69: attempt to index local 'row' (a number value) 1. unknown - gamemodes/terrortown/gamemode/vgui/sb_team.lua:69 [/CODE] Whenever I attempt to open my scoreboard that's what pops up. Here is my coding for my scoreboard lua cl_scoreboard.lua [CODE]-- a much requested darker scoreboard local table = table local surface = surface local draw = draw local math = math local team = team local namecolor = { admin = Color(220, 180, 0, 255) }; include("vgui/sb_main.lua") sboard_panel = nil local function ScoreboardRemove() if sboard_panel then sboard_panel:Remove() sboard_panel = nil end end hook.Add("TTTLanguageChanged", "RebuildScoreboard", ScoreboardRemove) function GM:ScoreboardCreate() ScoreboardRemove() sboard_panel = vgui.Create("TTTScoreboard") end function GM:ScoreboardShow() self.ShowScoreboard = true if not sboard_panel then self:ScoreboardCreate() end gui.EnableScreenClicker(true) sboard_panel:SetVisible(true) sboard_panel:UpdateScoreboard(true) sboard_panel:StartUpdateTimer() end function GM:ScoreboardHide() self.ShowScoreboard = false gui.EnableScreenClicker(false) if sboard_panel then sboard_panel:SetVisible(false) end end function GM:GetScoreboardPanel() return sboard_panel end function GM:HUDDrawScoreBoard() -- replaced by panel version end[/CODE] sb_row.lua [CODE]---- 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:AddColumn( GetTranslation("sb_ping"), function(ply) return ply:Ping() end ) self:AddColumn( GetTranslation("sb_deaths"), function(ply) return ply:Deaths() end ) self:AddColumn( GetTranslation("sb_score"), function(ply) return ply:Frags() end ) if KARMA.IsEnabled() then self:AddColumn( GetTranslation("sb_karma"), function(ply) return math.Round(ply:GetBaseKarma()) end ) end -- Let hooks add their custom columns hook.Call("TTTScoreboardColumns", nil, self) 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 function PANEL:AddColumn( label, func ) local lbl = vgui.Create( "DLabel", self ) lbl.GetPlayerText = func lbl.IsHeading = false table.insert( self.cols, lbl ) return lbl 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!\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 for i=1,#self.cols do -- Set text from function, passing the label along so stuff like text -- color can be changed self.cols[i]:SetText( self.cols[i].GetPlayerText(ply, self.cols[i]) ) 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 * (#self.cols+1)) - self.tag:GetWide()/2, (SB_ROW_HEIGHT - self.tag:GetTall()) / 2) self.sresult:SetPos(self:GetWide() - (50*(#self.cols+1)) - 8, (SB
Post sb_team.lua, also why are you editing the core TTT files?
[QUOTE=smithy285;44216517]Post sb_team.lua, also why are you editing the core TTT files?[/QUOTE] sb_team.lua [CODE]---- Unlike sandbox, we have teams to deal with, so here's an extra panel in the ---- hierarchy that handles a set of player rows belonging to its team. include("sb_row.lua") local function CompareScore(pa, pb) if not ValidPanel(pa) then return false end if not ValidPanel(pb) then return true end local a = pa:GetPlayer() local b = pb:GetPlayer() if not IsValid(a) then return false end if not IsValid(b) then return true end if a:Frags() == b:Frags() then return a:Deaths() < b:Deaths() end return a:Frags() > b:Frags() end local PANEL = {} function PANEL:Init() self.name = "Unnamed" self.color = COLOR_WHITE self.rows = {1} self.rowcount = 0 self.rows_sorted = {} self.group = "spec" end function PANEL:SetGroupInfo(name, color, group) self.name = name self.color = color self.group = group end local bgcolor = Color(20,20,20, 150) function PANEL:Paint() -- Darkened background draw.RoundedBox(0, 0, 0, self:GetWide(), self:GetTall(), bgcolor) surface.SetFont("treb_small") -- Header bg local txt = self.name .. " (" .. self.rowcount .. ")" local w, h = surface.GetTextSize(txt) draw.RoundedBox(0, 0, 0, w + 24, 20, self.color) -- Shadow surface.SetTextPos(11, 11 - h/2) surface.SetTextColor(0,0,0, 200) surface.DrawText(txt) -- Text surface.SetTextPos(10, 10 - h/2) surface.SetTextColor(255,255,255,255) surface.DrawText(txt) -- Alternating row background local y = 24 for i, row in ipairs(self.rows_sorted) do if (i % 2) != 0 then surface.SetDrawColor(75,75,75, 100) surface.DrawRect(0, y, self:GetWide(), row:GetTall()) end y = y + row:GetTall() + 1 end -- Column darkening surface.SetDrawColor(0,0,0, 80) surface.DrawRect(self:GetWide() - 175, 0, 50, self:GetTall()) surface.DrawRect(self:GetWide() - 75, 0, 50, self:GetTall()) surface.DrawRect(self:GetWide() - 300, 0, 76, self:GetTall()) end function PANEL:AddPlayerRow(ply) if ScoreGroup(ply) == self.group and not self.rows[ply] then local row = vgui.Create("TTTScorePlayerRow", self) row:SetPlayer(ply) self.rows[ply] = row self.rowcount = table.Count(self.rows) -- row:InvalidateLayout() -- must force layout immediately or it takes its sweet time to do so self:PerformLayout() --self:InvalidateLayout() end end function PANEL:HasPlayerRow(ply) return self.rows[ply] != nil end function PANEL:HasRows() return self.rowcount > 0 end function PANEL:UpdateSortCache() self.rows_sorted = {} for k,v in pairs(self.rows) do table.insert(self.rows_sorted, v) end table.sort(self.rows_sorted, CompareScore) end function PANEL:UpdatePlayerData() local to_remove = {} for k,v in pairs(self.rows) do -- Player still belongs in this group? if ValidPanel(v) and IsValid(v:GetPlayer()) and ScoreGroup(v:GetPlayer()) == self.group then v:UpdatePlayerData() else -- can't remove now, will break pairs table.insert(to_remove, k) end end if #to_remove == 0 then return end for k,ply in pairs(to_remove) do local pnl = self.rows[ply] if ValidPanel(pnl) then pnl:Remove() end -- print(CurTime(), "Removed player", ply) self.rows[ply] = nil end self.rowcount = table.Count(self.rows) self:UpdateSortCache() self:InvalidateLayout() end function PANEL:PerformLayout() if self.rowcount < 1 then self:SetVisible(false) return end self:SetSize(self:GetWide(), 30 + self.rowcount + self.rowcount * SB_ROW_HEIGHT) -- Sort and layout player rows self:UpdateSortCache() local y = 24 for k, v in ipairs(self.rows_sorted) do v:SetPos(0, y) v:SetSize(self:GetWide(), v:GetTall()) y = y + v:GetTall() + 1 end self:SetSize(self:GetWide(), 30 + (y - 24)) end vgui.Register("TTTScoreGroup", PANEL, "Panel") [/CODE] To get the rank tab you have to edit the sb_row.lua, but I reset the sb_row.lua to default.
Sorry, you need to Log In to post a reply to this thread.