-- Color Nicks
if CM2_Options["ColorNicks"] then
    -- Hold Original unmodified words for later use
    local temp2 = ChatMod2_GetWords(text)
    local temp = ChatMod2_StripSpecial(text)
    temp = string.gsub(temp, "[^a-zA-Z0-9%s]", "")
    temp = temp:lower()
    local words = ChatMod2_GetWords(temp)

    for word = 1, #words do
        -- Cant be the player name or it locks up the client... Go figure...
        if words[word] ~= UnitName("player") then
            print(temp)
            if CM2_Nick[words[word]] ~= nil then
                --{level, class, guild, realm, name} Nick Layout. Name is the unfiltered name.
                local newWord = ChatMod2_ColorName(CM2_Nick[words[word]][2], words[word])

                text = text:gsub(temp2[word], newWord)
            end
        end
    end
end

The above is causing World Of Warcraft to fail to load into the game. Because I lack the debugging ability from the program itself does anyone see why here?

Below are the other functions mentioned in the above code:

function ChatMod2_GetWords(str)
    local results = {}

    for word in string.gmatch(str, "%S+", 9) do
        table.insert(results, word)
    end

    return results
end

function ChatMod2_ColorName(str, word)
    --Using the class and word provided precolor it for chat.
    if str == "MONK" then
        word = "\124cff00ff96" .. CM2_Nick[word][5] .. "|r"
    elseif str == "DEATH KNIGHT" then
        word = "\124cffc41f3b" .. CM2_Nick[word][5] .. "|r"
    elseif str == "DRUID" then
        word = "\124cffff7d0a" .. CM2_Nick[word][5] .. "|r"
    elseif str == "HUNTER" then
        word = "\124cffabd473" .. CM2_Nick[word][5] .. "|r"
    elseif str == "MAGE" then
        word = "\124cff69ccf0" .. CM2_Nick[word][5] .. "|r"
    elseif str == "PALADIN" then
        word = "\124cfff58cba" .. CM2_Nick[word][5] .. "|r"
    elseif str == "PRIEST" then
        word = "\124cffffffff" .. CM2_Nick[word][5] .. "|r"
    elseif str == "ROGUE" then
        word = "\124cfffff569" .. CM2_Nick[word][5] .. "|r"
    elseif str == "SHAMAN" then
        word = "\124cff0070de" .. CM2_Nick[word][5] .. "|r"
    elseif str == "WARLOCK" then
        word = "\124cff9482c9" .. CM2_Nick[word][5] .. "|r"
    elseif str == "WARRIOR" then
        word = "\124cffc79c6e" .. CM2_Nick[word][5] .. "|r"
    end

    return word
end

function ChatMod2_StripSpecial(msg)
    --Strips out all special characters such as Ö and the like.
    --Should only be used for being returned to a temp string unless replacement is required.
    if msg ~= nil and type(msg) == "string" then
        for x=1, #msg do
            local CharVal = string.byte(string.sub(msg,x,x+1), -1)
            --local StrTab = {}
            --for a=1, #msg do
              --  StrTab:Insert(
            --print("Debug: "..string.byte(string.sub(msg,x,x+1)))
            --print(CharVal)
            if CharVal ~= nil then
                if 146 <= CharVal and CharVal <= 150 then
                    msg = StringReplace(msg, x, "O")
                elseif 178 <= CharVal and CharVal <= 182 then
                    msg = StringReplace(msg, x, "o")
                elseif 128 <= CharVal and CharVal <= 134 then
                    msg = StringReplace(msg, x, "A")
                elseif 160 <= CharVal and CharVal <= 166 then
                    msg = StringReplace(msg, x, "a")
                elseif 136 <= CharVal and CharVal <= 139 then
                    msg = StringReplace(msg, x, "E")
                elseif 168 <= CharVal and CharVal <= 171 then
                    msg = StringReplace(msg, x, "e")
                elseif 153 <= CharVal and CharVal <= 156 then
                    msg = StringReplace(msg, x, "U")
                elseif 185 <= CharVal and CharVal <= 188 then
                    msg = StringReplace(msg, x, "u")
                elseif 140 <= CharVal and CharVal <= 143 then
                    msg = StringReplace(msg, x, "I")
                elseif 172 <= CharVal and CharVal <= 175 then
                    msg = StringReplace(msg, x, "i")
                elseif 135 == CharVal then
                    msg = StringReplace(msg, x, "C")
                elseif 167 == CharVal then
                    msg = StringReplace(msg, x, "c")
                elseif 144 == CharVal then
                    msg = StringReplace(msg, x, "D")
                elseif 176 == CharVal then
                    msg = StringReplace(msg, x, "o")
                elseif 152 == CharVal then
                    msg = StringReplace(msg, x, "O")
                elseif 184 == CharVal then
                    msg = StringReplace(msg, x, "o")
                end
            end
        end
    end

    return msg
end

I appreciate any and all help.

有帮助吗?

解决方案

ChatMod2_GetWords is clearly fine.

ChatMod2_ColorName on the other hand will explode if CM2_Nick doesn't have a word entry or if that entry doesn't have an index 5.

I haven't looked at ChatMod2_StripSpecial much yet.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top