Does anyone know how to change the colors of chat text? (TTT, ULX)
Thanks :)
Disclaimer: did a lot of searching, couldn't find anything
Elaborate, please.
[QUOTE=Sm63;46422301]Elaborate, please.[/QUOTE]
Alrighty! Np, my bad.
e.g. im in the ULX group of Owner, when I type a message into the chat...
[Owner]Voyboy: sus on sm63, kos him if I die
I want the "sus on sm63, kos him if I die" to appear in a defined color, e.g. (I don't code, just an example)
if usergroup=Owner then chatcolor = (255, 255, 255)
if usergroup=Admin then chatcolor = (255, 0, 255)
if steamid=92873498 then chatcolor = (255, 255, 255)
there could be an easy way to do this, hopefully there is, thanks!
Return false on the PlayerSay hook and overwrite it with just a chat.AddText function like this
[lua]
hook.Add("PlayerSay","RankChatColors",function(ply,text)
return false, if ply:IsUserGroup("owner") then
chat.AddText(Color(128,0,0),"[Owner]",team.GetColor(ply:Team()),ply:Name(),color_white,": ",Color(255,255,0),text)
elseif ply:IsUserGroup("") then --repeat for all usergroups
--chat.AddText stuff
end)
[/lua]
Untested BTW.
PlayerSay it's Server side and chat.AddText it's clientside
This will require override the chat.AddText method
[QUOTE=gonzalolog;46424160]PlayerSay it's Server side and chat.AddText it's clientside
This will require override the chat.AddText method[/QUOTE]
Not to mention returning false before the rest of the code will cause none of that code to be run…
That solution was voted down by a few people :( Does anyone know how to do this?
Because the code is ugly. This is what I would use; I just wrote this, it also includes chat tags and player name coloring. Not sure if it works, but here you go.
[code]
local cols = {/* CHAT TEXT COLOR */ /* CHAT TAG COLOR */ /* NAME COLOR */ /*OPTIONAL: Pretty chat tag */}
cols["admin"] = {Color(255, 25, 25), Color(255, 25, 25), Color(255, 25, 25)}
cols["owner"] = {Color(255, 25, 25), Color(255, 25, 25), Color(255, 25, 25)}
//etc
hook.Add("OnPlayerChat", "Shit", function(ply, text, team, dead)
local rank = ply:GetUserGroup() or "user"
local col = cols[rank] or {}
local tag = col[4] or "["..rank.."]"
local chattextcol = col[1] or Color(255, 255, 255)
local chattagcol = col[2] or Color(255, 255, 255)
local namecolor = col[3] or Color(255, 255, 255)
local chat = {}
table.insert(chat, chattagcol)
table.insert(chat, tag)
if (dead) then table.insert(chat, Color(255, 30, 40)) table.insert(chat, "*DEAD*") end
if (team) then table.insert(chat, Color(30, 160, 40)) table.insert(chat, "( TEAM )") end
if (IsValid(ply)) then table.insert(chat, namecolor) table.insert(chat, ply:Nick()) else table.insert(chat, "Console") end
table.insert(chat, chattextcol)
table.insert(chat, ": "..text)
chat.AddText(unpack(chat))
return true
end)
[/code]
[QUOTE=crazyscouter;46428163]Because the code is ugly. This is what I would use; I just wrote this, it also includes chat tags and player name coloring. Not sure if it works, but here you go.
[code]
local cols = {/* CHAT TEXT COLOR */ /* CHAT TAG COLOR */ /* NAME COLOR */ /*OPTIONAL: Pretty chat tag */}
cols["admin"] = {Color(255, 25, 25), Color(255, 25, 25), Color(255, 25, 25)}
cols["owner"] = {Color(255, 25, 25), Color(255, 25, 25), Color(255, 25, 25)}
//etc
hook.Add("OnPlayerChat", "Shit", function(ply, text, team, dead)
local rank = ply:GetUserGroup() or "user"
local col = cols[rank] or {}
local tag = col[4] or "["..rank.."]"
local chattextcol = col[1] or Color(255, 255, 255)
local chattagcol = col[2] or Color(255, 255, 255)
local namecolor = col[3] or Color(255, 255, 255)
local chat = {}
table.insert(chat, chattagcol)
table.insert(chat, tag)
if (dead) then table.insert(chat, Color(255, 30, 40)) table.insert(chat, "*DEAD*") end
if (team) then table.insert(chat, Color(30, 160, 40)) table.insert(chat, "( TEAM )") end
if (IsValid(ply)) then table.insert(chat, namecolor) table.insert(chat, ply:Nick()) else table.insert(chat, "Console") end
table.insert(chat, chattextcol)
table.insert(chat, ": "..text)
chat.AddText(unpack(chat))
return true
end)
[/code][/QUOTE]
[jamesp103|895|STEAM_0:1:64332991] Lua Error:
TTTScoreboardColorForPlayer hook returned something that isn't a color!
AND
[cooperman117|920|STEAM_0:0:56525854] Lua Error:
[ERROR] lua/autorun/god.lua:2: ')' expected near '}'
1. unknown - lua/autorun/god.lua:0
[QUOTE=Voyboy;46429400][jamesp103|895|STEAM_0:1:64332991] Lua Error:
TTTScoreboardColorForPlayer hook returned something that isn't a color!
AND
[cooperman117|920|STEAM_0:0:56525854] Lua Error:
[ERROR] lua/autorun/god.lua:2: ')' expected near '}'
1. unknown - lua/autorun/god.lua:0[/QUOTE]
These seem to be unrelated to the code you have. (especially the second one, first one might be unrelated too)
[QUOTE=LUModder;46431040]These seem to be unrelated to the code you have. (especially the second one, first one might be unrelated too)[/QUOTE]
[ERROR] lua/autorun/god.lua:2: ')' expected near '}'
1. unknown - lua/autorun/god.lua:0
god.lua is the file with the posted script
Old chat tags that I used on my ttt servers all credit goes to [url=http://www.garrysmod.org/downloads/?a=view&id=133493]tyguy[/url], these are the ones he made straight from the zip. drop in your lua/auto/client. Obviously you'll want to edit the table for your own ranks. And if you don't want ranks to show remove the v[3],v[2], from the chat.addtext. If you need help modifying these just ask
[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)
local Tags =
{
--Group --Tag --Color
{"admin", "[ADMIN] ", Color(200, 0, 255, 255) },
{"superadmin", "[SUPERADMIN] ", Color(255, 0, 0, 255) },
{"developer", "[DEVELOPER] ", Color(0, 0, 0, 255) },
{"ldeveloper", "[DEVELOPER] ", Color(0, 0, 0, 255) },
{"donatoradmin", "[ADMIN] ", Color(255, 255, 0, 255) },
{"mod", "[MOD] ", Color(0, 255, 208, 255) },
{"donatormod", "[MOD] ", Color(255, 255, 0, 255) },
{"trialstaff", "[T-STAFF] ", Color(235, 255, 59, 255) },
{"respected", "[RESPECTED] ", Color(0, 255, 0, 255) },
{"trusted", "[TRUSTED] ", Color(110, 255, 94, 255) },
{"chatmod", "[CHAT MOD] ", Color(28, 255, 251, 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, ": ", strText)
return true
end
end
end )
[/code]
Sorry, you need to Log In to post a reply to this thread.