2014-05-13 27 views
1
-- 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 

以上是造成魔獸世界無法加載到遊戲中的問題。因爲我缺乏程序本身的調試能力,所以沒有人看到爲什麼在這裏?問題與魔獸世界中的lua代碼

以下是在上面的代碼中提到的其他功能:

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 

我明白任何及所有的幫助。

+0

已知的引用函數是否能正常工作?代碼是否是導致遊戲無法顯示的新代碼的第一個代碼片段? –

+0

是的,我已經通過/運行在客戶端單獨測試了它們,它們按預期工作。 最後一次發生這是一個無限循環,但我沒有看到一個 – TULOA

+0

你運行引用的函數究竟是如何?什麼論點?什麼全球狀態? 'ChatMod2_GetWords'顯然很好。另一方面,如果'CM2_Nick'沒有'詞'條目或者如果該條目沒有索引'5','ChatMod2_ColorName'將會爆炸。我還沒有看過'ChatMod2_StripSpecial'。 –

回答

1

ChatMod2_GetWords顯然很好。

,另一方面ChatMod2_ColorName會爆炸,如果CM2_Nick沒有一個字的條目或該項目沒有我還沒有ChatMod2_StripSpecial看多又一個索引5

+0

我做了修改它如何處理,它似乎工作,所以我敢打賭,這是問題。 – TULOA

+0

我不確定此官方政策是什麼,但發佈了您實際進行的更改(無論是在評論中還是作爲對您問題的修改)可能都是一個好主意。 –

+0

明天發病吧。它遲到了,我目前還沒有訪問它。 – TULOA