Galactix Posted July 5, 2018 Share Posted July 5, 2018 (edited) Hello, I have used the function setPlayerNametagColor to set the color of the player's nametag according to his ACL rank, but I would also like the color in chat to be changed as to grant more visibility to both staff and vip players. The problem is that I have been searching for similar topics but found nothing usable to start scripting such a function, so I would like someone to give me an idea of what to use in order to make that possible. Edited July 5, 2018 by Galactix Link to comment
Discord Moderators Pirulax Posted July 5, 2018 Discord Moderators Share Posted July 5, 2018 Hello, because you put effort in it, I'll write a code for ya'. local HEX_TABLE = {[0] = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "A", "B", "C", "D", "E", "F"} local ENABLED_MSG_TYPES = {[0] = true} local function rgb2hex(r,g,b) return "#"..HEX_TABLE[math.floor(r/16)]..HEX_TABLE[r-(16*r1)]..HEX_TABLE[math.floor(g/16)].. HEX_TABLE[g-(16*g1)]..HEX_TABLE[math.floor(b/16)]..HEX_TABLE[b-(16*b1)] end addEventHandler("onPlayerChat", root, function(msg, msgType) if (not DISABLED_MSG_TYPES[msgType]) then outputChatBox(rgb2hex(getPlayerNametagColor(source))..msg) end end ) Untested. Link to comment
Galactix Posted July 5, 2018 Author Share Posted July 5, 2018 Thanks, but I get the error "attempt to index global "DISABLED_MSG_TYPES" (a nil value) How to fix it? Link to comment
Mr.Loki Posted July 5, 2018 Share Posted July 5, 2018 (edited) addEventHandler("onPlayerChat", root, function(msg, msgType) if msgType == 0 then local r,g,b = getPlayerNametagColor( source ) local name = getPlayerName( source ):gsub("#%x%x%x%x%x%x","") -- remove cc from name local msg = msg:gsub("#%x%x%x%x%x%x","") outputChatBox(name.."#FFFFFF: "..msg,r,g,b,true) end end ) Edited July 5, 2018 by Mr.Loki Link to comment
Galactix Posted July 5, 2018 Author Share Posted July 5, 2018 (edited) @Mr.Loki I didn't meant it for message color, but for the nametags color set up with the setPlayerNametagColor function. It doesn't appear in chat, only in scoreboard and under the player's health. By the way, how to use the account name for display instead to prevent players from using hexacode colors? Edited July 5, 2018 by Galactix Link to comment
Mr.Loki Posted July 6, 2018 Share Posted July 6, 2018 5 hours ago, Galactix said: @Mr.Loki I didn't meant it for message color, but for the nametags color set up with the setPlayerNametagColor function. It doesn't appear in chat, only in scoreboard and under the player's health. That's what i did in the code. i only changed the Name color in the messages to work with setPlayerNametagColor. 5 hours ago, Galactix said: By the way, how to use the account name for display instead to prevent players from using hexacode colors? The code I posted shows you how to remove CCs(Color codes) from names and messages. Link to comment
Galactix Posted July 6, 2018 Author Share Posted July 6, 2018 (edited) Well, using your script doesn't color nametags and doesn't cancel any hexcolor coded nametag without giving any error. I have however found this on the wiki for the outputChatBox function which works for the nametag color on players without hexacode colors: function colouredChat ( message, theType ) if theType == 0 then --if its normal chat (not /me or teamchat) then cancelEvent() --prevent MTA from outputting chat message = string.gsub(message, "#%x%x%x%x%x%x", "") --remove any hex tags in a player's chat to prevent custom colours by using lua's string.gsub local r,g,b = getPlayerNametagColor ( source ) --get the player's nametag colour local chatterName = getPlayerName ( source ) --get his name --output a message with the name as his nametag colour, and the rest in white. outputChatBox ( chatterName..":#FFFFFF "..message, getRootElement(), r, g, b, true ) end end addEventHandler("onPlayerChat", getRootElement(), colouredChat) except that the player using nicknames containing hexcolor codes aren't affected by it, why? Edited July 6, 2018 by Galactix Link to comment
Mr.Loki Posted July 6, 2018 Share Posted July 6, 2018 Oh my bad i just checked my code and forgot to add root at line 7 should be outputChatBox(name.."#FFFFFF: "..msg,root,r,g,b,true) 1 Link to comment
Galactix Posted July 7, 2018 Author Share Posted July 7, 2018 20 hours ago, Mr.Loki said: Oh my bad i just checked my code and forgot to add root at line 7 should be outputChatBox(name.."#FFFFFF: "..msg,root,r,g,b,true) Thanks, works smoothly Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now