Quantcast
WoWInterface - View Single Post - [HELP] script NOT working with Class identify
View Single Post
06-30-20, 01:42 PM   #4
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 547
It's possible the LOOT_CLOSED event is too early to use, since it fires before the last CHAT_MSG_LOOT event for everything you looted. I suggest using BAG_UPDATE_DELAYED, which fires once at the end of any bag updates. I also suggest using that filename variable instead, since the first return won't be "Mage" if your client is not English. The filename is an all-caps identifier that will always be the English name in every client. It's also possible that UnitClass doesn't return anything while addons are loading. It's not uncommon to wait for the ADDON_LOADED, PLAYER_LOGIN, or even PLAYER_ENTERING_WORLD events before requesting data.

I rearranged your code with my suggestions and cleaned it up a bit:

Lua Code:
  1. local UnitClass,GetContainerNumSlots,GetContainerItemInfo,PickupContainerItem,DeleteCursorItem,UseContainerItem,select
  2.     = UnitClass,GetContainerNumSlots,GetContainerItemInfo,PickupContainerItem,DeleteCursorItem,UseContainerItem,select
  3.  
  4. local _, class
  5.  
  6. local items = { -- abandon list
  7.  
  8.     --food
  9.     [4599] = true,
  10.     [4608] = true,
  11.  
  12. }
  13.  
  14. local open = { -- open list
  15.  
  16.     [2744] = true,
  17.     [5523] = true,
  18.     [5524] = true,
  19.     [7973] = true,
  20.     [15874] = true,
  21.     [20767] = true,
  22.     [21150] = true,
  23.  
  24. }
  25.  
  26. local f = CreateFrame("frame")
  27. f:RegisterEvent("PLAYER_LOGIN")
  28. f:RegisterEvent("BAG_UPDATE_DELAYED")
  29. f:SetScript("OnEvent", function(self, event, ...)
  30.     if event == "PLAYER_LOGIN" then
  31.         _, class = UnitClass("player")
  32.     else
  33.         for b = 0, 4 do
  34.             for s = 1, GetContainerNumSlots(b) do
  35.                 local id = select(10, GetContainerItemInfo(b, s))
  36.  
  37.                 if class == "MAGE" and items[id] then
  38.                     PickupContainerItem(b, s)
  39.                     DeleteCursorItem()
  40.                     --print("clean")
  41.                 end
  42.  
  43.                 if open[id] then
  44.                     UseContainerItem(b, s)
  45.                     --print("open")
  46.                 end
  47.             end
  48.         end
  49.     end
  50. end)
  Reply With Quote