Chat Prefix

Hello, I’ve got a code to out the players rank next to their name in chat, but instead it just says terrorist or spectator?


  function insertChatTags(ply, msg)
            if ply:IsValid() then
                    local ply_team = ply:Team()
                    local team_name = team.GetName( ply_team )
                   
                    --local h,s,v = ColorToHSV( team.GetColor( ply_team ) )
                    --local comp_col = HSVToColor( 180-h, s, v )
                   
                   
                    --PHX-Server specifics
                    if ( team_name == "Owner" ) then
                            comp_col = Color(255,255,255)
                    elseif ( team_name == "Co-Owner" ) then
                            comp_col = Color(255,255,255)        
                    elseif ( team_name == "SuperAdmin" ) then
                            comp_col = Color(255,255,255)
                    elseif ( team_name == "Admin" ) then   
                            comp_col = Color(255,255,255)
                    elseif ( team_name == "Donator" ) then
                            comp_col = Color(255,255,255)
                    elseif ( team_name == "Trusted" ) then 
                            comp_col = Color(255,255,255)
                    elseif ( team_name == "user" ) then    
                            comp_col = Color(255,255,255)
                            team_name = "Guest"
				    elseif ( team_name == "Member" ) then    
                            comp_col = Color(255,255,255)
                            team_name = "Member"
				    elseif ( team_name == "Trusted" ) then    
                            comp_col = Color(255,255,255)
                            team_name = "Trusted"
                    else
                            comp_col = Color(255, 255, 255)
                    end
                   
                   
                    chat.AddText( team.GetColor( ply_team ), "[",comp_col, team_name,team.GetColor( ply_team ), "] ", ply:GetName(), color_white, ": ", msg )
                    return true
            end
    end
     
    hook.Add( "OnPlayerChat", "ulx_chattags", insertChatTags )


Why is it not working?

Also this is code from a plugin, and I have no knowledge of LUA, so there’s probably a lot of things wrong in here.

Original Plugin: http://www.garrysmod.org/downloads/?a=view&id=129161

Thanks in advanced.

because ranks aren’t set up as teams, if you’re using ULX it would be ply:IsUserGroup(“superadmin”)

That code is doing exactly what its supposed to. When you use ply:Team() it gets there team. Thats what it means. You probably want ply:IsUserGroup( “Owner” ) or whatever.

I’m still extremely bad at code, what part of the code do I actually need to change? Where it says


elseif ( team_name == "Donator" ) then

Or


local ply_team = ply:Team()
                    local team_name = team.GetName( ply_team )

All of it. You don’t want to use ply_team. You want ply:IsUsergroup, sub it out accordingly.

I made him a script.

Could I get a script for this as well, I’m having the same issue