Rookie editing TTT scoreboard

Hello there!

I’m starting to try and learn how to lua code and since I play a lot of TTT I thought I’d start there.

It’s just basics for any experienced coder but since I only got the wiki to follow I probably overlooked something that everyone else would notice.
I’m creating a rank column on the scoreboard with colored rank names and everything was working fine until I tried adding the colors to the ranks.

This is the code I wrote and this is the error I got:

[ERROR] gamemodes/terrortown/gamemode/vgui/sb_row.lua:82: ‘}’ expected (to close ‘{’ at line 71) near ‘=’

  1. unknown - gamemodes/terrortown/gamemode/vgui/sb_row.lua:0

(first line here is line 71)


local namecolor = {
    default = COLOR_WHITE,
        owner = Color(255,0,0,255),
        superadmin = Color(0,255,255,255),
        admin = Color(0,255,0,255),
        moderator = Color(0,255,255,255),
        faggot = Color(253,215,228,255),
        user = Color(255,250,250,255),
        trusted = Color(173,216,230,255),
        jr-mod = Color(173,216,230,255),
        donator = Color(173,216,230,255),
        coowner = Color(173,216,230,255),
        sid = Color(255,215,0,255),
        donatorplus = Color(173,216,230,255),
        superdonator = Color(173,216,230,255),
        lua = Color(173,216,230,255),
        supermod = Color(173,216,230,255)
};
 
function GM:TTTScoreboardColorForPlayer(ply)
   if not IsValid(ply) then return namecolor.default 
end
 
        if ply:IsUserGroup("owner") then
                return namecolor.owner
        elseif ply:IsUserGroup("coowner") then
                return namecolor.coowner
        elseif ply:IsUserGroup("superadmin") then
                return namecolor.superadmin
        elseif ply:IsUserGroup("faggot") then
                return namecolor.faggot
        elseif ply:IsUserGroup("admin") then
                return namecolor.admin
        elseif ply:IsUserGroup("moderator") then
                return namecolor.moderator
        elseif ply:IsUserGroup("member") then
                return namecolor.member
        elseif ply:IsUserGroup("user") then
                return namecolor.user
        elseif ply:IsUserGroup("trusted") then
                return namecolor.trusted
        elseif ply:IsUserGroup("jrmod") then
                return namecolor.jrmod
        elseif ply:IsUserGroup("donator") then
                return namecolor.donator
        elseif ply:IsUserGroup("donatorplus") then
                return namecolor.donatorplus
        elseif ply:IsUserGroup("superdonator") then
                return namecolor.superdonator
        elseif ply:IsUserGroup("supermod") then
                return namecolor.supermod
        elseif ply:IsUserGroup("lua") then
                return namecolor.lua
 
   end
   return namecolor.default
end

I would be very happy if any of you could tell me what I did wrong and why this piece of code doesn’t work.

set this in LUA tags

In the future please put




tags around your code, it helps a lot visually.

Your issue is the line that says jr-mod = Color(173,216,230,255). The name is causing an issue because - is used for math. If you remove that line you shouldn’t get that error.
I recommend using jr_mod instead.

Sorry, I’m pretty new :slight_smile:
Have edited the post and tagged the code

[editline]13th July 2013[/editline]

Thank you that stopped the error, but now it crashes spamming:


TTTScoreboardColorForPlayer hook returned something that isn't a color!
TTTScoreboardColorForPlayer hook returned something that isn't a color!
TTTScoreboardColorForPlayer hook returned something that isn't a color!
TTTScoreboardColorForPlayer hook returned something that isn't a color!
TTTScoreboardColorForPlayer hook returned something that isn't a color!
TTTScoreboardColorForPlayer hook returned something that isn't a color!
TTTScoreboardColorForPlayer hook returned something that isn't a color!
TTTScoreboardColorForPlayer hook returned something that isn't a color!
TTTScoreboardColorForPlayer hook returned something that isn't a color!
TTTScoreboardColorForPlayer hook returned something that isn't a color!
TTTScoreboardColorForPlayer hook returned something that isn't a color!
TTTScoreboardColorForPlayer hook returned something that isn't a color!
TTTScoreboardColorForPlayer hook returned something that isn't a color!
TTTScoreboardColorForPlayer hook returned something that isn't a color!
TTTScoreboardColorForPlayer hook returned something that isn't a color!
TTTScoreboardColorForPlayer hook returned something that isn't a color!
TTTScoreboardColorForPlayer hook returned something that isn't a color!
TTTScoreboardColorForPlayer hook returned something that isn't a color!
TTTScoreboardColorForPlayer hook returned something that isn't a color!
TTTScoreboardColorForPlayer hook returned something that isn't a color!
Disconnect: "Too many Lua Errors! Sorry!".
Disconnect: "Too many Lua Errors! Sorry!". 

I think your rgb color code is to long i think its supposed to have 3 variables like this-- (0,0,0) Not to sure though

This is a much better way to do this. Your basically making a switch out of the group name. So indexing colors on a table by group name would seem to be a better option. Also the alpha channel on the return color is ignored, so it is irrelevant, but you can change that yourself.

[lua]
local namecolor = {
default = COLOR_WHITE,
[“owner”] = Color(255,0,0,255),
[“superadmin”] = Color(0,255,255,255),
[“admin”] = Color(0,255,0,255),
[“moderator”] = Color(0,255,255,255),
[“faggot”] = Color(253,215,228,255),
[“user”] = Color(255,250,250,255),
[“trusted”] = Color(173,216,230,255),
[“jr-mod”] = Color(173,216,230,255),
[“donator”] = Color(173,216,230,255),
[“coowner”] = Color(173,216,230,255),
[“sid”] = Color(255,215,0,255),
[“donatorplus”] = Color(173,216,230,255),
[“superdonator”] = Color(173,216,230,255),
[“lua”] = Color(173,216,230,255),
[“supermod”] = Color(173,216,230,255)
}

local function getCustomColor(ply)
if (not IsValid(ply)) then return namecolor.default end
return namecolor[ply:GetUserGroup()] or namecolor.default
end
return namecolor.default
end
hook.Add(“TTTScoreboardColorForPlayer”, “Custom Colors”, getCustomColor)
[/lua]

Your hook was also broken.

No, its right. Its Red, Green, Blue, Alpha. Alpha is used to determine if something is see through.

My Best guess at that error is that you don’t have COLOR_WHITE set to anything. It’s just a variable so until you assign it to something its nil. Just replace COLOR_WHITE with Color(255, 255, 255, 255).

If that doesn’t fix it then post back.

Thank you all so much!
I finally figured out the errors and all your quick answers and tips helped me a lot.

If a moderator reads this please lock the thread.

I hope you realize that only works if he uses ULX…

You can close the thread yourself. Just mark it as closed