• Rainbow colored names
    4 replies, posted
I'm trying to make my name rainbow colored and this is what I have. [lua] if (ply:SteamID()=="MySteamID") or (ply:SteamID()=="AnotherSteamID") then local chatTable = {v[3], v[2], nickteam, "(TEAM) "} local name = string.Explode("",ply:Nick()) for i=1, #name do local num = #name local Step = 360/num local Pos = 1 local color = HSVToColor(Pos,1,1) colortext = table.concat(color, ", ") table.insert(chatTable,"'"..colortext.."'") table.insert(chatTable,name[i]) Pos=Pos+Step end chatadd = table.concat( chatTable, ", ") ply:RunString("chat.AddText("..chatadd..", color_white, ': '"..strText) else *CODE FOR OTHER CHAT* [/lua] strText is what is said and v[3] and v[2] don't matter (color and text) The problem is that you cannot concat a color, the "HSVToColor", and I was wondering if there was a way to get around this. I also tried that RunString-ing a color as "Color("..color[r]..","..color[g]..","..color[b]..","..color[a]..")", but that also didn't work. Yes, I'm sure there is a more efficient way of doing this and I am open to suggestions, but I can't think of any other way. Any help is appreciated, Panda
You can send the table (without first concatenating it) using the net library, then pass the [URL="http://wiki.garrysmod.com/page/Global/unpack"]unpack[/URL]ed table on the client to chat.AddText. The function chat.AddText accepts a variable number of arguments. Here's an example of a table you could unpack for chat.AddText. [lua]local text = { Color(255,0,0), -- set color to red "Panda", -- append 'Panda' (will be colored red) Color(0,255,0), -- set color to green "man", -- append 'man' (will be colored green) Color(0,0,255), -- set color to blue "09", -- append '09' (will be colored blue) color_white, -- set color to white ": ", -- name separator (will be colored white) message -- player's message (will be colored white) } chat.AddText( unpack(text) )[/lua]
Thanks for the help... This is shared, so I don't need to worry about using the net library. If I have any problems I'll post back tomorrow.
[QUOTE=Pandaman09;40225878]Thanks for the help... This is shared, so I don't need to worry about using the net library. If I have any problems I'll post back tomorrow.[/QUOTE] Assuming you're sending this from the server, using shared code doesn't mean the client knows what's going on. Also, Player.RunString is not an existing function. You're likely looking for Player.SendLua, but I recommend looking into using the net library.
[QUOTE=samm5506;40225902]Assuming you're sending this from the server, using shared code doesn't mean the client knows what's going on. Also, Player.RunString is not an existing function. You're likely looking for Player.SendLua, but I recommend looking into using the net library.[/QUOTE] Just re-read the function and i must have mis-read it. I'm not worried about it working because the same script also adds a tag before players name, so changing text color would be strange. [editline]10th April 2013[/editline] It worked! thanks for the help samm Solved... Thread may be closed.
Sorry, you need to Log In to post a reply to this thread.