Thread Tools Display Modes
10-27-14, 06:29 AM   #1
Shenj
A Murloc Raider
Join Date: Feb 2011
Posts: 5
Exclamation AutoLootFix for 6.0

Hey, im not sure if a lot of people know but there has been a bug in the autoloot in WoW for a very long time where sometimes it would not actually autoloot and AutoLootFix fixed this bug, but in 6.0 the way AutoLoot works has changed and this Addon is no longer working as intended

It's a fairly basic Addon and I hope someone can look into how to make it work, sadly while the "click more than once causes autoloot to be disabled" bug has kinda been fixed, sometimes it will still not autoloot which makes it a bit harder to reproduce but it happens pretty often for me at the very least.

In LootFrame.lua of Blizzards Loot Frame AutoLoot now looks like this.

Lua Code:
  1. ...
  2.     if ( event == "LOOT_OPENED" ) then
  3.         local autoLoot = ...;
  4.         if( autoLoot == 1 ) then
  5.             LootFrame_InitAutoLootTable( self );
  6.             LootFrame:SetScript("OnUpdate", LootFrame_OnUpdate);
  7.             self.AutoLootDelay = LOOTFRAME_AUTOLOOT_DELAY;
  8.         else
  9.             self.AutoLootDelay = 0;
  10.             self.AutoLootTable = nil;
  11.         end
  12.        
  13.         self.page = 1;
  14.         LootFrame_Show(self);
  15.         if ( not self:IsShown()) then
  16.             CloseLoot(autoLoot == 0);   -- The parameter tells code that we were unable to open the UI
  17.         end
  18.     elseif( event == "LOOT_READY" ) then
  19.         LootFrame_InitAutoLootTable( self );
  20.     ...

In AutoLootFix it's this:
Lua Code:
  1. f:SetScript("OnEvent", function(self, event, ...)
  2.     if event == "PLAYER_ENTERING_WORLD" then
  3.         UpdateAutoLootStatus(GetCVar"autoLootDefault")
  4.     elseif event == "CVAR_UPDATE" then
  5.         local glStr, value = ...
  6.         if glStr == "AUTO_LOOT_DEFAULT_TEXT" then
  7.             UpdateAutoLootStatus(value)
  8.         end
  9.     elseif event == "LOOT_OPENED" then
  10.         if not IsAutoLootKeyDown() then
  11.         --  HideUIPanel(LootFrame)
  12.         end
  13.         local shouldAutoLoot = ...
  14.         if shouldAutoLoot == 0 and not IsAutoLootKeyDown() then
  15.             --print"autoLoot bugged" < This still triggers when autoloot fails
  16.             for i = 1, GetNumLootItems() do
  17.                 LootSlot(i)    
  18.             end
  19.         end
  20.     end
  21. end)

The Addon still triggers fine but the following no longer applies and needs to be changed, sadly i have no damn clue how to make it work as simple as it may be.
Lua Code:
  1. for i = 1, GetNumLootItems() do
  2.                 LootSlot(i)    
  3.             end
  4.         end

For now i replaced the whole addon with this, disabled AutoLoot and AutoLoot key in the Interface and instead use this autoloot, it works but i'd like something that's less hacky
Lua Code:
  1. local f = CreateFrame"Frame"
  2. f:RegisterEvent"LOOT_OPENED"
  3.  
  4. f:SetScript("OnEvent", function(self, event, ...)
  5.     if event == "LOOT_OPENED" and not IsAltKeyDown() then
  6.         for i = 1, GetNumLootItems() do
  7.             LootSlot(i)
  8.         end
  9.     end
  10. end)

Last edited by Shenj : 11-03-14 at 06:34 PM.
  Reply With Quote
10-27-14, 09:13 AM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
It likely doesn't work because most 1s and 0s in the interface have been changed to true/false and it's comparing "if( autoLoot == 1 ) then" when it should simply be "if autLoot then".

The places where it compares the value to 0, like "autoLoot == 0" and "shouldAutoLoot == 0" should be changed to "not autoLoot" and "not shouldAutoLoot".
  Reply With Quote
