rowaasr13@0: -- [AUTOLOCAL START] rowaasr13@0: local CreateFrame = CreateFrame rowaasr13@0: local InCombatLockdown = InCombatLockdown rowaasr13@0: local SecureHandlerWrapScript = SecureHandlerWrapScript rowaasr13@0: local print = print rowaasr13@0: local type = type rowaasr13@0: -- [AUTOLOCAL END] rowaasr13@0: rowaasr13@0: local frame_name = "OOCDo" rowaasr13@0: local button = CreateFrame("Button", frame_name, nil, "SecureActionButtonTemplate,SecureHandlerMouseUpDownTemplate") rowaasr13@0: button:SetAttribute("type", "macro") rowaasr13@0: button:SetAttribute("macrotext", "") rowaasr13@0: SecureHandlerWrapScript( rowaasr13@0: button, -- frame rowaasr13@0: "OnClick", -- script rowaasr13@0: button, -- header rowaasr13@6: 'return nil, "reset"', -- pre rowaasr13@6: 'self:SetAttribute("type", "macro") self:SetAttribute("macrotext", "")' -- post rowaasr13@0: ) rowaasr13@0: rowaasr13@7: --- Sets button to perform given macro text as-is. rowaasr13@7: -- Sets button's .type to "macro" and .macrotext to given string verbatim rowaasr13@7: -- @param command macro text to perform rowaasr13@7: -- @param command2 same as command, if first argument is "taken" because of : call. rowaasr13@2: function button.MacroText(command, command2) rowaasr13@0: if command == button then command = command2 end rowaasr13@0: if InCombatLockdown() then return end rowaasr13@7: button:SetAttribute("type", "macro") rowaasr13@0: button:SetAttribute("macrotext", command) rowaasr13@0: end rowaasr13@0: button.Macro = button.MacroText rowaasr13@0: button.T = button.MacroText rowaasr13@8: button.M = button.MacroText rowaasr13@8: rowaasr13@8: --- Tries to set button to use first available item from list. rowaasr13@8: -- Sets button's .type to "item" and .item to first item that player have (GetItemCount > 0). rowaasr13@8: -- 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. rowaasr13@8: -- If none of items was found, button will still lose previously assigned command. rowaasr13@8: -- @param ... list of item IDs to try rowaasr13@8: -- @return true if any item was found and nil otherwise rowaasr13@8: function button.Use(...) rowaasr13@8: if InCombatLockdown() then return end rowaasr13@8: button:SetAttribute("type", "item") rowaasr13@8: button:SetAttribute("item", nil) rowaasr13@8: for idx = 1, select('#', ...) do repeat rowaasr13@8: local elem = select(idx, ...) rowaasr13@8: if elem == button then break end rowaasr13@8: if type(elem) == "number" then rowaasr13@8: if GetItemCount(elem) > 0 then rowaasr13@8: button:SetAttribute("item", "item:" .. elem) rowaasr13@8: return true rowaasr13@8: end rowaasr13@8: end rowaasr13@8: until true end rowaasr13@8: end rowaasr13@8: rowaasr13@11: --- Tries to set button to cast first available spell from list. rowaasr13@8: -- Sets button's .type to "spell" and .spell to first spell that player knowns (GetSpellInfo(name) returns something). rowaasr13@8: -- 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. rowaasr13@8: -- If none of spells was found, button will still lose previously assigned command. rowaasr13@8: -- @param ... list of spell IDs to try rowaasr13@8: -- @return true if any spell was found and nil otherwise rowaasr13@8: function button.Cast(...) rowaasr13@8: if InCombatLockdown() then return end rowaasr13@8: button:SetAttribute("type", "spell") rowaasr13@8: button:SetAttribute("spell", nil) rowaasr13@8: for idx = 1, select('#', ...) do repeat rowaasr13@8: local elem = select(idx, ...) rowaasr13@8: if elem == button then break end rowaasr13@8: if type(elem) == "number" then rowaasr13@8: if GetSpellInfo(GetSpellInfo(elem)) then rowaasr13@8: button:SetAttribute("spell", elem) rowaasr13@8: return true rowaasr13@8: end rowaasr13@8: end rowaasr13@8: until true end rowaasr13@8: end