chat tags(corresponding with ULX)

I’ve been trying o get chat tags on my server but since gmod 13 updated none that i have found worked besides one that colored the whole name and disabled all commands(EX:/ooc)

I have also found this one which has no errors but it says the players team
(EX:[DS] SaintlyDemonic: y
[S.W.A.T Leader] [DS] SaintlyDemonic: y)
Notice it copies the players chat x2
[lua]
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 == "SAdmin" ) 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"
                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 )

[/lua]

FYI:This file is called "chat tags.lua placed in “Addons/ULX/lua/ulx/modules/cl”

[editline]4th December 2012[/editline]

Also this is the one that works completely besides it disables all rp commands.
This goes in the autorun folder.
This will color the whole name and disable rp commands.
[lua]
– v5
– for yellowish white = 238, 221, 130

if (SERVER) then
AddCSLuaFile( “chat.lua” )
local Tag = “”
local R = 0
local G = 0
local B = 0

function CustomChat_ChatMessage( name, String, bool, R, G, B) – ChatMessage(rgb, name, rgb2, String)
umsg.Start( “CustomChat_ChatMsg” )
umsg.String(name)
umsg.String(String)
umsg.String(bool)
umsg.Long®
umsg.Long(G)
umsg.Long(B)
umsg.End()
end