10-30-14, 05:47 AM   #3
Shenj
A Murloc Raider
Join Date: Feb 2011
Posts: 5
Thanks, I've changed it but honestly I don't know if it works as I ultimately ended up removing the check and having it simply autloot like this all the time because Blizzards new AutoLoot has some really long delays which just feels weird especially because you can see it, it's not something in the background.

Lua Code:
  1. local f = CreateFrame"Frame"
  2. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  3. f:RegisterEvent("CVAR_UPDATE")
  4.  
  5. local UpdateAutoLootStatus = function(value)
  6.     if tonumber(value) == 1 then
  7.         f:RegisterEvent("LOOT_OPENED")
  8.     else
  9.         f:UnregisterEvent("LOOT_OPENED")
  10.     end
  11. end
  12.  
  13. IsAutoLootKeyDown = function()
  14.     -- Possible values: ALT, CTRL, SHIFT, NONE
  15.     local key = InterfaceOptionsControlsPanelAutoLootKeyDropDown:GetValue()
  16.     if key ~= "NONE" then
  17.         if key == "CTRL" then key = "CONTROL" end
  18.         local first, rest = key:sub(1, 1), key:sub(2):lower()
  19.         return _G[("Is%s%sKeyDown"):format(first, rest)]()
  20.     end
  21. end
  22.  
  23. f:SetScript("OnEvent", function(self, event, ...)
  24.     if event == "PLAYER_ENTERING_WORLD" then
  25.         --InterfaceOptionsControlsPanelAutoLootKeyDropDown:SetValue("NONE")
  26.         --SetCVar("autoLootDefault", 0, "AUTO_LOOT_DEFAULT_TEXT")
  27.         UpdateAutoLootStatus(GetCVar"autoLootDefault")
  28.     elseif event == "CVAR_UPDATE" then
  29.         local glStr, value = ...
  30.         if glStr == "AUTO_LOOT_DEFAULT_TEXT" then
  31.             UpdateAutoLootStatus(value)
  32.         end
  33.     elseif event == "LOOT_OPENED" and not IsAutoLootKeyDown() then
  34.         --local shouldAutoLoot = ...
  35.        
  36.         --if not shouldAutoLoot and not IsAutoLootKeyDown() then
  37.         --  print"AutoLootFix: Looting"
  38.             for i = 1, GetNumLootItems() do
  39.                 LootSlot(i)
  40.             end
  41.         --end
  42.     end
  43. end)

Last edited by Shenj : 10-30-14 at 08:01 AM.
  Reply With Quote
10-30-14, 09:54 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
You may want to reverse the order of looting to start with the last slot; otherwise you run the risk of the indices shifting as items move up to fill the slots already looted, and items getting skipped.

Code:
            for i = GetNumLootItems(), 1, -1 do
                LootSlot(i)
            end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
11-03-14, 06:31 PM   #5
Shenj
A Murloc Raider
Join Date: Feb 2011
Posts: 5
Originally Posted by Phanx View Post
You may want to reverse the order of looting to start with the last slot; otherwise you run the risk of the indices shifting as items move up to fill the slots already looted, and items getting skipped.

Code:
            for i = GetNumLootItems(), 1, -1 do
                LootSlot(i)
            end
Thanks will see if this fixes it glitching out here and there for huge loot tables.

I added a little bit of extra functionality to it, what i want is to show a Alert if a Rare items drops as i am now hiding the LootFrame instantly to avoid FPS drops, for now it seems to work but if someone can look over it and clean it up/fix something weirdly looking, please

