Quantcast
WoWInterface - View Single Post - [HELP] script NOT working with Class identify
View Single Post
07-05-20, 07:40 AM   #5
sh4dowburn
A Murloc Raider
Join Date: Oct 2019
Posts: 7
Originally Posted by Kanegasi View Post
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)
thank you so much for the optimization of code,
BAG_UPDATE_DELAYED is much better LOOT_CLOSED in this case,
this really help me a lots.
  Reply With Quote