• Rank Display looks ugly, can anyone fix this?
    17 replies, posted
Well I'm running a functional TTT Gmod Server. With my knowledge of Lua I modified the scoreboard so that shows your rank. Such as if you are a Mod or Admin or even the Owner. This is what it currently looks like: [url]http://puu.sh/1BNKj[/url] Here is what I want it to be similar to: [url]http://i.imgur.com/LRHxq.jpg[/url] Now I don't know exactly why the text is like that with it stacking but If any one can help me with it will be really appreciated :D. Download Link of Code: [url]http://www.mediafire.com/?af0eanq46057uaq[/url] 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.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!\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.cols[5] = vgui.Create("DLabel", self) self.cols[5]:SetText("Rank ") if ply:IsUserGroup("superadmin") then self.cols[5]:SetText("Super Admin ") -- self.cols[5]:SetTextColor(Color(255,0,0,255)) end if ply:IsUserGroup("admin") then self.cols[5]:SetText("Admin ") --self.cols[5]:SetTextColor(Color(255,0,0,255)) end if ply:IsUserGroup("owner") then self.cols[5]:SetText("Teh Owner ") --self.cols[5]:SetTextColor(Color(255,0,0,255)) end if ply:IsUserGroup("operator") then self.cols[5]:SetText("Moderator ") --self.cols[5]:SetTextColor(Color(255,0,0,255)) end if ply:IsUserGroup("operator") then self.cols[5]:SetText("Moderator ") --self.cols[5]:SetTextColor(Color(255,0,0,255)) end if ply:IsUserGroup("Respected") then self.cols[5]:SetText("Donor ") --self.cols[5]:SetTextColor(Color(255,0,0,255)) 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)
Prefer you just post the code instead of making me download a random mediafire .rar.
[QUOTE=CaptainFab;39101901]Prefer you just post the code instead of making me download a random mediafire .rar.[/QUOTE] Sure. I'll do that.
You didn't close ("rank") on sb_main
[QUOTE=CaptainFab;39102142]You didn't close ("rank") on sb_main[/QUOTE] That crashed the server. Warning: vgui.Create failed to create the VGUI component (TTTScoreboard) [ERROR] gamemodes/terrortown/gamemode/cl_scoreboard.lua:39: attempt to index global 'sboard_panel' (a nil value) 1. unknown - gamemodes/terrortown/gamemode/cl_scoreboard.lua:39
Move self.cols[5] = vgui.Create( "DLabel", self ) self.cols[5]:SetText("Rank") above if KARMA.IsEnabled() then self.cols[4] = vgui.Create("DLabel", self) self.cols[4]:SetText(GetTranslation("sb_karma")) end You need to move the code for the group names and colors down to about line 167. Also change all ifs after the first one and make it elseif. Take out the -- before self.cols there also and line it up under the if then statement correctly also. I'm not sure WHY you don't think closing the rank names in a ("namehere") isn't a good idea either.
[QUOTE=CaptainFab;39105960]Move self.cols[5] = vgui.Create( "DLabel", self ) self.cols[5]:SetText("Rank") above if KARMA.IsEnabled() then self.cols[4] = vgui.Create("DLabel", self) self.cols[4]:SetText(GetTranslation("sb_karma")) end You need to move the code for the group names and colors down to about line 167. Also change all ifs after the first one and make it elseif. Take out the -- before self.cols there also and line it up under the if then statement correctly also. I'm not sure WHY you don't think closing the rank names in a ("namehere") isn't a good idea either.[/QUOTE] Well I closed everything and I get disconnected still. [ERROR] gamemodes/terrortown/gamemode/vgui/sb_row.lua:164: unexpected symbol near ')' 1. unknown - gamemodes/terrortown/gamemode/vgui/sb_row.lua:0 This is line 164: self.cols[5]:SetText("Rank "))
[QUOTE=Starz0r;39109039]This is line 164: self.cols[5]:SetText("Rank ")[B])[/B][/QUOTE] You added an extra parenthesis.
[QUOTE=Eccid;39109208]You added an extra parenthesis.[/QUOTE] I thought that was closing it?
[QUOTE=Starz0r;39109282]I thought that was closing it?[/QUOTE] No... No that is not how you close it.....
[QUOTE=CaptainFab;39110420]No... No that is not how you close it.....[/QUOTE] Do I use the end tag to close it then?
You only need one ).....
[QUOTE=CaptainFab;39110768]You only need one ).....[/QUOTE] Then what am I closing and how? EDIT: I've already added the elseif statements.
Anyone have any idea? EDIT: Glad I'm getting downvoted for asking a question. :D
I put the offending parenthesis in bold on my reply you put [CODE] self.cols[5]:SetText("Rank "))[/CODE] when it needs to be [code] self.cols[5]:SetText("Rank ")[/code] What do you use to edit your scripts? Find something built to work with code and you'll have an easier time. I use notepad++ for lua, and would have spotted the extra parenthesis with it.
[QUOTE=Eccid;39114335]I put the offending parenthesis in bold on my reply you put [CODE] self.cols[5]:SetText("Rank "))[/CODE] when it needs to be [code] self.cols[5]:SetText("Rank ")[/code] What do you use to edit your scripts? Find something built to work with code and you'll have an easier time. I use notepad++ for lua, and would have spotted the extra parenthesis with it.[/QUOTE] Same thing I use for editing my code.
What do I do next? Is there anything I should add because it still isn't working. It just crashes the server.
[QUOTE=Starz0r;39117994]What do I do next? Is there anything I should add because it still isn't working. It just crashes the server.[/QUOTE] Bump.
Sorry, you need to Log In to post a reply to this thread.