• [HELP] Print Chat Message Colour
    13 replies, posted
Hey guys, what's the way to Print messages to chat like ply:ChatPrint does but with colours? ply:ChatPrint(Color(0,255,0), "Test") doesn't work so... What could I use? I know chat.AddText works but I wanted something like "ply":chat.AddText Thanks for reading :)
If you are wanting to use chat colors serverside, use the [URL="http://wiki.garrysmod.com/page/Net_Library_Usage"]net[/URL] library.
[QUOTE=The Android1;44459689]If you are wanting to use chat colors serverside, use the [URL="http://wiki.garrysmod.com/page/Net_Library_Usage"]net[/URL] library.[/QUOTE] I want it Client side, but with colours
If you are running the code clientside, then what is wrong with using chat.AddText?
[QUOTE=The Android1;44459711]If you are running the code clientside, then what is wrong with using chat.AddText?[/QUOTE] I can't use it for only one player to see it
[QUOTE=Pwned231;44459798]I can't use it for only one player to see it[/QUOTE] If you want everyone to see it you will somehow have to have networking involved.
[QUOTE=The Android1;44459811]If you want everyone to see it you will somehow have to have networking involved.[/QUOTE] I want only ONE guy to see it, That's why I wanted "ply:ChatPrint" but with colours, what I meant was "ply = LocalPlayer" but ChatPrint doesnt work with colours
[code]if SERVER then 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] Drop that in a shared file. You can call BroadcastMsg() and ply:PlayerMsg() serveside to print coloured chat to players. It accepts arguments in the exact same way as chat.AddText() Usage: [code] BroadcastMsg(Color(255,0,0),"Hello World") [/code] [HIGHLIGHT]Hello World[/HIGHLIGHT] in everyone's chatbox. [code] ply:PlayerMsg(Color(255,0,0),"Hello, "..ply:Nick()) -- where ply is my player entity. [/code] [HIGHLIGHT]Hello, Mors Quaedam[/HIGHLIGHT] in my chatbox.
[QUOTE=Mors Quaedam;44459973][code]if SERVER then 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] Drop that in a shared file. You can call BroadcastMsg() and ply:PlayerMsg() serveside to print coloured chat to players. It accepts arguments in the exact same way as chat.AddText() Usage: [code] BroadcastMsg(Color(255,0,0),"Hello World") [/code] [HIGHLIGHT]Hello World[/HIGHLIGHT] in everyone's chatbox. [code] ply:PlayerMsg(Color(255,0,0),"Hello, "..ply:Nick()) -- where ply is my player entity. [/code] [HIGHLIGHT]Hello, Mors Quaedam[/HIGHLIGHT] in my chatbox.[/QUOTE] I actually wonder why we don't have such a function in base GMod, and only ChatPrint.
Where's the best place to put this shared code so that I can call it from anywhere? (from addons or gamemodes) I'm still pretty new so I put it where it works, but there must be a rule of some sort...
Thanks Mors Quaedam, now I understand why I didn't find what I wanted before... And thanks for everyone who tried to help me :)
[QUOTE=Mors Quaedam;44459973] ... [/QUOTE] Not sure why but It didn't work, and 0 errors, it just doesn't pop up... Any idea what's the problem?
Print something in the net receive function to ensure that you're receiving the net message. Check the client console for the print.
[QUOTE=Jeezy;44468495]Print something in the net receive function to ensure that you're receiving the net message. Check the client console for the print.[/QUOTE] Thanks for the help, I was actually doing that already, didn't notice that I put the file in the autorun/server folder *facepalm* It's working, Thanks
Sorry, you need to Log In to post a reply to this thread.