Gmod Chat in color

Quick question?

Whats the command to add color to a message in chat (serverside - Gmod)

chat.AddText( Color( rgba ), ‘text’, Color( rgba ), ‘text’ )

That’s clientside.

You’ll have to network it to all clients.


AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")

include("shared.lua")


function GM:PlayerInitialSpawn(ply)
 chat.AddText( Color( 0,0,255 ), "lol")
end


Why doesn’t this work

GM:PlayerInitialSpawn is serverside. You could do something like this:

[lua]
// serverside
util.AddNetworkString( “PlayerDisplayChat” )
local PLAYER = FindMetaTable( “Player” )
if PLAYER then
function PLAYER:SendMessage( … )
local args = { … }
net.Start( “PlayerDisplayChat” )
net.WriteTable( args )
net.Send( self )
end
end
// clientside
net.Receive( “PlayerDisplayChat”, function()
local args = net.ReadTable()
chat.AddText( unpack( args ) )
end )
[/lua]

If you want to add the message to all connected players, you needn’t worry much about networking - just use this:

[lua]
BroadcastLua([[chat.AddText(Color(0,255,0), “blue stuff”)]])
[/lua]

That should do.

-snip-


BroadcastLua(chat.AddText(Color(0,255,0), "blue stuff"), (Color(255,0,0) , "hello"))

Why doesnt this work?

Error: ‘)’ expected near ‘,’

Did you just place parentheses at random places?

[editline]29th August 2014[/editline]

[lua]
BroadcastLua(“chat.AddText(Color(0,255,0), ‘blue stuff’, Color(255,0,0), ‘hello’)”)
[/lua]

I was trying to follow some kind of format. I’m really not sure and thanks alot

[editline]29th August 2014[/editline]

Okay this is frustrating and sorry about all these questions.


BroadcastLua("chat.AddText(Color(0,255,0), 'blue stuff', Color(255,0,0), .. ply:Nick)")

Include the following code on your server:


if SERVER then
	AddCSLuaFile()
	local PLAYER = FindMetaTable("Player")
	util.AddNetworkString( "ColoredMessage" )
	function BroadcastMsg(...)
		local args = {...}
		net.Start("ColoredMessage")
		net.WriteTable(args)
		net.Broadcast()
	end

	function PLAYER:PlayerMsg(...)
		local args = {...}
		net.Start("ColoredMessage")
		net.WriteTable(args)
		net.Send(self)
	end
elseif CLIENT then
	net.Receive("ColoredMessage",function(len) 
		local msg = net.ReadTable()
		chat.AddText(unpack(msg))
		chat.PlaySound()
	end)
end

The code you posted here needs to be like this:


ply:PlayerMsg(Color(0,255,0),"Blue stuff, ",Color(255,0,0),ply:Nick())

It’s a serverside version of chat.AddText().

Call BroadcastMsg() with normal chat.AddText() arguments to send a coloured message to everyone on the server, player:PlayerMsg() to send a specific player a coloured message.