ULX

Author Topic: Lua error  (Read 3223 times)

0 Members and 3 Guests are viewing this topic.

Offline ojbristow

  • Newbie
  • *
  • Posts: 47
  • Karma: 0
    • Superclocked
Lua error
« on: January 04, 2014, 01:42:51 PM »
Hello,

When I try to add someone to the rank 'TTTAdmin' everything is fine until someone views the 'Scoreboard'.  When you try to view the scoreboard and a TTTAdmin is online you will get kicked.  Here is the error:

Code: [Select]
[[SPCL] Owen|2|STEAM_0:1:50719053] Lua Error:

[ERROR] lua/vgui/dlabel.lua:68: bad key to string index (number expected, got string)
1. error - [C]:-1
2. __index - lua/includes/extensions/string.lua:262
3. ApplySchemeSettings - lua/vgui/dlabel.lua:68
4. unknown - lua/vgui/dlabel.lua:74

I have never edited anything in the sting.lua and dlabel.lua. I have noidea how to fix this, any help would be much appreciated!

Thanks,

Owen


Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: Lua error
« Reply #1 on: January 04, 2014, 01:52:56 PM »
Do you have a custom scoreboard with ranks or something? If so, copy/paste the gamemodes/terrortown/gamemode/vgui/sb_row.lua.
Use the code BB code.
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: Lua error
« Reply #2 on: January 04, 2014, 03:12:47 PM »
If you are using the default TTT scoreboard, you can't just edit the sb_row.

You must also configure the sb_main as well.

A simple Google search will net you the code for both.
Out of the Garry's Mod business.

Offline ojbristow

  • Newbie
  • *
  • Posts: 47
  • Karma: 0
    • Superclocked
Re: Lua error
« Reply #3 on: January 04, 2014, 03:18:10 PM »
I have the set the scoreboard up properly, probably should have said that in the first post, it is working for the rest of the ranks.

Thanks,

Owen


Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: Lua error
« Reply #4 on: January 04, 2014, 03:29:21 PM »
I have the set the scoreboard up properly, probably should have said that in the first post, it is working for the rest of the ranks.

Thanks,

Owen

In that case, post your sb_row.Lua for me please.
Out of the Garry's Mod business.

Offline ojbristow

  • Newbie
  • *
  • Posts: 47
  • Karma: 0
    • Superclocked
Re: Lua error
« Reply #5 on: January 04, 2014, 03:31:44 PM »
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),
   owner = Color(255, 255, 0, 255),
   member = Color(0, 255, 255),
   trustedmember = Color(0, 139, 139),
   donator = Color(255, 165, 0),
   tttmod = Color(255, 182, 193),
   globalmod = Color(255, 20, 147),
   supporter = Color(0, 128, 0),
   trustedadmin = Color(0, 0, 139),
   tttadmin = Color(0, 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.dev
   elseif ply:IsAdmin() and GetGlobalBool("ttt_highlight_admins", true) then
      return namecolor.admin
   elseif ply:IsUserGroup("superadmin") then
      return namecolor.owner
   elseif ply:IsUserGroup("TTTMod") then
  return namecolor.tttmod
   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("Member") then
                self.cols[5]:SetText("Member")
                self.cols[5]:SetTextColor(namecolor.member)
elseif ply:IsUserGroup("user") then
self.cols[5]:SetText("Guest")
self.cols[5]:SetTextColor(namecolor.default)
        elseif ply:IsUserGroup("Owner") then
        self.cols[5]:SetText("Owner")
self.cols[5]:SetTextColor(Color(255, 255, 0,255))
elseif ply:IsUserGroup("Superadmin") then
        self.cols[5]:SetText("Owner")
self.cols[5]:SetTextColor(namecolor.owner)
        elseif ply:IsUserGroup("TrustedMember") then
    self.cols[5]:SetText("Trusted Member")
self.cols[5]:SetTextColor(namecolor.trustedmember)
elseif ply:IsUserGroup("Donator") then
self.cols[5]:SetText("Donator")
self.cols[5]:SetTextColor(namecolor.donator)
elseif ply:IsUserGroup("TTTMod") then
self.cols[5]:SetText("TTT Mod")
self.cols[5]:SetTextColor(namecolor.tttmod)
elseif ply:IsUserGroup("GlobalMod") then
self.cols[5]:SetText("Global Mod")
self.cols[5]:SetTextColor(namecolor.globalmod)
        elseif ply:IsUserGroup("Supporter") then
                self.cols[5]:SetText("Supporter")
                self.cols[5]:SetTextColor(namecolor.supporter)
elseif ply:IsUserGroup("TrustedAdmin") then
self.cols[5]:SetText("Trusted Admin")
self.cols[5]:SetTextColor(namecolor.trustedadmin)
elseif ply:IsUserGroup("TTTAdmin") then
self.cols[5]:SetText("TTT Admin")
self.cols[5]:SetTextColor("namecolor.tttadmin")
--      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)
      if v == self.cols[5] then
        v:SetPos(self:GetWide() - (85*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" )

Thanks,

Owen


Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: Lua error
« Reply #6 on: January 04, 2014, 03:37:42 PM »
It doesn't work because namecolor.tttadmin is being called as string.
Out of the Garry's Mod business.

Offline ojbristow

  • Newbie
  • *
  • Posts: 47
  • Karma: 0
    • Superclocked
Re: Lua error
« Reply #7 on: January 04, 2014, 03:39:38 PM »
Jesus, im an idiot, thanks for pointing it out.

Owen


Offline Neku

  • Hero Member
  • *****
  • Posts: 549
  • Karma: 27
Re: Lua error
« Reply #8 on: January 04, 2014, 03:43:29 PM »
It happens to everyone at some point.  ;)
Out of the Garry's Mod business.