Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.53 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.     53901, --Flask of the Frost Wyrm
  11.     53902, --Flask of Stoneblood
  12.     53903, --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 Scanner = CreateFrame("Frame")
  57. Scanner:RegisterEvent("BAG_UPDATE")
  58. Scanner:RegisterEvent("UNIT_INVENTORY_CHANGED")
  59. Scanner:SetScript("OnEvent", function()
  60.     --AutoButton:SetAlpha(0)
  61.     --AutoButton:EnableMouse(false)
  62.    
  63.     local bcount = 0
  64.     --Scan bags for Item matchs
  65.     for b = 0, NUM_BAG_SLOTS do
  66.         for s = 1, GetContainerNumSlots(b) do
  67.             local itemID = GetContainerItemID(b, s)
  68.             itemID = tonumber(itemID)
  69.             for i, Items in pairs(Items) do
  70.                 if itemID == Items then
  71.                     bcount = bcount + 1
  72.                     local itemName, _, _, _, _, _, _, _, _, _, _ = GetItemInfo(itemID)
  73.                     local count = GetItemCount(itemID)
  74.                     local itemIcon = GetItemIcon(itemID)                   
  75.                      
  76.                     local button = createButton(bcount)
  77.  
  78.                     --Set our texture to the item found in bags
  79.                     button.t:SetTexture(itemIcon)
  80.  
  81.                     --Get the count if there is one
  82.                     if count and count ~= 1 then
  83.                         button.c:SetText(count)
  84.                     else
  85.                         button.c:SetText("")
  86.                     end
  87.  
  88.                     --Make button use the set item when clicked
  89.                     button:SetAttribute("item", itemName)
  90.  
  91.                     button:SetScript("OnUpdate", function(self, elapsed)
  92.                         local cd_start, cd_finish, cd_enable = GetContainerItemCooldown(b, s)
  93.                         CooldownFrame_SetTimer(button.Cooldown, cd_start, cd_finish, cd_enable)
  94.                     end)
  95.                     button:SetAlpha(1)
  96.                     button:EnableMouse(true)
  97.                    
  98.                     buttons[bcount] = button
  99.                 end
  100.             end
  101.         end
  102.     end
  103.  
  104.     --Scan inventory for Equipment matches
  105.     for w = 1, 19 do
  106.         for e, EquipedItems in pairs(EquipedItems) do
  107.             if GetInventoryItemID("player", w) == EquipedItems then
  108.                 local itemName, _, _, _, _, _, _, _, _, _, _ = GetItemInfo(EquipedItems)
  109.                 local itemIcon = GetInventoryItemTexture("player",w)               
  110.                
  111.                 local button = createButton(bcount)
  112.                
  113.                 --Set our texture to the item found in bags
  114.                 button.t:SetTexture(itemIcon)
  115.                 button.c:SetText("")               
  116.  
  117.                 --Make button use the set item when clicked
  118.                 button:SetAttribute("item", itemName)
  119.  
  120.                 button:SetScript("OnUpdate", function(self, elapsed)
  121.                     local cd_start, cd_finish, cd_enable = GetInventoryItemCooldown("player",w)
  122.                     CooldownFrame_SetTimer(button.Cooldown, cd_start, cd_finish, cd_enable)
  123.                 end)
  124.                 button:SetAlpha(1)
  125.                 button:EnableMouse(true)
  126.                
  127.                 buttons[bcount] = button
  128.             end
  129.         end
  130.     end
  131.  
  132.     -- Display the buttons
  133.     for i,b in pairs(buttons) do
  134.         if i == 1 then         
  135.             b:SetPoint("TOPLEFT", Minimap, "BOTTOMLEFT", TukuiDB.Scale(-2), TukuiDB.Scale(-2))
  136.         else
  137.             b:SetPoint("BOTTOMLEFT", buttons[i-1], "BOTTOMRIGHT", TukuiDB.Scale(4), 0)
  138.         end
  139.     end
  140. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement