• Changing color of HUD_PRINTTALK
    18 replies, posted
Anyone know how you'd go about changing the color of [CODE]HUD_PRINTTALK[/CODE] text?
You can't.
If you really need to change the color of the text, just use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/draw/DrawText]draw.DrawText[/url] with an xAlign (last argument) of TEXT_ALIGN_CENTER to center it.
[QUOTE=Internet1001;50604400]If you really need to change the color of the text, just use [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/draw/DrawText]draw.DrawText[/url] with an xAlign (last argument) of TEXT_ALIGN_CENTER to center it.[/QUOTE] This would work but I need to be calling it from the server side rather than client.
If you wan't to just do a single color + single string you could always do [lua] if ( SERVER ) then util.AddNetworkString("ColoredMessage"); local meta = FindMetaTable("Player"); function meta:ColoredMessage( msg, r, g, b, a ) if ( !msg ) then msg = "No message"; end if ( !r ) then r = 255; end if ( !g ) then g = 255; end if ( !b ) then b = 255; end if ( !a ) then a = 255; end net.Start("ColoredMessage"); net.WriteString( msg ); net.WriteColor( Color( r, g, b, a ) ); net.Send( self ); end end if ( CLIENT ) then net.Receive("ColoredMessage", function( len ) local msg = net.ReadString(); local color = net.ReadColor(); chat.AddText( color, msg ); end) end [/lua]
[QUOTE=Klaes4Zaugen;50604448]If you wan't to just do a single color + single string you could always do [lua] if ( SERVER ) then util.AddNetworkString("ColoredMessage"); local meta = FindMetaTable("Player"); function meta:ColoredMessage( msg, r, g, b, a ) if ( !msg ) then msg = "No message"; end if ( !r ) then r = 255; end if ( !g ) then g = 255; end if ( !b ) then b = 255; end if ( !a ) then a = 255; end net.Start("ColoredMessage"); net.WriteString( msg ); net.WriteColor( Color( r, g, b, a ) ); net.Send( self ); end end if ( CLIENT ) then net.Receive("ColoredMessage", function( len ) local msg = net.ReadString(); local color = net.ReadColor(); chat.AddText( color, msg ); end) end [/lua][/QUOTE] Well the way I have it set up, the server taking the value of a text box from the client and putting it through HUD_PRINTTALK that way the chat is printed to all players from a player in game
[QUOTE=Thane;50604927]Well the way I have it set up, the server taking the value of a text box from the client and putting it through HUD_PRINTTALK that way the chat is printed to all players from a player in game[/QUOTE] Then network it to all players and draw it clientside. ChatPrint uses usermessages internally anyway.
[QUOTE=code_gs;50605129]Then network it to all players and draw it clientside. ChatPrint uses usermessages internally anyway.[/QUOTE] So do what Klaes4Zaugen said and on serverside make it go to each player connected?
[QUOTE=Thane;50604927]Well the way I have it set up, the server taking the value of a text box from the client and putting it through HUD_PRINTTALK that way the chat is printed to all players from a player in game[/QUOTE] Instead of doing [lua] for _,ply in pairs ( player.GetAll() ) do ply:PrintMessage(HUD_PRINTTALK, "ur shit"); end [/lua] do [lua] for _,ply in pairs ( player.GetAll() ) do ply:ColoredMessage( "ur shit", 255, 255, 255 ); end [/lua] ^ this makes it white text
[QUOTE=Klaes4Zaugen;50605544]Instead of doing [lua] for _,ply in pairs ( player.GetAll() ) do ply:PrintMessage(HUD_PRINTTALK, "ur shit"); end [/lua] do [lua] for _,ply in pairs ( player.GetAll() ) do ply:ColoredMessage( "ur shit", 255, 255, 255 ); end [/lua] ^ this makes it white text[/QUOTE] I'm rather new to Lua so I'll need a little more of an explanation on what to do with this, lol
[QUOTE=Thane;50605568]I'm rather new to Lua so I'll need a little more of an explanation on what to do with this, lol[/QUOTE] Just do the last one in where you recieve the data from the client
[QUOTE=Thane;50604927]Well the way I have it set up, the server taking the value of a text box from the client and putting it through HUD_PRINTTALK that way the chat is printed to all players from a player in game[/QUOTE] And where do I put this? In a shared file? Sorry I put this in shared?[CODE] if ( SERVER ) then util.AddNetworkString("ColoredMessage"); local meta = FindMetaTable("Player"); function meta:ColoredMessage( msg, r, g, b, a ) if ( !msg ) then msg = "No message"; end if ( !r ) then r = 255; end if ( !g ) then g = 255; end if ( !b ) then b = 255; end if ( !a ) then a = 255; end net.Start("ColoredMessage"); net.WriteString( msg ); net.WriteColor( Color( r, g, b, a ) ); net.Send( self ); end end if ( CLIENT ) then net.Receive("ColoredMessage", function( len ) local msg = net.ReadString(); local color = net.ReadColor(); chat.AddText( color, msg ); end) end[/CODE]
If you want to have multiple colors, I recommend keeping it simple and using SendLua() Here's an example: [CODE] ply:SendLua([[ --> Send the player the code in between these brackets chat.AddText(Color(0, 255, 0), "[TEST] ", Color(255, 255, 255), "Testing123") --> Set "[TEST]" to green, and set "Testing123" to white. ]]) [/CODE] Edit: Keep in mind you can't send them server-side variables through this. Aaaaaaand code_gs is right.
[QUOTE=Tupac;50605589]If you want to have multiple colors, I recommend keeping it simple and using SendLua() Here's an example: [CODE] ply:SendLua([[ --> Send the player the code in between these brackets chat.AddText(Color(0, 255, 0), "[TEST] ", Color(255, 255, 255), "Testing123") --> Set "[TEST]" to green, and set "Testing123" to white. ]]) [/CODE][/QUOTE] Way more expensive, and insecure for new programmers who don't know what they're looking for.
[QUOTE=code_gs;50605607]Way more expensive, and insecure for new programmers who don't know what they're looking for.[/QUOTE] Alright so I could i put the stuff in the "if ( server )" in my server file and the stuff in "if ( client )" in my client file
[QUOTE=Thane;50605659]Alright so I could i put the stuff in the "if ( server )" in my server file and the stuff in "if ( client )" in my client file[/QUOTE] You can yes, just remove the if ( CLIENT/SERVER ) then end
[QUOTE=Klaes4Zaugen;50605755]You can yes, just remove the if ( CLIENT/SERVER ) then end[/QUOTE] this is too experienced for me lol I'll try some other time. Thanks anyways guys!
:snip:
Here's the finished working code that Red-XIII was able to help me out with in shared.lua [CODE]if ( SERVER ) then util.AddNetworkString( "ColoredMessage" ); local meta = FindMetaTable("Player"); function meta:ColoredMessage( tmpS, r, g, b, a ) if ( !tmpS ) then tmpS = "No message"; end if ( !r ) then r = 255; end if ( !g ) then g = 255; end if ( !b ) then b = 255; end if ( !a ) then a = 255; end net.Start( "ColoredMessage" ); net.WriteString( tmpS ); net.WriteColor( Color( r, g, b, a ) ); net.SendOmit( self ); end net.Receive("ColoredMessage", function( len, ply ) local tmpS = net.ReadString(); local tmpC = net.ReadColor(); ply:ColoredMessage(tmpS, tmpC.r, tmpC.g, tmpC.b, tmpC.a); end) end if ( CLIENT ) then net.Receive("ColoredMessage", function( len ) local tmpS = net.ReadString(); local tmpC = net.ReadColor(); chat.AddText( tmpC, tmpS ); end) function ColoredMessage( tmpS, tmpC ) chat.AddText( tmpC, tmpS ); net.Start( "ColoredMessage" ); net.WriteString( tmpS ); net.WriteColor( tmpC ) net.SendToServer(); end end[/CODE] And on the client side [CODE]local TextEntry = vgui.Create( "DTextEntry", divider ) TextEntry:SetPos(5, 54) TextEntry:SetSize( 120, 20 ) TextEntry:SetText( "" ) TextEntry.OnEnter = function() ColoredMessage( TextEntry:GetValue(), Color( 255, 1, 1, 255 ) ) end[/CODE] Works beautifully
Sorry, you need to Log In to post a reply to this thread.