Changing chat colors

Does anyone know how to change the colors of chat text? (TTT, ULX)
Thanks :slight_smile:

Disclaimer: did a lot of searching, couldn’t find anything

Elaborate, please.

Alrighty! Np, my bad.

e.g. im in the ULX group of Owner, when I type a message into the chat…

[Owner]Voyboy: sus on sm63, kos him if I die

I want the “sus on sm63, kos him if I die” to appear in a defined color, e.g. (I don’t code, just an example)

if usergroup=Owner then chatcolor = (255, 255, 255)
if usergroup=Admin then chatcolor = (255, 0, 255)
if steamid=92873498 then chatcolor = (255, 255, 255)

there could be an easy way to do this, hopefully there is, thanks!

Return false on the PlayerSay hook and overwrite it with just a chat.AddText function like this

[lua]
hook.Add(“PlayerSay”,“RankChatColors”,function(ply,text)
return false, if ply:IsUserGroup(“owner”) then
chat.AddText(Color(128,0,0),"[Owner]",team.GetColor(ply:Team()),ply:Name(),color_white,": “,Color(255,255,0),text)
elseif ply:IsUserGroup(”") then --repeat for all usergroups
–chat.AddText stuff
end)
[/lua]

Untested BTW.

PlayerSay it’s Server side and chat.AddText it’s clientside
This will require override the chat.AddText method

Not to mention returning false before the rest of the code will cause none of that code to be run…

That solution was voted down by a few people :frowning: Does anyone know how to do this?

Because the code is ugly. This is what I would use; I just wrote this, it also includes chat tags and player name coloring. Not sure if it works, but here you go.



local cols = {/* CHAT TEXT COLOR */ /* CHAT TAG COLOR */ /* NAME COLOR */ /*OPTIONAL: Pretty chat tag */}
cols["admin"] = {Color(255, 25, 25), Color(255, 25, 25), Color(255, 25, 25)}
cols["owner"] = {Color(255, 25, 25), Color(255, 25, 25), Color(255, 25, 25)}
//etc
hook.Add("OnPlayerChat", "Shit", function(ply, text, team, dead)
	local rank = ply:GetUserGroup() or "user"
	local col  = cols[rank] or {}
	local tag  = col[4] or "["..rank.."]"
	local chattextcol = col[1] or Color(255, 255, 255)
	local chattagcol  = col[2] or Color(255, 255, 255)
	local namecolor   = col[3] or Color(255, 255, 255)

	local chat = {}

	table.insert(chat, chattagcol)
	table.insert(chat, tag)

	if (dead) then table.insert(chat, Color(255, 30, 40)) table.insert(chat, "*DEAD*") end
	if (team) then table.insert(chat, Color(30, 160, 40)) table.insert(chat, "( TEAM )") end 
	if (IsValid(ply)) then table.insert(chat, namecolor) table.insert(chat, ply:Nick()) else table.insert(chat, "Console") end

	table.insert(chat, chattextcol)
	table.insert(chat, ": "..text)

	chat.AddText(unpack(chat))

	return true
end)


[jamesp103|895|STEAM_0:1:64332991] Lua Error:
TTTScoreboardColorForPlayer hook returned something that isn’t a color!

AND
[cooperman117|920|STEAM_0:0:56525854] Lua Error:

[ERROR] lua/autorun/god.lua:2: ‘)’ expected near ‘}’

  1. unknown - lua/autorun/god.lua:0

These seem to be unrelated to the code you have. (especially the second one, first one might be unrelated too)

[ERROR] lua/autorun/god.lua:2: ‘)’ expected near ‘}’

  1. unknown - lua/autorun/god.lua:0

god.lua is the file with the posted script

Old chat tags that I used on my ttt servers all credit goes to tyguy, these are the ones he made straight from the zip. drop in your lua/auto/client. Obviously you’ll want to edit the table for your own ranks. And if you don’t want ranks to show remove the v[3],v[2], from the chat.addtext. If you need help modifying these just ask



--Chat Tags by Tyguy
CreateClientConVar("chat_tags_color_r", 255, true, false)
CreateClientConVar("chat_tags_color_g", 0, true, false)
CreateClientConVar("chat_tags_color_b", 0, true, false)
CreateClientConVar("chat_tags_color_a", 255, true, false)

local Tags = 
{
--Group    --Tag     --Color
{"admin", "[ADMIN] ", Color(200, 0, 255, 255) },
{"superadmin", "[SUPERADMIN] ", Color(255, 0, 0, 255) },
{"developer", "[DEVELOPER] ", Color(0, 0, 0, 255) },
{"ldeveloper", "[DEVELOPER] ", Color(0, 0, 0, 255) },
{"donatoradmin", "[ADMIN] ", Color(255, 255, 0, 255) },
{"mod", "[MOD] ", Color(0, 255, 208, 255) },
{"donatormod", "[MOD] ", Color(255, 255, 0, 255) },
{"trialstaff", "[T-STAFF] ", Color(235, 255, 59, 255) },
{"respected", "[RESPECTED] ", Color(0, 255, 0, 255) },
{"trusted", "[TRUSTED] ", Color(110, 255, 94, 255) },
{"chatmod", "[CHAT MOD] ", Color(28, 255, 251, 255) }


}

hook.Add("OnPlayerChat", "Tags", function(ply, strText)
	for k,v in pairs(Tags) do
		if ply:IsUserGroup(v[1]) then
			local R = GetConVarNumber("chat_tags_color_r")
			local G = GetConVarNumber("chat_tags_color_g")
			local B = GetConVarNumber("chat_tags_color_b")
			local A = GetConVarNumber("chat_tags_color_a")
			local nickteam = team.GetColor(ply:Team())
			chat.AddText(v[3], v[2], nickteam, ply:Nick(), color_white, ": ", strText)
			return true
		end
	end
end )