comparison OOCDo.lua @ 8:3b9bc71a1dd6

.Use - use first available item; .Cast - use first available spell
author rowaasr13
date Tue, 10 Jan 2017 19:40:33 +0300
parents e41de98f6b33
children 088390bd4ab3
comparison
equal deleted inserted replaced
7:e41de98f6b33 8:3b9bc71a1dd6
26 if command == button then command = command2 end 26 if command == button then command = command2 end
27 if InCombatLockdown() then return end 27 if InCombatLockdown() then return end
28 button:SetAttribute("type", "macro") 28 button:SetAttribute("type", "macro")
29 button:SetAttribute("macrotext", command) 29 button:SetAttribute("macrotext", command)
30 end 30 end
31
32 button.Macro = button.MacroText 31 button.Macro = button.MacroText
33 button.T = button.MacroText 32 button.T = button.MacroText
34 button.M = button.MacroText 33 button.M = button.MacroText
34
35 --- Tries to set button to use first available item from list.
36 -- Sets button's .type to "item" and .item to first item that player have (GetItemCount > 0).
37 -- Returns if any item was found or not, so you can use this in conditional to do something else if there were no suitable items.
38 -- If none of items was found, button will still lose previously assigned command.
39 -- @param ... list of item IDs to try
40 -- @return true if any item was found and nil otherwise
41 function button.Use(...)
42 if InCombatLockdown() then return end
43 button:SetAttribute("type", "item")
44 button:SetAttribute("item", nil)
45 for idx = 1, select('#', ...) do repeat
46 local elem = select(idx, ...)
47 if elem == button then break end
48 if type(elem) == "number" then
49 if GetItemCount(elem) > 0 then
50 button:SetAttribute("item", "item:" .. elem)
51 return true
52 end
53 end
54 until true end
55 end
56
57 --- Tries to set button to castwe first available spell from list.
58 -- Sets button's .type to "spell" and .spell to first spell that player knowns (GetSpellInfo(name) returns something).
59 -- Returns if any spell was found or not, so you can use this in conditional to do something else if there were no suitable spells.
60 -- If none of spells was found, button will still lose previously assigned command.
61 -- @param ... list of spell IDs to try
62 -- @return true if any spell was found and nil otherwise
63 function button.Cast(...)
64 if InCombatLockdown() then return end
65 button:SetAttribute("type", "spell")
66 button:SetAttribute("spell", nil)
67 for idx = 1, select('#', ...) do repeat
68 local elem = select(idx, ...)
69 if elem == button then break end
70 if type(elem) == "number" then
71 if GetSpellInfo(GetSpellInfo(elem)) then
72 button:SetAttribute("spell", elem)
73 return true
74 end
75 end
76 until true end
77 end