Hello Fellow FacePunch users. So today i was trying to add in a code i use to have, but when i did it, it just errored out. The code is this in sb_row:
[code] if ply:IsUserGroup("owner") then
self.cols[5]:SetText("Owner")
self.cols[5]:SetTextColor(Color(0, 0, 255, 255))
end
if ply:IsUserGroup("superadmin") then
self.cols[5]:SetText("Vice Pres.")
self.cols[5]:SetTextColor(Color(0, 255, 130, 255))
end
if ply:IsUserGroup("manager") then
self.cols[5]:SetText("Manager")
self.cols[5]:SetTextColor(Color(0, 255, 255, 255))
end
if ply:IsUserGroup("ps_admin") or ply:IsUserGroup("ps_admin") then
self.cols[5]:SetText("Admin")
self.cols[5]:SetTextColor(Color(255, 100, 5, 255))
end
if ply:IsUserGroup("moderator") or ply:IsUserGroup("ps_moderator") then
self.cols[5]:SetText("Moderator")
self.cols[5]:SetTextColor(Color(255, 160, 5, 255))
end
if ply:IsUserGroup("operator") or ply:IsUserGroup("ps_operator") then
self.cols[5]:SetText("Operator")
self.cols[5]:SetTextColor(Color(255, 245, 5, 255))
end
if ply:IsUserGroup("clan_member") then
self.cols[5]:SetText("Member")
self.cols[5]:SetTextColor(Color(255, 0, 0, 255))
end
if ply:IsUserGroup("ps_member") then
self.cols[5]:SetText("VIP Member")
self.cols[5]:SetTextColor(Color(255, 0, 0, 255))
end
if ply:IsUserGroup("vip") then
self.cols[5]:SetText("VIP")
self.cols[5]:SetTextColor(Color(30, 255, 5, 255))
end
if ply:IsUserGroup("regular") then
self.cols[5]:SetText("Regular")
self.cols[5]:SetTextColor(Color(255, 255, 255, 255))
end
if ply:IsUserGroup("user") then
self.cols[5]:SetText("")
self.cols[5]:SetTextColor(Color(255, 255, 255, 255))
end
if ply:IsUserGroup("watchlist") then
self.cols[5]:SetText("Watch List")
self.cols[5]:SetTextColor(Color(255, 0, 255, 255))
end[/code]
So then i looked through the code, and saw that the method i was using to put it on a column was obsolete. I saw it uses this now:
[Code] self:AddColumn( GetTranslation("sb_score"), function(ply) return ply:Frags() end )[/code]
Can someone help me implement this into the new scoreboard code?
Thanks
Also please don't link me to something similar or the same, I like the code the way I have it, I don't want someone else's code.
-bump-
You say not to link you to another players code, but this script may help you get a better understanding. [url]https://github.com/rejax/TTT-EasyScoreboard[/url]
Although some important hooks to use are listed here.
[url]http://ttt.badking.net/guides/hooks[/url]
[quote]TTTScoreboardColorForPlayer (ply)
Client
Called to determine what colour a player's name should be on the scoreboard. Hence, it must return a Color object, or return nil (or nothing at all). The "ply" parameter contains a player object, so you can for example check the player's SteamID and give certain people a special colour. Note that TTT also uses this hook for the default colours, so you should return nil for players that you do not want to do anything special with.
TTTScoreboardColumns (pnl)
Client
Called when the scoreboard is initialized. Additional custom columns can be added by calling "pnl:AddColumn(heading, func)", where "pnl" is the panel passed to this hook as an argument, "label" is your column heading text, and "func" is a function you define that will be called to get up-to-date text for the column. The function is called for each row as "func(ply, label)", where "ply" is the player on that row and "label" is the DLabel object (which can be used to set text colour).
For example, to show user IDs on the scoreboard, you would do the following in this hook:
pnl:AddColumn("ID", function(ply) return ply:UserID() end)
TTTScoreboardMenu (menu)
Client
Called to show a context menu when the player right-clicks a player in the scoreboard. The "menu" parameter is a DermaMenu that you can add options to that the player can click. By default there is no context menu when right clicking, it will only appear if you add options in this hook.[/quote]
If you're wanting to use an unnecessary amount of lines you can do it your way by having a for loop and a table, but your way still works. Also you could use if/elseif/else instead a bunch of if statements that way it will ignore the rest of the options.
I quickly typed this up for an idea. Very straight forward.
[lua]
hook.Add( "TTTScoreboardColumns", function( pnl )
local ugroup = string.lower(ply:GetUserGroup())
local title
if ugroup == "owner" then title = "Owner"
elseif ugroup == "superadmin" then title = "Vice Pres."
elseif ugroup == "manager" then title = "Manager"
elseif ugroup == "admin" or ugroup == "ps_admin" then title = "Admin"
elseif ugroup == "moderator" or ugroup == "ps_moderator" then title = "Moderator"
else title = "User" end
pnl:AddColumn("Rank", title)
end)[/lua]
You could just always use an old copy of sb_row and sb_main if you really wanted to keep using the old way.
Please do not do a lot of if/elseif statements, they're ugly as all can be. Create a table and check if the players group is in that, then use the data from it.
[QUOTE=Tobiasx;45255784]Also please don't link me to something similar or the same, [B]I like the code the way I have it[/B], I don't want someone else's code.[/QUOTE]
[QUOTE=SaintSin6;45258413]You say not to link you to another players code, but this script may help you get a better understanding. [url]https://github.com/rejax/TTT-EasyScoreboard[/url]
If you're wanting to use an unnecessary amount of lines you can do it your way [B]by having a for loop and a table[/B],[B] but your way still works[/B]. Also you could use if/elseif/else instead a bunch of if statements that way it will ignore the rest of the options.
[/QUOTE]
He said he wanted to keep the code "his way" so I left the if statements for him. I suggested using a table and he can learn to write that himself if he wanted to.
Sorry, you need to Log In to post a reply to this thread.