Edit: So far so good, went through quite a bunch of revision and changes, so far it looks to work how i want it, not that i really know what im doing, mostly copy&paste with a few changes. One thing that doesn't work here is my Color/Name of the Label, doesn't apply correctly.
Lua Code:
  1. --AutoLootfix, EasyLoot, Dugi stuff
  2. local f = CreateFrame"Frame"
  3. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  4. f:RegisterEvent("CVAR_UPDATE")
  5.  
  6. local AutoLootTable = {}
  7. local twipe = table.wipe
  8. local UpdateAutoLootStatus = function(value)
  9.     if tonumber(value) == 1 then
  10.         f:RegisterEvent("LOOT_OPENED")
  11.         f:RegisterEvent("CHAT_MSG_LOOT")
  12.     else
  13.         f:UnregisterEvent("LOOT_OPENED")
  14.         f:UnregisterEvent("CHAT_MSG_LOOT")
  15.     end
  16. end
  17.  
  18. IsAutoLootKeyDown = function()
  19.     -- Possible values: ALT, CTRL, SHIFT, NONE
  20.     local key = InterfaceOptionsControlsPanelAutoLootKeyDropDown:GetValue()
  21.     if key ~= "NONE" then
  22.         if key == "CTRL" then key = "CONTROL" end
  23.         local first, rest = key:sub(1, 1), key:sub(2):lower()
  24.         return _G[("Is%s%sKeyDown"):format(first, rest)]()
  25.     end
  26. end
  27.  
  28. local function GetItemIdFromLink(link)
  29.     return tonumber(link:match(".+|Hitem:([^:]+):.+"))
  30. end
  31.  
  32. f:SetScript("OnEvent", function(self, event, ...)
  33.     if event == "PLAYER_ENTERING_WORLD" then
  34.         UpdateAutoLootStatus(GetCVar"autoLootDefault")
  35.     elseif event == "CVAR_UPDATE" then
  36.         local glStr, value = ...
  37.         if glStr == "AUTO_LOOT_DEFAULT_TEXT" then
  38.             UpdateAutoLootStatus(value)
  39.         end
  40.     elseif event == "LOOT_OPENED" and not IsAutoLootKeyDown() then
  41.             twipe(AutoLootTable)
  42.             for i = GetNumLootItems(), 1, -1 do
  43.                 local lootLink = GetLootSlotLink(i)
  44.                 if lootLink then
  45.                     local itemId = GetItemIdFromLink(lootLink)
  46.                     tinsert(AutoLootTable, itemId)
  47.                 end
  48.                 LootSlot(i)
  49.             end
  50.             if not (IsInInstance() and GetNumGroupMembers() > 1) then
  51.                 if (ElvLootFrame:IsShown()) then
  52.                     ElvLootFrame:Hide()
  53.                 elseif (LootFrame:IsShown()) then
  54.                     LootFrame:Hide()
  55.                 end
  56.             end
  57.     elseif (event=="CHAT_MSG_LOOT") then
  58.         local message, sender, language, channelString, target, flags, _, channelNumber, channelName, _, _ = ...
  59.         AutoLoot_IncomingLoot(message)
  60.     end
  61. end)
  62.  
  63. local ITEMNAME = {
  64.     [LE_ITEM_QUALITY_COMMON] = "Common",
  65.     [LE_ITEM_QUALITY_UNCOMMON] = "Uncommon",
  66.     [LE_ITEM_QUALITY_EPIC] = "Epic",
  67.     [LE_ITEM_QUALITY_RARE] = "Rare",
  68.     [LE_ITEM_QUALITY_LEGENDARY] = "Legendary",
  69.     [LE_ITEM_QUALITY_HEIRLOOM] = "Heirloom"
  70. }
  71.  
  72. local LOOT_SELF_REGEX = gsub(LOOT_ITEM_SELF, "%%s", "(.+)") --"You receive item: %s."
  73. local LOOT_PUSHED_REGEX = gsub(LOOT_ITEM_PUSHED_SELF, "%%s", "(.+)") --"You receive loot: %s."
  74.  
  75. function AutoLoot_IncomingLoot(message)
  76.     local itemLink = string.match(message, LOOT_SELF_REGEX) or string.match(message, LOOT_PUSHED_REGEX)
  77.     if itemLink then
  78.         local itemId = GetItemIdFromLink(itemLink)
  79.         local _, _, itemRarity = GetItemInfo(itemLink)
  80.        
  81.         if tContains(AutoLootTable, itemId) and (itemRarity >= 3) then
  82.             LootWonAlertFrame_ShowAlert(itemLink)
  83.             for i=1, #LOOT_WON_ALERT_FRAMES do
  84.                 local frame = LOOT_WON_ALERT_FRAMES[i];
  85.                 if ( frame:IsShown() ) then
  86.                     local RarityText = ITEMNAME[itemRarity]
  87.                     local color = ITEM_QUALITY_COLORS[itemRarity];
  88.                     frame.Label:SetText(format(RarityText, _G["ITEM_QUALITY"..itemRarity.."_DESC"]))
  89.                     frame.Label:SetVertexColor(color.r, color.g, color.b);
  90.                     frame.Label:SetPoint('TOPLEFT', frame.Icon, 'TOPRIGHT', 7, 3)
  91.                 end
  92.             end
  93.         end
  94.     end
  95. end

