Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.74 KB | None | 0 0
  1. local Items = {
  2.     39213, -- Massive Seaforium Charge (Strand of the Ancients)
  3.     47030, -- Huge Seaforium Bombs (Isle of Conquest)
  4.     42986, -- The RP-GG (Wintergrasp)
  5.     37860, -- Ruby Drake (Occulus)
  6.     37815, -- Emerald Drake (Occulus)
  7.     37859, -- Amber Essence (Occulus)
  8.     46029, -- Mimiron's Core (Ulduar)
  9.     -- 34722, -- Frostweave Bandage (Test)
  10.     46376, --Flask of the Frost Wyrm
  11.     46379, --Flask of Stoneblood
  12.     46377, --Flask of Endless Rage
  13.     40211, --Potion of Speed
  14.     40093, --Indestructible Potion
  15. }
  16.  
  17. local EquipedItems = {
  18.     49278, -- Goblin Rocket Pack (ICC)
  19.     --50356, -- Corroded Skeleton Key (Test)
  20. }
  21.  
  22. local buttons = { }
  23.  
  24. local function createButton(id)
  25.     --Create our Button
  26.     local AutoButton = CreateFrame("Button", "AutoButton"..id, UIParent, "SecureActionButtonTemplate")
  27.     AutoButton:SetWidth(TukuiDB.Scale(27))
  28.     AutoButton:SetHeight(TukuiDB.Scale(27))
  29.     TukuiDB.SetTemplate(AutoButton)
  30.     TukuiDB.StyleButton(AutoButton, false)
  31.     AutoButton:SetAttribute("type", "item")
  32.     AutoButton:SetAlpha(0)
  33.     AutoButton:EnableMouse(false)
  34.      
  35.     --Texture for our button
  36.     AutoButton.t = AutoButton:CreateTexture(nil,"OVERLAY",nil)
  37.     AutoButton.t:SetPoint("TOPLEFT", AutoButton, "TOPLEFT", TukuiDB.Scale(2), TukuiDB.Scale(-2))
  38.     AutoButton.t:SetPoint("BOTTOMRIGHT", AutoButton, "BOTTOMRIGHT", TukuiDB.Scale(-2), TukuiDB.Scale(2))
  39.     AutoButton.t:SetTexCoord(0.1, 0.9, 0.1, 0.9)
  40.      
  41.     --Count text for our button
  42.     AutoButton.c = AutoButton:CreateFontString(nil,"OVERLAY",f)
  43.     AutoButton.c:SetFont(TukuiCF.media.font,12,"OUTLINE")
  44.     AutoButton.c:SetTextColor(0.8, 0.8, 0.8, 1)
  45.     AutoButton.c:SetPoint("BOTTOMRIGHT", TukuiDB.Scale(-2), TukuiDB.Scale(2))
  46.     AutoButton.c:SetJustifyH("CENTER") 
  47.      
  48.     --Cooldown
  49.     AutoButton.Cooldown = CreateFrame("Cooldown",nil,AutoButton)
  50.     AutoButton.Cooldown:SetPoint("TOPLEFT", AutoButton, "TOPLEFT", TukuiDB.Scale(2), TukuiDB.Scale(-2))
  51.     AutoButton.Cooldown:SetPoint("BOTTOMRIGHT", AutoButton, "BOTTOMRIGHT", TukuiDB.Scale(-2), TukuiDB.Scale(2))
  52.    
  53.     return AutoButton
  54. end
  55.  
  56. local function isItemAlreadyButton(itemID)
  57.     for i, b in pairs(buttons) do
  58.         if buttons[i]:GetName() == "AutoButton"..itemID then return true end
  59.     end
  60.     return false
  61. end
  62.  
  63. local Scanner = CreateFrame("Frame")
  64. Scanner:RegisterEvent("BAG_UPDATE")
  65. Scanner:RegisterEvent("UNIT_INVENTORY_CHANGED")
  66. Scanner:SetScript("OnEvent", function()
  67.     --AutoButton:SetAlpha(0)
  68.     --AutoButton:EnableMouse(false)
  69.    
  70.     local bcount = 0
  71.     --Scan bags for Item matchs
  72.     for b = 0, NUM_BAG_SLOTS do
  73.         for s = 1, GetContainerNumSlots(b) do
  74.             local itemID = GetContainerItemID(b, s)
  75.             itemID = tonumber(itemID)
  76.             for i, Items in pairs(Items) do
  77.                 if itemID == Items and not isItemAlreadyButton(itemID) == true then
  78.                     bcount = bcount + 1
  79.                     local itemName, _, _, _, _, _, _, _, _, _, _ = GetItemInfo(itemID)
  80.                     local count = GetItemCount(itemID)
  81.                     local itemIcon = GetItemIcon(itemID)                   
  82.                      
  83.                     local button = createButton(itemID)
  84.  
  85.                     --Set our texture to the item found in bags
  86.                     button.t:SetTexture(itemIcon)
  87.  
  88.                     --Get the count if there is one
  89.                     if count and count ~= 1 then
  90.                         button.c:SetText(count)
  91.                     else
  92.                         button.c:SetText("")
  93.                     end
  94.  
  95.                     --Make button use the set item when clicked
  96.                     button:SetAttribute("item", itemName)
  97.  
  98.                     button:SetScript("OnUpdate", function(self, elapsed)
  99.                         local cd_start, cd_finish, cd_enable = GetContainerItemCooldown(b, s)
  100.                         CooldownFrame_SetTimer(button.Cooldown, cd_start, cd_finish, cd_enable)
  101.                     end)
  102.                     button:SetAlpha(1)
  103.                     button:EnableMouse(true)
  104.                    
  105.                     buttons[bcount] = button
  106.                 end
  107.             end
  108.         end
  109.     end
  110.  
  111.     --Scan inventory for Equipment matches
  112.     for w = 1, 19 do
  113.         for e, EquipedItems in pairs(EquipedItems) do
  114.             if GetInventoryItemID("player", w) == EquipedItems then
  115.                 local itemName, _, _, _, _, _, _, _, _, _, _ = GetItemInfo(EquipedItems)
  116.                 local itemIcon = GetInventoryItemTexture("player",w)               
  117.                
  118.                 local button = createButton(bcount)
  119.                
  120.                 --Set our texture to the item found in bags
  121.                 button.t:SetTexture(itemIcon)
  122.                 button.c:SetText("")               
  123.  
  124.                 --Make button use the set item when clicked
  125.                 button:SetAttribute("item", itemName)
  126.  
  127.                 button:SetScript("OnUpdate", function(self, elapsed)
  128.                     local cd_start, cd_finish, cd_enable = GetInventoryItemCooldown("player",w)
  129.                     CooldownFrame_SetTimer(button.Cooldown, cd_start, cd_finish, cd_enable)
  130.                 end)
  131.                 button:SetAlpha(1)
  132.                 button:EnableMouse(true)
  133.                
  134.                 buttons[bcount] = button
  135.             end
  136.         end
  137.     end
  138.  
  139.     -- Display the buttons
  140.     for i,b in pairs(buttons) do
  141.         if i == 1 then         
  142.             b:SetPoint("TOPLEFT", Minimap, "BOTTOMLEFT", TukuiDB.Scale(-2), TukuiDB.Scale(-2))
  143.         else
  144.             b:SetPoint("BOTTOMLEFT", buttons[i-1], "BOTTOMRIGHT", TukuiDB.Scale(4), 0)
  145.         end
  146.     end
  147. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement