在魔兽世界中使用lua代码的问题

时间:2014-05-13 19:17:03

标签: lua world-of-warcraft

    -- 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

以上导致魔兽世界无法加载到游戏中。因为我缺乏程序本身的调试能力,有没有人在这里看到原因?

以下代码中提到的其他功能如下:

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

我感谢任何帮助。

1 个答案:

答案 0 :(得分:2)

ChatMod2_GetWords显然很好。

另一方面,如果ChatMod2_ColorName没有单词条目或者该条目没有索引5,则

CM2_Nick会爆炸。

我还没有看过ChatMod2_StripSpecial