I'm pretty sure LUA can't fix this, because I attempted to do a client-side refresh and it didn't work in fixing my issue.
The issue is that sometimes in-game rather than displaying a rank where I coded in the ranks, it instead just displays, "Rank". The users in those spots are in groups that already have ranks in the code. This is Trouble in Terrorist Town.
[url]http://puu.sh/gxMY0/9013a85246.jpg[/url]
Lines 228-313 are where the ranks are set.
[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
self.cols[5] = vgui.Create("DLabel", self)
self.cols[5]:SetText("Rank")
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.kills = vgui.Create("DLabel", self)
self.kills:SetText("")
self.kills: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" )
TraitorKills_Add( self )
end
local namecolor = {
default = COLOR_WHITE,
admin = Color(220, 180, 0, 255)
};
//namecolors
function GM:TTTScoreboardColorForPlayer(ply)
if not IsValid(ply) then return namecolor.default end
if ply:IsUserGroup("ownerno") then
return rainbow()
elseif ply:IsUserGroup("devno") then
return Color(249,245,138)
elseif ply:IsUserGroup("servermanagerno") then
return Color(157,112,162)
elseif ply:IsUserGroup("staffchiefno") then
return Color(232,66,66)
end
return namecolor.default
end
local function rainbow()
local frequency, time = .5, RealTime()
local red = math.sin( frequency * time ) * 127 + 128
local green = math.sin( frequency * time + 2 ) * 127 + 128
local blue = math.sin( frequency * time + 4 ) * 127 + 128
return Color( red, green, blue )
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))
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.kills:SizeToContents()
self.kills:SetPos(SB_ROW_HEIGHT + self.nick:GetWide() + 15, (SB_ROW_HEIGHT - self.kills:GetTall()) / 2)
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
if ply:IsUserGroup("user") then
self.cols[5]:SetText("Guest ")
self.cols[5]:SetTextColor(Color(178, 255, 102))
elseif ply:IsUserGroup("regular") then
self.cols[5]:SetText("Regular ")
self.cols[5]:SetTextColor(Color(102, 204, 0))
elseif ply:IsUserGroup("superadmin") then
self.cols[5]:SetText("Super Admin ")
self.cols[5]:SetTextColor(Color(255, 188, 0))
elseif ply:IsUserGroup("dev") then
self.cols[5]:SetText("Developer ")
self.cols[5]:SetTextColor(Color(255, 250, 77))
elseif ply:IsUserGroup("permaguest") then
self.cols[5]:SetText("Perma-Guest ")
self.cols[5]:SetTextColor(Color(178, 255, 102))
elseif ply:IsUserGroup("moderator") then
self.cols[5]:SetText("Mod ")
self.cols[5]:SetTextColor(Color(141, 255, 255))
elseif ply:IsUserGroup("boulousrank") then
self.cols[5]:SetText("Trusted ")
self.cols[5]:SetTextColor(Color(99, 174, 174))
elseif ply:IsUserGroup("donatormod") then
self.cols[5]:SetText("Mod ")
self.cols[5]:SetTextColor(Color(141, 255, 255))
elseif ply:IsUserGroup("donatormod+") then
What rank is the player having the issue?
[QUOTE=T. Sparkle;47312831]What rank is the player having the issue?[/QUOTE]
It is not a specific rank, I notice it happens when someone joins after you have joined.
if you just want to hide it, you can change line 35 to SetText("")
to fix it, it looks like you need to call UpdatePlayerData more often
I recommend using something like this: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_utilities/concommand_clearvgui.lua[/url]
in addons/acecool/lua/client/concommand_clearvgui.lua then use by typing clearvgui in console to remove all vgui elements. Make sure the open code creates a new one if it doesn't already exist. Then you shouldn't have any issues refreshing vgui elements ( the reason they may not be updating is likely caused by the gm creating it once and never again ).
Instead of hard-coding all of the ranks using a large if / elseif tree, use a table; something like these examples:
_p:GetUserGroupInfo( ) system ( which you can extend if you want to return more info.. Then you can remove .name from return so local _info = _p:GetUserGroupInfo( ); then you can use _info.name, _info.color, or whatever you want to add ) -- To add more names, use all lower-case group name. If there are spaces, use [ "group name" ] = { name = "", ... }; -- This will let you remove the huge if elseif tree and it'll execute faster, look cleaner, and be easier to add new groups...
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/player/player_rank_name.lua.html[/url]
Chat Tags:
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/chat_tags/chat_tags_example.lua.html[/url]
[ NOTE ] Remove .html to view / copy .Lua ... Hopefully this helps.
[QUOTE=PortalGod;47312858]if you just want to hide it, you can change line 35 to SetText("")
to fix it, it looks like you need to call UpdatePlayerData more often[/QUOTE]
How could I create a loop to update the PlayerData say once every 10 seconds? Would that slow down the server?
Instead of creating too many ifelse statements, why not create a table?
A basic example (WILL NOT WORK):
[CODE]ranksandwords{}
ranksandwords[1]{"usergroupnamehere", "textyouwanthere", Color(r,g,b,a)}
for k,v in pairs(ranksandwords) do
for o,i in pairs(player.GetAll()) do
if i:GetUserGroup() == v[1] then
self.cols[5]:SetText(v[2])
self.cols[5]:SetTextColor(v[3])
end
end
end
[/CODE]
[QUOTE=nikorev;47317416]Instead of creating too many ifelse statements, why not create a table?
A basic example (WILL NOT WORK):
[CODE]ranksandwords{}
ranksandwords[1]{"usergroupnamehere", "textyouwanthere", Color(r,g,b,a)}
for k,v in pairs(ranksandwords) do
for o,i in pairs(player.GetAll()) do
if i:GetUserGroup() == v[1] then
self.cols[5]:SetText(v[2])
self.cols[5]:SetTextColor(v[3])
end
end
end
[/CODE][/QUOTE]
that's probably worse than the way he was doing
[lua]
ranks["usergroupnamehere"] = {"something", Color()};
...
local rank = ranks[ply:GetUserGroup()];
[/lua]
[QUOTE=Frubbs;47321491]This:
[CODE] ranks["user"] = {"Guest", Color(178, 255, 102)};
ranks["regular"] = {"Regular", Color(102, 204, 0)};
ranks["veteran"] = {"Veteran", Color(60, 128, 0)};
ranks["trusted"] = {"Trusted", Color(99, 174, 174)};
ranks["moderator"] = {"Mod", Color(141, 255, 255)};
ranks["donatormod"] = {"Mod", Color(141, 255, 255)};
ranks["donatormod+"] = {"Mod", Color(141, 255, 255)};
ranks["donatormod++"] = {"Mod", Color(141, 255, 255)};
ranks["admin"] = {"Admin", Color(253, 118, 0)};
ranks["donatoradmin"] = {"Admin", Color(253, 118, 0)};
ranks["donatoradmin+"] = {"Admin", Color(253, 118, 0)};
ranks["donatoradmin++"] = {"Admin", Color(253, 118, 0)};
ranks["donator"] = {"Donator", Color(255, 250, 77)};
ranks["donator+"] = {"Donator+", Color(68,118,255)};
ranks["donator++"] = {"Donator++", Color(rainbow())};
ranks["superadmin"] = {"Super Admin", Color(255, 188, 0)};
ranks["owner"] = {"Owner", Color(rainbow())};
ranks["staffchief"] = {"", Color()};
ranks["servermanager"] = {"Manager", Color(129,77,135)};
ranks["dev"] = {"Developer", Color(255, 250, 77)};
local rank = ranks[ply:GetUserGround()];[/CODE]
Resulted in this error:
[CODE][ERROR] gamemodes/terrortown/gamemode/vgui/sb_row.lua:230: attempt to index global 'ranks' (a nil value)
1. UpdatePlayerData - gamemodes/terrortown/gamemode/vgui/sb_row.lua:230
2. SetPlayer - gamemodes/terrortown/gamemode/vgui/sb_row.lua:177
3. AddPlayerRow - gamemodes/terrortown/gamemode/vgui/sb_team.lua:97
4. UpdateScoreboard - gamemodes/terrortown/gamemode/vgui/sb_main.lua:283
5. Init - gamemodes/terrortown/gamemode/vgui/sb_main.lua:136
6. Create - lua/includes/extensions/client/panel/scriptedpanels.lua:153
7. ScoreboardCreate - gamemodes/terrortown/gamemode/cl_scoreboard.lua:27
8. unknown - gamemodes/terrortown/gamemode/cl_scoreboard.lua:34
[/CODE][/QUOTE]
put
local ranks = {}
at the top of the file
also change GetUserGround to GetUserGroup
i have no idea why i typed that wrong
[QUOTE=MeepDarknessM;47321502]put
local ranks = {}
at the top of the file
also change GetUserGround to GetUserGroup
i have no idea why i typed that wrong[/QUOTE]
[CODE]local rank = ranks[ply:GetUserGroup()];
ranks["user"] = {"Guest", Color(178, 255, 102)};
ranks["regular"] = {"Regular", Color(102, 204, 0)};
ranks["veteran"] = {"Veteran", Color(60, 128, 0)};
ranks["trusted"] = {"Trusted", Color(99, 174, 174)};
ranks["moderator"] = {"Mod", Color(141, 255, 255)};
ranks["donatormod"] = {"Mod", Color(141, 255, 255)};
ranks["donatormod+"] = {"Mod", Color(141, 255, 255)};
ranks["donatormod++"] = {"Mod", Color(141, 255, 255)};
ranks["admin"] = {"Admin", Color(253, 118, 0)};
ranks["donatoradmin"] = {"Admin", Color(253, 118, 0)};
ranks["donatoradmin+"] = {"Admin", Color(253, 118, 0)};
ranks["donatoradmin++"] = {"Admin", Color(253, 118, 0)};
ranks["donator"] = {"Donator", Color(255, 250, 77)};
ranks["donator+"] = {"Donator+", Color(68,118,255)};
ranks["donator++"] = {"Donator++", Color(rainbow())};
ranks["superadmin"] = {"Super Admin", Color(255, 188, 0)};
ranks["owner"] = {"Owner", Color(rainbow())};
ranks["staffchief"] = {"", Color()};
ranks["servermanager"] = {"Manager", Color(129,77,135)};
ranks["dev"] = {"Developer", Color(255, 250, 77)};[/CODE]
At the top of the file resulted in this error:
[CODE]
[ERROR] gamemodes/terrortown/gamemode/vgui/sb_team.lua:97: attempt to index local 'row' (a nil value)
1. AddPlayerRow - gamemodes/terrortown/gamemode/vgui/sb_team.lua:97
2. UpdateScoreboard - gamemodes/terrortown/gamemode/vgui/sb_main.lua:283
3. Init - gamemodes/terrortown/gamemode/vgui/sb_main.lua:136
4. Create - lua/includes/extensions/client/panel/scriptedpanels.lua:153
5. ScoreboardCreate - gamemodes/terrortown/gamemode/cl_scoreboard.lua:27
6. unknown - gamemodes/terrortown/gamemode/cl_scoreboard.lua:34
[/CODE]
Can you post the whole updated code again?
[QUOTE=code_gs;47321690]Can you post the whole updated code again?[/QUOTE]
[QUOTE=code_gs;47321690]Can you post the whole updated code again?[/QUOTE]
[CODE]
---- Scoreboard player score row, based on sandbox version
include("sb_info.lua")
local rank = ranks[ply:GetUserGroup()];
ranks["user"] = {"Guest", Color(178, 255, 102)};
ranks["regular"] = {"Regular", Color(102, 204, 0)};
ranks["veteran"] = {"Veteran", Color(60, 128, 0)};
ranks["trusted"] = {"Trusted", Color(99, 174, 174)};
ranks["moderator"] = {"Mod", Color(141, 255, 255)};
ranks["donatormod"] = {"Mod", Color(141, 255, 255)};
ranks["donatormod+"] = {"Mod", Color(141, 255, 255)};
ranks["donatormod++"] = {"Mod", Color(141, 255, 255)};
ranks["admin"] = {"Admin", Color(253, 118, 0)};
ranks["donatoradmin"] = {"Admin", Color(253, 118, 0)};
ranks["donatoradmin+"] = {"Admin", Color(253, 118, 0)};
ranks["donatoradmin++"] = {"Admin", Color(253, 118, 0)};
ranks["donator"] = {"Donator", Color(255, 250, 77)};
ranks["donator+"] = {"Donator+", Color(68,118,255)};
ranks["donator++"] = {"Donator++", Color(rainbow())};
ranks["superadmin"] = {"Super Admin", Color(255, 188, 0)};
ranks["owner"] = {"Owner", Color(rainbow())};
ranks["staffchief"] = {"", Color()};
ranks["servermanager"] = {"Manager", Color(129,77,135)};
ranks["dev"] = {"Developer", Color(255, 250, 77)};
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
self.cols[5] = vgui.Create("DLabel", self)
self.cols[5]:SetText(" ")
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.kills = vgui.Create("DLabel", self)
self.kills:SetText("")
self.kills: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" )
TraitorKills_Add( self )
end
local function rainbow()
local frequency, time = .5, RealTime()
local red = math.sin( frequency * time ) * 127 + 128
local green = math.sin( frequency * time + 2 ) * 127 + 128
local blue = math.sin( frequency * time + 4 ) * 127 + 128
return Color( red, green, blue )
end
local namecolor = {
default = COLOR_WHITE,
admin = Color(220, 180, 0, 255)
};
//namecolors
function GM:TTTScoreboardColorForPlayer(ply)
if not IsValid(ply) then return namecolor.default end
if ply:IsUserGroup("ownerno") then
return rainbow()
elseif ply:IsUserGroup("devno") then
return Color(249,245,138)
elseif ply:IsUserGroup("servermanagerno") then
return Color(157,112,162)
elseif ply:IsUserGroup("staffchiefno") then
return Color(232,66,66)
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))
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.kills:SizeToContents()
self.kills:SetPos(SB_ROW_HEIGHT + self.nick:GetWide() + 15, (SB_ROW_HEIGHT - self.kills:GetTall()) / 2)
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
--[[ if ply:IsUserGroup("user") then
self.cols[5]:SetText("Guest ")
self.cols[5]:SetTextColor(Color(178, 255, 102))
elseif ply:IsUserGroup("regular") then
self.cols[5]:SetText("Regular ")
self.cols[5]:SetTextColor(Color(102, 204, 0))
elseif ply:IsUserGroup("superadmin") then
self.cols[5]:SetText("Super Admin ")
self.cols[5]:SetTextColor(Color(255, 188, 0))
elseif ply:IsUserGroup("dev") then
self.cols[5]:SetText("Developer
That error isn't related to the code, but you do have a few issues:
[code]ranks["staffchief"] = {"", Color()};[/code]
Empty string, empty color.
[code] ranks["owner"] = {"Owner", Color(rainbow())};[/code]
Is rainbow a defined function?
[QUOTE=code_gs;47322494]That error isn't related to the code, but you do have a few issues:
[code]ranks["staffchief"] = {"", Color()};[/code]
Empty string, empty color.
[code] ranks["owner"] = {"Owner", Color(rainbow())};[/code]
Is rainbow a defined function?[/QUOTE]
Rainbow is a defined function, I removed it from the code so it couldn't be copied. A friend coded the function for me.
Note, first link is to view on web, second link if you copy / paste or save.
If you used my example:
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/player/player_rank_name.lua.html[/url] - [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/player/player_rank_name.lua[/url]
you could add [code]color = Color( ); [/code] for each rank... It'd be in a clean and easy to read list. If any ranks have spaces or special chars, you'd follow the instructions ( also in the example )..
It also has helper functions... So: _p:UserGroupData( ); returns the table for the group the user is in, or it uses default if the group doesn't exist in the table...
_p:UserGroupName( ); gets you a friendly name and _p:UserGroupColor( ); gets you a color.
Or, combined:
[code]local _name, _color = _p:UserGroupNameColor( );[/code] -- gives you both name and color in the form of a delimited return.
[code]local _level = _p:UserGroupLevel( );[/code] -- gets you the user-level ( if you want it, uncomment level from each table )
So, your table would be:
[url]https://dl.dropboxusercontent.com/u/26074909/tutoring/player/player_rank_name_example.lua.html[/url] - [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/player/player_rank_name_example.lua[/url]
dropped into addons/addon_name/lua/autorun/sh_player_rank_helper_functions.lua
And you'd only need to use the helper-function in the scoreboard like: [code]local name, color = ply:UserGroupNameColor( );[/code] -- and you'd then use name where the rank-name goes, and color where the rank color goes. It'll use default if not found, or it'll use the rank specified.
Sure, the table could be compressed into 1 line each, which looks like: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/player/player_rank_name_example2.lua.html[/url] - [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/player/player_rank_name_example2.lua[/url] ( I prefer using names as keys and lining them up...
and it can be shortened even further by making the ranks that are duplicated with different names by creating aliases after the initial table was created which looks like this: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/player/player_rank_name_example3.lua.html[/url] - [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/player/player_rank_name_example3.lua[/url]
Now, your issue is because you're trying to get a player rank [B]OUTSIDE [/B]of the row for the player... You need to get the rank [B]inside Init[/B] ( if that is part of the player row code ) because you're otherwise trying to populate rank when the client loads the script instead of when the scoreboard row initializes with each player passed in...
You're also not using ranks = { }; prior to defining each element to the table.
You're also trying to use: local rank = ranks[ply:GetUserGroup()]; -- before the table is populated ( needs to be in init or the function where you set the player to the row )
Sorry, you need to Log In to post a reply to this thread.