• PrintMessage
    8 replies, posted
Hello, I'm just asking to make sure, What i want to do is printing a message to specified player's chat with colors, here is my simple code: [lua] -- Which one of these work? this one below? ply:PrintMessage( HUD_PRINTTALK, Color(255, 0, 153, 255).."Testing the color" ) -- Or this one? ply:PrintMessage( HUD_PRINTTALK, Format( "&sTesting the color", Color(255, 0, 153, 255) ) ) [/lua] And is the HUD_PRINTTALK for printing on the player's chat box? Thank you!
[url]http://wiki.garrysmod.com/page/Player/PrintMessage[/url] First argument has to be a number, in your case 3 instead of "HUD_PRINTTALK". [code]ply:PrintMessage(3, "YOURSTRING")[/code] Have no idea about the color though, but you could just make a usermessage and use chat.AddText.
[QUOTE=LennyPenny;41129445]3 instead of "HUD_PRINTTALK".[/QUOTE] Why? HUD_PRINTTALK works fine?
It would have to be like this, [lua]ply:PrintMessage( HUD_PRINTTALK,"Testing the color" )[/lua] as PrintMessage does not have a colour function, if you want colour try something like this: [lua] util.AddNetworkString("NetMessageName") if SERVER then net.Start("NetMessageName") net.Send(ply) else net.Receive("NetMessageName", function() chat.AddText(Color(255,0,0),"Testing the colour") end) end[/lua]
[QUOTE=goosey;41129606]It would have to be like this, [lua]ply:PrintMessage( HUD_PRINTTALK,"Testing the color" )[/lua] as PrintMessage does not have a colour function, if you want colour try something like this: [lua] util.AddNetworkString("NetMessageName") if SERVER then net.Start("NetMessageName") net.Send(ply) else net.Receive("NetMessageName", function() chat.AddText(Color(255,0,0),"Testing the colour") end) end[/lua][/QUOTE] Possible to make it like a function that i can use for sending to a player? Thanks
[code]function Shit(ply) util.AddNetworkString("NetMessageName") if SERVER then net.Start("NetMessageName") net.Send(ply) else net.Receive("NetMessageName", function() chat.AddText(Color(255,0,0),"Testing the colour") end) end concommand.Add("SendShit",Shit)[/code] Make sure its shared.
[code]if SERVER then util.AddNetworkString("NetMessageName") net.Start("NetMessageName") local tbl = {Color(255,0,0),"Testing the colour"} -- Put your shit inside of this table. net.WriteTable(tbl) net.Send(ply) else net.Receive("NetMessageName", function() chat.AddText(unpack(net.ReadTable())) end) end[/code]
Disregard all previous replies. Serverside: [code] util.AddNetworkString( "PrintColor" ) local Meta = FindMetaTable( "Player" ) function Meta:PrintColor( ... ) net.Start( "PrintColor" ) net.WriteTable( { ... } ) net.Send( self ) end[/code] Clientside: [code] net.Receive( "PrintColor", function() chat.AddText( unpack( net.ReadTable() ) ) end )[/code] Example usage: [code] Warlock:PrintColor( Color( 255, 0, 0 ), "Roses are red, ", Color( 0, 0, 255 ), "violets are blue, ", Color( 255, 255, 255 ), "this is white and so are you!" )[/code] It'd actually be more efficient to not send it as a table, but as separate values, but yeah... It's not really a performance intensive task.
Solved :) If you're interested in how: shared (SERVER & CLIENT) File: [lua] local meta = FindMetaTable("Player") function meta:Send(msg) umsg.Start( "Send_Print", self ) umsg.String( msg ) umsg.End() end function SendAll(msg) umsg.Start( "Send_Print" ) umsg.String( msg ) umsg.End() end [/lua] cl_init (CLIENT) File: [lua] usermessage.Hook( "Send_Print", function( data ) chat.PlaySound() -- Prints in white chat.AddText( Color( 255, 255, 255, 255 ), (data:ReadString() or "This is a random message!") ) end ) [/lua] Psst: I was a noob 3 weeks ago with CLIENT and SERVER files stuffs :)
Sorry, you need to Log In to post a reply to this thread.