Edit: More code
For now i switched to this code as i have no idea how i manipulate the frames Blizzard creates properly, so im just spawning my own based on blizzards code.

Lua Code:
  1. --AutoLootfix, EasyLoot, Dugi stuff
  2. local f = CreateFrame"Frame"
  3. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  4. f:RegisterEvent("CVAR_UPDATE")
  5.  
  6. local AutoLootTable = {}
  7. local twipe = table.wipe
  8. local UpdateAutoLootStatus = function(value)
  9.     if tonumber(value) == 1 then
  10.         f:RegisterEvent("LOOT_OPENED")
  11.         f:RegisterEvent("CHAT_MSG_LOOT")
  12.     else
  13.         f:UnregisterEvent("LOOT_OPENED")
  14.         f:UnregisterEvent("CHAT_MSG_LOOT")
  15.     end
  16. end
  17.  
  18. IsAutoLootKeyDown = function()
  19.     -- Possible values: ALT, CTRL, SHIFT, NONE
  20.     local key = InterfaceOptionsControlsPanelAutoLootKeyDropDown:GetValue()
  21.     if key ~= "NONE" then
  22.         if key == "CTRL" then key = "CONTROL" end
  23.         local first, rest = key:sub(1, 1), key:sub(2):lower()
  24.         return _G[("Is%s%sKeyDown"):format(first, rest)]()
  25.     end
  26. end
  27.  
  28. local function GetItemIdFromLink(link)
  29.     return tonumber(link:match(".+|Hitem:([^:]+):.+"))
  30. end
  31.  
  32. f:SetScript("OnEvent", function(self, event, ...)
  33.     if event == "PLAYER_ENTERING_WORLD" then
  34.         UpdateAutoLootStatus(GetCVar"autoLootDefault")
  35.     elseif event == "CVAR_UPDATE" then
  36.         local glStr, value = ...
  37.         if glStr == "AUTO_LOOT_DEFAULT_TEXT" then
  38.             UpdateAutoLootStatus(value)
  39.         end
  40.     elseif event == "LOOT_OPENED" and not IsAutoLootKeyDown() then
  41.             twipe(AutoLootTable)
  42.             for i = GetNumLootItems(), 1, -1 do
  43.                 local lootLink = GetLootSlotLink(i)
  44.                 if lootLink then
  45.                     local itemId = GetItemIdFromLink(lootLink)
  46.                     tinsert(AutoLootTable, itemId)
  47.                 end
  48.                 LootSlot(i)
  49.             end
  50.             if not (IsInInstance() and GetNumGroupMembers() > 1) then
  51.                 if (ElvLootFrame:IsShown()) then
  52.                     ElvLootFrame:Hide()
  53.                 elseif (LootFrame:IsShown()) then
  54.                     LootFrame:Hide()
  55.                 end
  56.             end
  57.     elseif (event=="CHAT_MSG_LOOT") then
  58.         local message, sender, language, channelString, target, flags, _, channelNumber, channelName, _, _ = ...
  59.         AutoLoot_IncomingLoot(message)
  60.     end
  61. end)
  62.  
  63. local ITEMNAME = {
  64.     [LE_ITEM_QUALITY_COMMON] = "Common",
  65.     [LE_ITEM_QUALITY_UNCOMMON] = "Uncommon",
  66.     [LE_ITEM_QUALITY_EPIC] = "Epic",
  67.     [LE_ITEM_QUALITY_RARE] = "Rare",
  68.     [LE_ITEM_QUALITY_LEGENDARY] = "Legendary",
  69.     [LE_ITEM_QUALITY_HEIRLOOM] = "Heirloom"
  70. }
  71.  
  72. local LOOT_SELF_REGEX = gsub(LOOT_ITEM_SELF, "%%s", "(.+)") --"You receive item: %s."
  73. local LOOT_PUSHED_REGEX = gsub(LOOT_ITEM_PUSHED_SELF, "%%s", "(.+)") --"You receive loot: %s."
  74.  
  75. function AutoLoot_IncomingLoot(message)
  76.     local itemLink = string.match(message, LOOT_SELF_REGEX) or string.match(message, LOOT_PUSHED_REGEX)
  77.     if itemLink then
  78.         local itemId = GetItemIdFromLink(itemLink)
  79.         local itemName, _, itemRarity = GetItemInfo(itemLink)
  80.        
  81.         if tContains(AutoLootTable, itemId) and (itemRarity >= 3) then
  82.             LootMagicFrame_ShowAlert(itemLink)
  83.         end
  84.     end
  85. end
  86.  
  87. function LootMagicFrame_ShowAlert(itemLink, quantity)
  88.     local frame;
  89.     for i=1, #LOOT_WON_ALERT_FRAMES do
  90.         local lootWon = LOOT_WON_ALERT_FRAMES[i];
  91.         if ( not lootWon:IsShown() ) then
  92.             frame = lootWon;
  93.             break;
  94.         end
  95.     end
  96.  
  97.     if ( not frame ) then
  98.         frame = CreateFrame("Button", nil, UIParent, "LootWonAlertFrameTemplate");
  99.         table.insert(LOOT_WON_ALERT_FRAMES, frame);
  100.     end
  101.  
  102.     LootMagicFrame_SetUp(frame, itemLink, quantity);
  103.     AlertFrame_AnimateIn(frame);
  104.     AlertFrame_FixAnchors();
  105. end
  106.  
  107. local LOOTMAGICALERTFRAME={
  108.     Default = { bgOffsetX=0, bgOffsetY=0, labelOffsetX=7, labelOffsetY=3, labelText=YOU_WON_LABEL, glowAtlas="loottoast-glow"},
  109.     Horde = { bgOffsetX=-1, bgOffsetY=-1, labelOffsetX=7, labelOffsetY=3, labelText=YOU_EARNED_LABEL, pvpAtlas="loottoast-bg-horde", glowAtlas="loottoast-glow"},
  110.     Alliance = { bgOffsetX=-1, bgOffsetY=-1, labelOffsetX=7, labelOffsetY=3, labelText=YOU_EARNED_LABEL, pvpAtlas="loottoast-bg-alliance", glowAtlas="loottoast-glow"},
  111. }
  112. function LootMagicFrame_SetUp(self, itemLink, quantity)
  113.     local itemName, itemHyperLink, itemRarity, _, _, _, _, _, _, itemTexture = GetItemInfo(itemLink);
  114.  
  115.  
  116.     local windowInfo = LOOTMAGICALERTFRAME.Default;
  117.     if( showFactionBG ) then
  118.         local factionGroup = UnitFactionGroup("player");
  119.         windowInfo = LOOTMAGICALERTFRAME[factionGroup]
  120.         self.PvPBackground:SetAtlas(windowInfo.pvpAtlas, true);
  121.         self.PvPBackground:SetPoint("CENTER", windowInfo.bgOffsetX, windowInfo.bgOffsetY);
  122.         self.Background:Hide();
  123.         self.BGAtlas:Hide();
  124.         self.PvPBackground:Show(); 
  125.     else
  126.         if ( windowInfo.bgAtlas ) then
  127.             self.Background:Hide();
  128.             self.BGAtlas:Show();
  129.             self.BGAtlas:SetAtlas(windowInfo.bgAtlas);
  130.             self.BGAtlas:SetPoint("CENTER", windowInfo.bgOffsetX, windowInfo.bgOffsetY);
  131.         else
  132.             self.Background:SetPoint("CENTER", windowInfo.bgOffsetX, windowInfo.bgOffsetY);
  133.             self.Background:Show();
  134.             self.BGAtlas:Hide();
  135.         end
  136.         self.PvPBackground:Hide();
  137.     end
  138.     self.glow:SetAtlas(windowInfo.glowAtlas);
  139.     self.IconBorder:SetShown(not windowInfo.noIconBorder);
  140.     if ( windowInfo.iconUnderBG ) then
  141.         self.Icon:SetDrawLayer("BACKGROUND");
  142.     else
  143.         self.Icon:SetDrawLayer("BORDER");
  144.     end
  145.    
  146.     local color = ITEM_QUALITY_COLORS[itemRarity];
  147.     local RarityText = ITEMNAME[itemRarity]
  148.     self.Label:SetText(format(RarityText, _G["ITEM_QUALITY"..itemRarity.."_DESC"]));
  149.     self.Label:SetVertexColor(color.r, color.g, color.b);
  150.     self.Label:SetPoint("TOPLEFT", self.Icon, "TOPRIGHT", windowInfo.labelOffsetX, windowInfo.labelOffsetY);
  151.  
  152.     self.Icon:SetTexture(itemTexture);
  153.     self.ItemName:SetText(itemName);
  154.    
  155.     self.ItemName:SetVertexColor(color.r, color.g, color.b);
  156.     self.IconBorder:SetTexCoord(unpack(LOOT_BORDER_QUALITY_COORDS[itemRarity] or LOOT_BORDER_QUALITY_COORDS[LE_ITEM_QUALITY_UNCOMMON]));
  157.  
  158.     self.RollTypeIcon:Hide();
  159.     self.RollValue:Hide();
  160.     self.SpecIcon:Hide();
  161.     self.SpecRing:Hide();
  162.     self.hyperlink = itemHyperLink;
  163.     self:SetScript('OnClick', function()
  164.         local itemID = GetItemIDFromHyperlink(self.hyperlink);
  165.         if itemID then
  166.             ToggleAllBags();
  167.         end
  168.     end)
  169.  
  170.  
  171.     --PlaySoundKitID(31578);    --UI_EpicLoot_Toast
  172. end

Last edited by Shenj : 11-04-14 at 08:15 AM.
  Reply With Quote
11-05-14, 11:18 PM   #6
Shenj
A Murloc Raider
Join Date: Feb 2011
Posts: 5
As the Nature of my Addon has changed, it no longer is a AutoLoot addon per se as im now using Blizzards autoloot itself and mine is pretty much just doing the Alert & instant hide of loot window, not sure why but i had to use OnUpdate to hide the frame because doing it at LOOT_OPENED event would break Blizzards autoloot, its still incomplete but im starting to be unable to improve it by much because of my lack of knowledge.

If i notice it failing to auto-loot again i will have to revert to force looting it.

Lua Code:
  1. --Credits AutoLootFix, Dugi
  2. local f = CreateFrame("Frame")
  3. f:RegisterEvent("PLAYER_ENTERING_WORLD")
  4. f:RegisterEvent("CVAR_UPDATE")
  5.  
  6. local LootAlertItems = {}
  7. local twipe = table.wipe
  8. local tinsert = table.insert
  9. local inInstance, instanceType
  10. local rarityThreshold = 3
  11.  
  12. local UpdateAutoLootStatus = function(value)
  13.     if tonumber(value) == 1 then
  14.         f:RegisterEvent("LOOT_OPENED")
  15.         f:RegisterEvent("CHAT_MSG_LOOT")
  16.     else
  17.         f:UnregisterEvent("LOOT_OPENED")
  18.         f:UnregisterEvent("CHAT_MSG_LOOT")
  19.     end
  20. end
  21.  
  22. IsAutoLootKeyDown = function()
  23.     -- Possible values: ALT, CTRL, SHIFT, NONE
  24.     local key = InterfaceOptionsControlsPanelAutoLootKeyDropDown:GetValue()
  25.     if key ~= "NONE" then
  26.         if key == "CTRL" then key = "CONTROL" end
  27.         local first, rest = key:sub(1, 1), key:sub(2):lower()
  28.         return _G[("Is%s%sKeyDown"):format(first, rest)]()
  29.     end
  30. end
  31.  
  32. local function GetItemIdFromLink(link)
  33.     return tonumber(link:match(".+|Hitem:([^:]+):.+"))
  34. end
  35.  
  36. f:SetScript("OnEvent", function(self, event, ...)
  37.     if event == "PLAYER_ENTERING_WORLD" then
  38.         inInstance, instanceType = IsInInstance()
  39.         UpdateAutoLootStatus(GetCVar"autoLootDefault")
  40.     elseif event == "CVAR_UPDATE" then
  41.         local glStr, value = ...
  42.         if glStr == "AUTO_LOOT_DEFAULT_TEXT" then
  43.             UpdateAutoLootStatus(value)
  44.         end
  45.     elseif event == "LOOT_OPENED" then
  46.         twipe(LootAlertItems)
  47.         local numItems = GetNumLootItems()
  48.         for i = numItems, 1, -1 do
  49.             local lootLink = GetLootSlotLink(i)
  50.             local _, _, _, rarity, locked = GetLootSlotInfo(i)
  51.             if lootLink and rarity >= rarityThreshold then
  52.                 local itemId = GetItemIdFromLink(lootLink)
  53.                 tinsert(LootAlertItems, itemId)
  54.             end
  55.             --LootSlot(i)
  56.         end
  57.         if not IsAutoLootKeyDown() then
  58.             f:SetScript("OnUpdate", LootAlert_OnUpdate);
  59.         end
  60.     elseif (event=="CHAT_MSG_LOOT") then
  61.         local message, sender, language, channelString, target, flags, _, channelNumber, channelName, _, _ = ...
  62.         LootAlert(message)
  63.     end
  64. end)
  65.  
  66. function LootAlert_OnUpdate(self, elapsed)
  67.     if not (inInstance and GetNumGroupMembers() > 0) then
  68.         if (ElvLootFrame:IsShown()) then
  69.             ElvLootFrame:Hide()
  70.         elseif (LootFrame:IsShown()) then
  71.             LootFrame:Hide()
  72.         end
  73.     end
  74.     self:SetScript("OnUpdate", nil);
  75. end
  76.  
  77. local ITEMNAME = {
  78.     [LE_ITEM_QUALITY_COMMON] = "Common",
  79.     [LE_ITEM_QUALITY_UNCOMMON] = "Uncommon",
  80.     [LE_ITEM_QUALITY_EPIC] = "Epic",
  81.     [LE_ITEM_QUALITY_RARE] = "Rare",
  82.     [LE_ITEM_QUALITY_LEGENDARY] = "Legendary",
  83.     [LE_ITEM_QUALITY_HEIRLOOM] = "Heirloom"
  84. }
  85.  
  86. local LOOT_SELF_REGEX = gsub(LOOT_ITEM_SELF, "%%s", "(.+)") --"You receive item: %s."
  87. local LOOT_PUSHED_REGEX = gsub(LOOT_ITEM_PUSHED_SELF, "%%s", "(.+)") --"You receive loot: %s."
  88.  
  89. function LootAlert(message)
  90.     local itemLink = string.match(message, LOOT_PUSHED_REGEX) or string.match(message, LOOT_SELF_REGEX)
  91.     if itemLink then
  92.         local itemId = GetItemIdFromLink(itemLink)
  93.         local itemName,_,_,_,_, Type, subType = GetItemInfo(itemLink)
  94.         if tContains(LootAlertItems, itemId) then
  95.             if (instanceType ~= "raid" and GetNumGroupMembers() == 0) or GetLootMethod() == "personalloot" then
  96.                 LootAlertFrame_ShowAlert(itemLink)
  97.             elseif subType == "Mount" or subType == "Companion Pets" or Type == "Recipe" then
  98.                 LootAlertFrame_ShowAlert(itemLink)
  99.             end
  100.         end
  101.     end
  102. end
  103.  
  104. function LootAlertFrame_ShowAlert(itemLink, quantity)
  105.     local frame;
  106.     for i=1, #LOOT_WON_ALERT_FRAMES do
  107.         local lootWon = LOOT_WON_ALERT_FRAMES[i];
  108.         if ( not lootWon:IsShown() ) then
  109.             frame = lootWon;
  110.             break;
  111.         end
  112.     end
  113.  
  114.     if ( not frame ) then
  115.         frame = CreateFrame("Button", nil, UIParent, "LootWonAlertFrameTemplate");
  116.         table.insert(LOOT_WON_ALERT_FRAMES, frame);
  117.     end
  118.  
  119.     LootAlertFrame_SetUp(frame, itemLink, quantity);
  120.     AlertFrame_AnimateIn(frame);
  121.     AlertFrame_FixAnchors();
  122. end
  123.  
  124. local LOOTALERTFRAME={
  125.     Default = { bgOffsetX=0, bgOffsetY=0, labelOffsetX=7, labelOffsetY=3, labelText=YOU_WON_LABEL, glowAtlas="loottoast-glow"},
  126.     Horde = { bgOffsetX=-1, bgOffsetY=-1, labelOffsetX=7, labelOffsetY=3, labelText=YOU_EARNED_LABEL, pvpAtlas="loottoast-bg-horde", glowAtlas="loottoast-glow"},
  127.     Alliance = { bgOffsetX=-1, bgOffsetY=-1, labelOffsetX=7, labelOffsetY=3, labelText=YOU_EARNED_LABEL, pvpAtlas="loottoast-bg-alliance", glowAtlas="loottoast-glow"},
  128. }
  129. function LootAlertFrame_SetUp(self, itemLink, quantity)
  130.     local itemName, itemHyperLink, itemRarity, _, _, _, _, _, _, itemTexture = GetItemInfo(itemLink);
  131.  
  132.  
  133.     local windowInfo = LOOTALERTFRAME.Default;
  134.     if( showFactionBG ) then
  135.         local factionGroup = UnitFactionGroup("player");
  136.         windowInfo = LOOTALERTFRAME[factionGroup]
  137.         self.PvPBackground:SetAtlas(windowInfo.pvpAtlas, true);
  138.         self.PvPBackground:SetPoint("CENTER", windowInfo.bgOffsetX, windowInfo.bgOffsetY);
  139.         self.Background:Hide();
  140.         self.BGAtlas:Hide();
  141.         self.PvPBackground:Show(); 
  142.     else
  143.         if ( windowInfo.bgAtlas ) then
  144.             self.Background:Hide();
  145.             self.BGAtlas:Show();
  146.             self.BGAtlas:SetAtlas(windowInfo.bgAtlas);
  147.             self.BGAtlas:SetPoint("CENTER", windowInfo.bgOffsetX, windowInfo.bgOffsetY);
  148.         else
  149.             self.Background:SetPoint("CENTER", windowInfo.bgOffsetX, windowInfo.bgOffsetY);
  150.             self.Background:Show();
  151.             self.BGAtlas:Hide();
  152.         end
  153.         self.PvPBackground:Hide();
  154.     end
  155.     self.glow:SetAtlas(windowInfo.glowAtlas);
  156.     self.IconBorder:SetShown(not windowInfo.noIconBorder);
  157.     if ( windowInfo.iconUnderBG ) then
  158.         self.Icon:SetDrawLayer("BACKGROUND");
  159.     else
  160.         self.Icon:SetDrawLayer("BORDER");
  161.     end
  162.    
  163.     local color = ITEM_QUALITY_COLORS[itemRarity];
  164.     local RarityText = ITEMNAME[itemRarity]
  165.     self.Label:SetText(format(RarityText, _G["ITEM_QUALITY"..itemRarity.."_DESC"]));
  166.     self.Label:SetVertexColor(color.r, color.g, color.b);
  167.     self.Label:SetPoint("TOPLEFT", self.Icon, "TOPRIGHT", windowInfo.labelOffsetX, windowInfo.labelOffsetY);
  168.  
  169.     self.Icon:SetTexture(itemTexture);
  170.     self.ItemName:SetText(itemName);
  171.    
  172.     self.ItemName:SetVertexColor(color.r, color.g, color.b);
  173.     self.IconBorder:SetTexCoord(unpack(LOOT_BORDER_QUALITY_COORDS[itemRarity] or LOOT_BORDER_QUALITY_COORDS[LE_ITEM_QUALITY_UNCOMMON]));
  174.  
  175.     self.RollTypeIcon:Hide();
  176.     self.RollValue:Hide();
  177.     self.SpecIcon:Hide();
  178.     self.SpecRing:Hide();
  179.     self.hyperlink = itemHyperLink;
  180.     self:SetScript('OnClick', function()
  181.         if(IsModifiedClick()) then
  182.             ChatEdit_InsertLink(self.hyperlink);
  183.         else
  184.             --This doesn't work with ElvUI
  185.             local bag = SearchBagsForItemLink(self.hyperlink);
  186.             if (bag >= 0) then
  187.                 OpenBag(bag);
  188.             end
  189.         end
  190.     end)
  191.  
  192.  
  193.     PlaySoundKitID(31578);  --UI_EpicLoot_Toast
  194. end

Last edited by Shenj : 11-06-14 at 12:27 AM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Search/Requests » AutoLootFix for 6.0

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off