在魔兽世界中发行lua代码


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

我感谢所有的帮助。

ChatMod2_GetWords显然很好。

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

我还没怎么看ChatMod2_StripSpecial

相关内容

  • 没有找到相关文章

最新更新