concommand.Add( “chat_alert”, function( ply, cmd, args )

if args[1] then // We're seeing if there are any arguments, arguments are stored on a table, so you will have to use args[index].
	if ply:IsAdmin() then 
	CustomChat_ChatMessage( "ALERT", "> "..string.gsub(args[1], "_", " "), "" , 255, 0, 0)
	else
	ply:PrintMessage(HUD_PRINTCONSOLE,"You are not Admin")
	Msg("--Player "..ply:Nick().." is not admin and tryed to use alert chat.

")
end
end
end )

function CustomChat_Checker( ply, text, teamonly )
–/*
if ply:IsUserGroup(“mod”) then
Tag = “[Mod]”
R = 0
G = 206
B = 209
elseif ply:IsUserGroup(“vip”) then
Tag = “[Vip]”
R = 0
G = 0
B = 255
elseif ply:IsSuperAdmin() then
Tag = “[SuperAdmin]”
R = 255
G = 0
B = 0
elseif ply:IsAdmin() then
Tag = “[Admin]”
R = 255
G = 0
B = 0
else
Tag = “[User]”
R = 238
G = 221
B = 130
end
/
/

if ply:IsSuperAdmin() then
Tag = “[Admin]”
R = 255
G = 0
B = 0
elseif ply:IsAdmin() then
Tag = “[Mod]”
R = 0
G = 206
B = 209
elseif ply:IsUserGroup(“vip”) then
Tag = “[Vip]”
R = 0
G = 0
B = 255
else
Tag = “[User]”
R = 238
G = 221
B = 130
end
*/
CustomChat_ChatMessage(ply:Nick(), "> "…text, Tag, R, G, B)
return “”
end
hook.Add(“PlayerSay”, “WordCheck”, CustomChat_Checker)

else --- client code				--

usermessage.Hook(“CustomChat_ChatMsg”, function( um, ply )
local name = um:ReadString()
local String = um:ReadString()
local Tag = um:ReadString()
local R = um:ReadLong()
local G = um:ReadLong()
local B = um:ReadLong()
chat.AddText(Color(R, G, B, 255), Tag…name, Color(255, 255, 255, 255), String)
end)
end-- final end

– Admin > flamedog: words
– SAdmin > flamedog: words
– Console > words
[/lua]

So… What exactly do you want help with?

I want it so that the jobs color projects to the players name and the users group too go before his/her name with the specified color.
The 2nd one posted works fine its just that it projects the groups color to the players name as well

Ex:[rank+ranks color] (Players name+Job color): Message

[lua]
– v5
– for yellowish white = 238, 221, 130

if (SERVER) then
AddCSLuaFile( “chat.lua” )
local Tag = “”
local R = 0
local G = 0
local B = 0

function CustomChat_ChatMessage( player, String, bool, R, G, B) – ChatMessage(rgb, name, rgb2, String)
umsg.Start( “CustomChat_ChatMsg” )
umsg.Entity(Player) --no idea if this si right
umsg.String(String)
umsg.String(bool)
umsg.Long®
umsg.Long(G)
umsg.Long(B)
umsg.End()
end

concommand.Add( “chat_alert”, function( ply, cmd, args )

if args[1] then // We're seeing if there are any arguments, arguments are stored on a table, so you will have to use args[index].
    if ply:IsAdmin() then
    CustomChat_ChatMessage( "ALERT", "> "..string.gsub(args[1], "_", " "), "" , 255, 0, 0)
    else
    ply:PrintMessage(HUD_PRINTCONSOLE,"You are not Admin")
    Msg("--Player "..ply:Nick().." is not admin and tryed to use alert chat.

")
end
end
end )

function CustomChat_Checker( ply, text, teamonly )
–/*
if ply:IsUserGroup(“mod”) then
Tag = “[Mod]”
R = 0
G = 206
B = 209
elseif ply:IsUserGroup(“vip”) then
Tag = “[Vip]”
R = 0
G = 0
B = 255
elseif ply:IsSuperAdmin() then
Tag = “[SuperAdmin]”
R = 255
G = 0
B = 0
elseif ply:IsAdmin() then
Tag = “[Admin]”
R = 255
G = 0
B = 0
else
Tag = “[User]”
R = 238
G = 221
B = 130
end
/
/

if ply:IsSuperAdmin() then
Tag = “[Admin]”
R = 255
G = 0
B = 0
elseif ply:IsAdmin() then
Tag = “[Mod]”
R = 0
G = 206
B = 209
elseif ply:IsUserGroup(“vip”) then
Tag = “[Vip]”
R = 0
G = 0
B = 255
else
Tag = “[User]”
R = 238
G = 221
B = 130
end
*/
CustomChat_ChatMessage(ply, "> "…text, Tag, R, G, B) --Rplaced ply:Nick() with ply
return “”
end
hook.Add(“PlayerSay”, “WordCheck”, CustomChat_Checker)

else --- client code                --

usermessage.Hook(“CustomChat_ChatMsg”, function( um, ply )
local player = um:ReadEntity() --changed
local String = um:ReadString()
local Tag = um:ReadString()
local R = um:ReadLong()
local G = um:ReadLong()
local B = um:ReadLong()
chat.AddText(Color(R, G, B, 255), Tag, Color(255,255,255), “(”,team.GetColor( ply:Team() ), Color(255, 255, 255, 255), “)”…String) --changed
end)
end-- final end

– Admin > flamedog: words
– SAdmin > flamedog: words
– Console > words
[/lua]
Going on the assumption that the original code works, this should too (although I’m not sure about my ussermessge thing [but this should be re-written to the net library anyways]).

I tryed but it didnt work it gave me this error

"
[ERROR] lua/autorun/chats.lua:101: attempt to index local ‘ply’ (a nil value)

  1. Function - lua/autorun/chats.lua:101
  2. unknown - lua/includes/modules/usermessage.lua:87
    "

-snip- Go towards the bottom of the page>>>

THANK YOU SOOOO MUTCH BRANDON =) Thanks for trying to help sabreman. I appreciate it both of you.
Brandon would you mind giving me your steam name so if i have any questions?

Yeah sure, here’s my Steam.

Wait i just ran some quick tests it dosnt work fully. It disables ALL Rp commands suh as becoming a job

[editline]4th December 2012[/editline]

I thought someone finally made 1 work after 2 days ive been looking for this… i was wrong :frowning:

That’s because it returns “”.

I added you , but can you tell me how too fix it so that it wont disable the rp commands?

Fixed up:
[lua]
local ranks = {
[“superadmin”] = Color(255,0,0),
[“admin”] = Color(255,0,0),
[“mod”] = Color(0,206,209),
[“vip”] = Color(0,0,255),
[“user”] = Color(238,221,130)
}

if (SERVER) then
AddCSLuaFile(“chat.lua”)

function CustomChat_ChatMessage(ply, msg, rank, r, g, b)
	umsg.Start("CustomChat_ChatMsg")
		umsg.Entity(ply)
		umsg.String(msg)
		umsg.String(rank)
		umsg.Short(r)
		umsg.Short(g)
		umsg.Short(b)
	umsg.End()
end

function CustomChat_Checker(ply, text, teamonly)
	local group = ply:GetUserGroup()
	local color = ranks[group]
	local txtcheck = string.sub(text,1,1)
	if txtcheck == "/" then
		return text
	else
		return "", CustomChat_ChatMessage(ply, text, "["..string.upper(string.sub(group,1,1))..string.sub(group,2).."]", color.r, color.g, color.b)
	end
end
hook.Add("PlayerSay", "WordCheck", CustomChat_Checker)

else
usermessage.Hook(“CustomChat_ChatMsg”, function(um)
local ply = um:ReadEntity()
local msg = um:ReadString()
local rank = um:ReadString()
local r = um:ReadShort()
local g = um:ReadShort()
local b = um:ReadShort()
chat.AddText(Color(r, g, b), rank, team.GetColor(ply:Team()), " "…ply:Nick(), Color(255,255,255), ": "…msg)
end)
end
[/lua]

ok so that works but it dosnt project into ooc

Can any1 help me make the tags appear in rp commands such as ooc pm adverts? Also make it NOT appear in local chat and for local chat NOT be like global(The local chat everyone can see not just the people near them)

[editline]5th December 2012[/editline]

anyone? :frowning:

To do that you would need to mod darkrp directly.