Gravestone Posted February 28, 2016 Share Posted February 28, 2016 I want to disable color codes from the chat and from player's nickname. The color doesn't appear in chat but it outputs in chatbox as a blank message. This is my chat script, if needed: addEventHandler('onPlayerChat', g_Root, function(msg, type) if type == 0 then cancelEvent() local r, g, b = getPlayerNametagColor(source) outputChatBox(getPlayerName(source) .. ': #FFFFFF' .. msg:gsub('#%x%x%x%x%x%x', ''), g_Root, r, g, b, true) outputServerLog( "CHAT: " .. getPlayerName(source) .. ": " .. msg ) end end ) Link to comment
Wisam Posted February 28, 2016 Share Posted February 28, 2016 Here, that should work try it function deletecc() for k, v in ipairs (getElementsByType("player")) do local name = getPlayerName(v) if (string.find(name,"#%x%x%x%x%x%x")) then local name = string.gsub(name,"#%x%x%x%x%x%x","") setPlayerName(v,name) cancelEvent() end end end addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),deletecc) function removeCC(oldNick,newNickname) local name = getPlayerName(source) if newNickname then name = newNickname end if (string.find(name,"#%x%x%x%x%x%x")) then local name = string.gsub(name,"#%x%x%x%x%x%x","") setPlayerName(source,name) if (newNickname) then cancelEvent() end end end addEventHandler("onPlayerJoin",getRootElement(),removeCC) addEventHandler("onPlayerChangeNick",getRootElement(),removeCC) Link to comment
Gravestone Posted February 28, 2016 Author Share Posted February 28, 2016 Didn't work. No errors in the debugscript either. Link to comment
1LoL1 Posted February 28, 2016 Share Posted February 28, 2016 Try this: addEventHandler("onPlayerChat", getRootElement(), function(msg, type) if type == 0 then cancelEvent() local r, g, b = getPlayerNametagColor(source) local msg = msg:gsub("#%x%x%x%x%x%x", "") outputChatBox(string.gsub(getPlayerName(source),"#%x%x%x%x%x%x","")..": #FFFFFF"..msg, getRootElement(), r, g, b, true) outputServerLog( "CHAT: " .. name .. ": " .. msg ) end end)) Link to comment
Gravestone Posted February 28, 2016 Author Share Posted February 28, 2016 'It outputs in chatbox as a blank message' if color coded. I mean if a player types message color coded it should show error like: Message should not contain color codes. 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