• Gmod Chat in color
    11 replies, posted
Quick question? Whats the command to add color to a message in chat (serverside - Gmod)
chat.AddText( Color( rgba ), 'text', Color( rgba ), 'text' )
[QUOTE=Netheous;45834988]chat.AddText( Color( rgba ), 'text', Color( rgba ), 'text' )[/QUOTE] That's clientside. You'll have to network it to all clients.
[CODE]AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") function GM:PlayerInitialSpawn(ply) chat.AddText( Color( 0,0,255 ), "lol") end [/CODE] 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]
[QUOTE=HumbleTH;45835066]GM:PlayerInitialSpawn is serverside. You could do something like this: // serversideutil.AddNetworkString( "PlayerDisplayChat" )local PLAYER = FindMetaTable( "Player" )if PLAYER then function PLAYER:SendMessage( ... ) local args = { ... } net.Start( "PlayerDisplayChat" ) net.WriteTable( args ) net.Send( self ) endend// clientsidenet.Receive( "PlayerDisplayChat", function() local args = net.ReadTable() chat.AddText( unpack( args ) )end ) [/QUOTE] That should do.
-snip-
[CODE]BroadcastLua(chat.AddText(Color(0,255,0), "blue stuff"), (Color(255,0,0) , "hello"))[/CODE] Why doesnt this work? Error: ')' expected near ','
[QUOTE=alex578344;45838101][CODE]BroadcastLua(chat.AddText(Color(0,255,0), "blue stuff"), (Color(255,0,0) , "hello"))[/CODE] Why doesnt this work? Error: ')' expected near ','[/QUOTE] 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. [CODE]BroadcastLua("chat.AddText(Color(0,255,0), 'blue stuff', Color(255,0,0), .. ply:Nick)")[/CODE]
Include the following code on your server: [code]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[/code] The code you posted here needs to be like this: [code]ply:PlayerMsg(Color(0,255,0),"Blue stuff, ",Color(255,0,0),ply:Nick())[/code] 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.
Sorry, you need to Log In to post a reply to this thread.