View Single Post
04-08-11, 05:14 PM   #8
Lanodar
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 6
I tried all day and i've finally found a solution
I combined, string.sub, string.find and string.gsub to split "!druid tank" into two parts with


Code:
arg1 = string.lower(arg1) -- converts arg1 into lower case
part1 =string.gsub(arg1,string.sub(arg1,string.find(arg1," ",1),string.len(arg1)),"")-- finds " " in arg1 and cuts off everything from " " to the end off arg1.

part2  =  string.gsub(arg1,string.sub(arg1,1,string.find(arg1," ")),"")-- same like part1 but cuts off everything before the " "
If there's only one word in the whisper, you'll receive an LUA error because there's noch space (" ") in arg1.
To avoid this I had to do the following:


Code:
     arg1 = strlower(arg1)
space = string.find(wmsg," ")
if space ~= nil then 
part1 =string.gsub(arg1,string.sub(arg1,string.find(arg1," ",1),string.len(arg1)),"")
part2  =  string.gsub(arg1,string.sub(arg1,1,string.find(arg1," ")),"")
else
part1=arg1
part2=nil
end


And if part1 == "!druid" and part2=="dps" or part2==nil (or other class/specc combinations) the addon will do stuff.

If something like "!omgwtf1337" is whispered. it sends a message with a command list.

Last edited by Lanodar : 04-08-11 at 05:29 PM.
  Reply With Quote