Easy Colored Chat

Easy Colored Chat

Easily create colored chat without having to call it client side. Calling colored chat has never been so easy!

I am working on a game mode and thought it was a hassle to make a lua to detect when I need chat commands. So I thought, “Why don’t I just call it through the server?”, then this was born.

It is very simple and is not totally done. You can edit this as much as you want and re-upload, I don’t care as long as you give me some credits. This is meant just to be more or less proof of concept.

Read more in the link below… enjoy :smiley:

I wouldn’t exactly call this efficient, but not too bad for a beginner.

Don’t ever remember saying I was a beginner?

There’s so many things I’d love to point out but that would just make me look like a dick. So instead I’ll just say “Well done!”.

Or just use Overv’s implementation of chat.AddText server side:
if SERVER then
chat = { }
function chat.AddText( … )
if ( type( arg[1] ) == “Player” ) then ply = arg[1] end
if !ply:IsValid() then return end
umsg.Start( “AddText”, ply )
umsg.Short( #arg )
for _, v in pairs( arg ) do
if ( type( v ) == “string” ) then
umsg.String( v )
elseif ( type ( v ) == “table” ) then
umsg.Short( v.r )
umsg.Short( v.g )
umsg.Short( v.b )
umsg.Short( v.a )
umsg.End( )
usermessage.Hook( “AddText”, function( um )
local argc = um:ReadShort( )
local args = { }
for i = 1, argc / 2, 1 do
table.insert( args, Color( um:ReadShort( ), um:ReadShort( ), um:ReadShort( ), um:ReadShort( ) ) )
table.insert( args, um:ReadString( ) )

    chat.AddText( unpack( args ) )
end )


Can you send me in a private message?

No offense, it’s obvious.

Y’all could post helpful comments here and explain what he’s doing wrong instead of being smug arseholes about it

I could be wrong, but couldn’t you just send one usermessage, instead of having one for text, and one for the color?

Pretty sure this is as simple as your script can get. Only reason I put a recipient filter on it was because I didn’t want to make it longer.

[lua]local Colors = {}
Colors[“red”] = Color(200,50,50)
Colors[“green”] = Color(50,200,50)
Colors[“blue”] = Color(50,50,200)
Colors[“yellow”] = Color(250, 250, 25)
Colors[“purple”] = Color(150,25,200)
Colors[“orange”] = Color(250, 100, 25)
Colors[“gold”] = Color(220,155,25)
Colors[“white”] = Color(250,250,250)
Colors[“black”] = Color(50,50,50)

local function EasyColoredChat(text, color, ply)
if !text then return end
if !Colors[color] then return end

local rf = RecipientFilter()
if !ply then

umsg.Start("ColoredText", rf)


[lua]local function ColoredChat(um)
local Text = um:ReadString()
local R = um:ReadShort()
local G = um:ReadShort()
local B = um:ReadShort()
chat.AddText(Color(R,G,B), Text)

usermessage.Hook(“ColoredText”, ColoredChat)[/lua]

For some reason whenever I tried that it would only read one value. But you can change it however you want.

Didn’t realize I was talking to such a lua god. I was out of place oh great one. Please forgive me for I do not know what I do.

You didn’t really just release that?

Oh god…

What the hell is that FindPlayer function? You could just return Player?

Not very good code wise but as a first script it’s not bad. This is where we all begin.

To elaborate on this, the FindPlayer function is useless. You could just use ‘if !ply’ or ‘if ply == nil’ to check if there was an argument given.

What you want to do though, is have a function to find a player by nick, so you can check if they exist if there is a player argument given and return the actual player to be used. Something like this:

[lua]local function findbynick(name)
if name == nil or name == “” then return nil; end
for k,v in ipairs(player.GetAll()) do
if string.find(string.lower(v:Nick()), string.lower(name)) != nil then
return v;
return nil;

Also, correct me if I’m wrong, but wont the code in the posts above not work? The ply argument EasyColouredChat is presumably taking a partial player name, which is then being treated as if it was a player entity. Unless this is only part of it.

Yeah, I know. I meant to put checks for names and SteamIDs, but I totally forgot. Rate that post dumb, lol.


Jesus christ, it’s sarcasm