WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   [HELP] script NOT working with Class identify (https://www.wowinterface.com/forums/showthread.php?t=58071)

sh4dowburn 06-30-20 01:45 AM

[HELP] script NOT working with Class identify
 
hi guyz,
i wrote this script for auto abandon items and open stuffs,

lately, added CLASS to avoid some of my characater abandon valuable items,
but it's not working correctly(the items i need to abandon when i played mage its not working. so sorry for forgot to mention it.) and i dont know how to make it work.

pls help me out, thank you guyz...
btw, it's for classic.

Lua Code:
  1. local UnitClass,GetContainerNumSlots,GetContainerItemInfo,PickupContainerItem,DeleteCursorItem,UseContainerItem,select
  2.     = UnitClass,GetContainerNumSlots,GetContainerItemInfo,PickupContainerItem,DeleteCursorItem,UseContainerItem,select
  3.    
  4. local n, filename, Id = UnitClass("player")
  5. local x
  6. if (n == "Mage") then x = true else x = false end
  7.  
  8. local items = { -- abandon list
  9.  
  10.   --food
  11.   [4608] = x,
  12.   [4599] = x,
  13.  
  14. }
  15.  
  16. local open = { -- open list
  17.  
  18. [20767] = true,
  19. [2744] = true,
  20. [5523] = true,
  21. [5524] = true,
  22. [7973] = true,
  23. [15874] = true,
  24. [21150] = true,
  25.  
  26. }
  27.  
  28. local f = CreateFrame('Frame', nil, UIParent)
  29. f:RegisterEvent('LOOT_CLOSED')
  30. f:SetScript('OnEvent', function(self, event, ...)
  31.   for b = 0, 4 do
  32.     for s = 1, GetContainerNumSlots(b) do
  33.       local id = select(10,GetContainerItemInfo(b,s))
  34.  
  35.       if items[id] then PickupContainerItem(b,s) DeleteCursorItem()
  36.       --print("clean")
  37.       end
  38.  
  39.       if open[id] then UseContainerItem(b, s)
  40.       --print("open")
  41.       end
  42.     end
  43.   end
  44. end)

Kanegasi 06-30-20 02:07 AM

When asking help with code, please avoid the phrases "not working correctly" and "getting an error".

Instead of declaring the code "not working correctly", you need to be specific with what you want the code to do and what it is currently doing. Instead of saying "getting an error", you need to copy and paste the error wherever you're asking for help.

After reviewing your code, it should delete Cured Ham Steak and Raw Black Truffle from your bags while you are logged into a Mage, but it will leave those items alone while on any other character. It should also open the following items: Scum Covered Bag, Green Hills of Stranglethorn - Page 20, Small Barnacled Clam, Thick-shelled Clam, Big-mouth Clam, Soft-shelled Clam, and Iron Bound Trunk.

Is that what you want? Did you want to save those items on your Mage but delete them on other characters? Why do you want to open a Stranglethorn page? Did you verify the 10th return of GetContainerItemInfo is an actual item ID and not 0 or nil? Why are you using f as a variable twice?

sh4dowburn 06-30-20 03:27 AM

Quote:

Originally Posted by Kanegasi (Post 336254)
When asking help with code, please avoid the phrases "not working correctly" and "getting an error".

Instead of declaring the code "not working correctly", you need to be specific with what you want the code to do and what it is currently doing. Instead of saying "getting an error", you need to copy and paste the error wherever you're asking for help.

After reviewing your code, it should delete Cured Ham Steak and Raw Black Truffle from your bags while you are logged into a Mage, but it will leave those items alone while on any other character. It should also open the following items: Scum Covered Bag, Green Hills of Stranglethorn - Page 20, Small Barnacled Clam, Thick-shelled Clam, Big-mouth Clam, Soft-shelled Clam, and Iron Bound Trunk.

Is that what you want? Did you want to save those items on your Mage but delete them on other characters? Why do you want to open a Stranglethorn page? Did you verify the 10th return of GetContainerItemInfo is an actual item ID and not 0 or nil? Why are you using f as a variable twice?

So sorry for forgot to mention the exactly problem is,
i want to delete the items with X when i play Mage, but it doesnt delete it when i play mage.
i did check all item ids and all fine.

it was a mistake for using f as a variable twice, the first f was short for classfilename(correct f to filename now.).
run some test later, should be work now.

Kanegasi 06-30-20 01:42 PM

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)

sh4dowburn 07-05-20 07:40 AM

Quote:

Originally Posted by Kanegasi (Post 336267)
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.


All times are GMT -6. The time now is 07:42 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI