Jump to content

Removing color codes


Gravestone

Recommended Posts

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...