-
Posted by friddan on Fri, 25 Oct 2013 12:23:52
Greetings! I've created an addon that should do the same as /roll, but when trying it in-game, the function doesn't seem to work. The game doesn't return the incorrect command message, I'm not getting any Lua errors, but nothing happens from inside the functions. Here is the code:
SLASH_ROLL1 = "/roll" SLASH_ROLL2 = "/random" SLASH_ROLL3 = "/rand" SLASH_ROLL4 = "/rnd" SlashCmdList["ROLL"] = function(msg) if msg == nil then SendChatMessage("(( -RC- I just rolled " .. math.random(0,100) .. ". ))", "say", nil) else local indexOfSeparator = strfind(msg, "-") if indexOfSeparator == nil then if checkDigits(msg) == 1 then SendChatMessage("(( -RC- I just rolled " .. math.random(0, msg) .. ". ))", "say", nil) else sendSyntax() end else local isCorrectArgument = 1 local minNum = strsub(msg, 1, indexOfSeparator - 1) local maxNum = strsub(msg, indexOfSeparator + 1) if checkDigits(minNum) == 0 then isCorrectArgument = 0 end if isCorrectArgument == 1 then if checkDigits(maxNum) == 0 then isCorrectArgument = 0 end end if isCorrectArgument == 1 then if minNum > maxNum then isCorrectArgument = 0 end end if isCorrectArgument == 1 then SendChatMessage("(( -RC- I just rolled " .. math.random(minNum, maxNum) .. ". ))", "say", nil) else sendSyntax() end end end end function checkDigits(num) local isOk = 1 for i = 1, strleng(num), 1 do if strsub(num, i, i) == $D then isOk = 0 end end if isOk == 1 then return 1 else return 0 end end function sendSyntax() print("-RC- Incorrect syntax:") print("/roll") print("/roll 'Maximum Roll'") print("/roll 'Minimum Roll'-'Maximum Roll'") return 0 end