Hello. I'm trying to change the word 'test' into another color, I've changed the code but it still seems to stay red. Any ideas?
[IMG]http://snag.gy/sYmw1.jpg[/IMG]
[CODE]--Chat Tags by Tyguy
CreateClientConVar("chat_tags_color_r", 0, true, false)
CreateClientConVar("chat_tags_color_g", 0, true, false)
CreateClientConVar("chat_tags_color_b", 0, true, false)
CreateClientConVar("chat_tags_color_a", 255, true, false)
local Tags =
{
--Group --Tag --Color
{"admin", "[admin] ", Color(0, 0, 255, 255) },
{"moderator", "[mod] ", Color(16, 181, 206, 255) },
{"respected_mod", "[respected_mod] ", Color(0, 255, 0, 255) }
}
hook.Add("OnPlayerChat", "Tags", function(ply, strText)
for k,v in pairs(Tags) do
if ply:IsUserGroup(v[1]) then
local R = GetConVarNumber("chat_tags_color_r")
local G = GetConVarNumber("chat_tags_color_g")
local B = GetConVarNumber("chat_tags_color_b")
local A = GetConVarNumber("chat_tags_color_a")
local nickteam = team.GetColor(ply:Team())
chat.AddText(v[3], v[2], nickteam, ply:Nick(), color_white, ": ", Color(R, G, B, A), strText)
return true
end
end
end )[/CODE]
This is your answer. Color(R, B, G, A)
[CODE]chat.AddText(v[3], v[2], nickteam, ply:Nick(), color_white, ": ",Color(R, B, G, A), strText)[/CODE]
[QUOTE=gary23548;41950636]Hello. I'm trying to change the word 'test' into another color, I've changed the code but it still seems to stay red. Any ideas?
[IMG]http://snag.gy/sYmw1.jpg[/IMG]
[CODE]--Chat Tags by Tyguy
CreateClientConVar("chat_tags_color_r", 0, true, false)
CreateClientConVar("chat_tags_color_g", 0, true, false)
CreateClientConVar("chat_tags_color_b", 0, true, false)
CreateClientConVar("chat_tags_color_a", 255, true, false)
local Tags =
{
--Group --Tag --Color
{"admin", "[admin] ", Color(0, 0, 255, 255) },
{"moderator", "[mod] ", Color(16, 181, 206, 255) },
{"respected_mod", "[respected_mod] ", Color(0, 255, 0, 255) }
}
hook.Add("OnPlayerChat", "Tags", function(ply, strText)
for k,v in pairs(Tags) do
if ply:IsUserGroup(v[1]) then
local R = GetConVarNumber("chat_tags_color_r")
local G = GetConVarNumber("chat_tags_color_g")
local B = GetConVarNumber("chat_tags_color_b")
local A = GetConVarNumber("chat_tags_color_a")
local nickteam = team.GetColor(ply:Team())
chat.AddText(v[3], v[2], nickteam, ply:Nick(), color_white, ": ", Color(R, G, B, A), strText)
return true
end
end
end )[/CODE][/QUOTE]
Look at the convars
[QUOTE=Sleazeball;41950794]This is your answer. Color(R, B, G, A)
[CODE]chat.AddText(v[3], v[2], nickteam, ply:Nick(), color_white, ": ",Color(R, B, G, A), strText)[/CODE][/QUOTE]
Its not. Those are used as convars
What are the values of each convar?
I've changed this value, but I was wrong. The color in 'test' stays red.
[CODE]--Chat Tags by Tyguy
CreateClientConVar("chat_tags_color_r", 255, true, false)
CreateClientConVar("chat_tags_color_g", 0, true, false)
CreateClientConVar("chat_tags_color_b", 0, true, false)
CreateClientConVar("chat_tags_color_a", 255, true, false)
[/CODE]
[CODE]--Chat Tags by Tyguy
CreateClientConVar("chat_tags_color_r", 0, true, false)
CreateClientConVar("chat_tags_color_g", 0, true, false)
CreateClientConVar("chat_tags_color_b", 0, true, false)
CreateClientConVar("chat_tags_color_a", 255, true, false)
[/CODE]
What is the output in your console when you type chat_tags_color_r? Because you have it archived, so changing the convar value in the lua won't change it on the client
[CODE]chat_tags_color_r = 255[/CODE]
Shouldn't this value reset to 0 after the server is restarted?
No. Looking at your code:
[code]--Chat Tags by Tyguy
CreateClientConVar("chat_tags_color_r", 0, true, false)
CreateClientConVar("chat_tags_color_g", 0, true, false)
CreateClientConVar("chat_tags_color_b", 0, true, false)
CreateClientConVar("chat_tags_color_a", 255, true, false)[/code]
CreateClientConVar is a 4 part function to create clientside variables similar to when using concommand.Add, but sets a default, and is able to save across joins/restarts.
The first part is a string variable which is the actual command. The second is a number which indicates the default and initial values.
The third is a bool value (true/false) that indicates if the value should save across sessions. This is the issue you are running into. Looking back at your code this is set to true across the board.
The fourth is if it should send to the server as a userdata. I've never used it so I wouldn't know.
That being said, you can set the true to false and it will default back across saves. Also that being said: Looking purely at this code I will say that this will only show that color for the specified usergroup on the client only. It will not show the color to all clients.
Shouldn't it be like this if you want it white?
I've been using this script since it was released, and this is what I have changed it to.
But every now and then people still ask me why the text is red.
The text is white for me though.
[CODE]--Chat Tags by Tyguy
CreateClientConVar("chat_tags_color_r", 255, true, false)
CreateClientConVar("chat_tags_color_g", 255, true, false)
CreateClientConVar("chat_tags_color_b", 255, true, false)
CreateClientConVar("chat_tags_color_a", 255, true, false)
[/CODE]
[QUOTE=zapha;41961653]Shouldn't it be like this if you want it white?
I've been using this script since it was released, and this is what I have changed it to.
But every now and then people still ask me why the text is red.
The text is white for me though.
[CODE]--Chat Tags by Tyguy
CreateClientConVar("chat_tags_color_r", 255, true, false)
CreateClientConVar("chat_tags_color_g", 255, true, false)
CreateClientConVar("chat_tags_color_b", 255, true, false)
CreateClientConVar("chat_tags_color_a", 255, true, false)
[/CODE][/QUOTE]
Because the normal players code it set to Red in RBG colours. You did set it to White for youself since its CLIENT convars not SERVER convars
I see.
Is there some way to force the settings upon the players then?
Like this perhaps?
[LUA]
RunConsoleCommand("chat_tags_color_r", "255");
RunConsoleCommand("chat_tags_color_g", "255");
RunConsoleCommand("chat_tags_color_b", "255");
[/LUA]
Add this to your init.lua file:
[lua]
hook.Add("PlayerInitialSpawn", "ChatTagSetConv", function(ply)
ply:ConCommand("chat_tags_color_r", 255)
ply:ConCommand("chat_tags_color_g", 255)
ply:ConCommand("chat_tags_color_b", 255)
end )
[/lua]
It will set the values to 255 when the [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index2901.html]player spawned for the first time in the server[/url].
Note: they will still be able to change it afterwards.
[QUOTE=Tomvdr;41964233]Add this to your init.lua file:
[lua]
hook.Add("PlayerInitialSpawn", "ChatTagSetConv", function(ply,)
ply:RunConsoleCommand("chat_tags_color_r", 255)
ply:RunConsoleCommand("chat_tags_color_g", 255)
ply:RunConsoleCommand("chat_tags_color_b", 255)
end )
[/lua]
It will set the values to 255 when the [url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index2901.html]player spawned for the first time in the server[/url].
Note: they will still be able to change it afterwards.[/QUOTE]
Thanks mate, will test this out as soon as my server is empty :)
[QUOTE=zapha;41964297]Thanks mate, will test this out as soon as my server is empty :)[/QUOTE]
Updated my previous post, had some errors.
[QUOTE=zapha;41961653]Shouldn't it be like this if you want it white?
I've been using this script since it was released, and this is what I have changed it to.
But every now and then people still ask me why the text is red.
The text is white for me though.
[CODE]--Chat Tags by Tyguy
CreateClientConVar("chat_tags_color_r", 255, true, false)
CreateClientConVar("chat_tags_color_g", 255, true, false)
CreateClientConVar("chat_tags_color_b", 255, true, false)
CreateClientConVar("chat_tags_color_a", 255, true, false)
[/CODE][/QUOTE]
That's a good point, I didn't realize until you mentioned it.
What is your end want with it? Because it's still clientside so they will only see the color they set, not colors others set.
Sorry, you need to Log In to post a reply to this thread.