WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   Old Addon Help! (FastDisenchant) (https://www.wowinterface.com/forums/showthread.php?t=52948)

Furchee 12-04-15 07:15 AM

Old Addon Help! (FastDisenchant)
 
Hi guys!

So I'm actually here because I'm rather miffed as to why this addon simply will not do it's job.
I've added the itemID's for WoD but it doesn't seem to want to loot regardless of which expansion.

Now I'm assuming blizzard changed something in the later expansions and broke this old addon and all I ask is someone to point me in the right direction of fixing this gem.

It's a rather simple coded thing and I'm sure the answer is quite obvious to those who have dealt with these types of codes before. *I code in sourcepawn so I understand the difference!

Anyway, without further delays here is the code!

Code:

local FastDEItems = {
        [774] = true, -- Malachite
        [818] = true, -- Tigerseye
        [1210] = true, -- Shadowgem
>>>>Cut out the list of items as there is quite a few!<<<<
}

function FastDisenchant_OnLoad()
        this:RegisterEvent("LOOT_OPENED");
end

function FastDisenchant_OnEvent(event)
        for slotnum = 1, GetNumLootItems() do
                if (not LootSlotIsItem(slotnum)) then return end

                local link = GetLootSlotLink(slotnum)
                local _, _, itemID = string.find(link, "item:(%d+)")

                itemID = tonumber(itemID);
                if (not itemID or not FastDEItems[itemID]) then return end
        end

        for slotnum = 1, GetNumLootItems() do LootSlot(slotnum) end
end


semlar 12-04-15 09:56 AM

You could try replacing LootSlotIsItem with LootSlotHasItem, it should be throwing an error since that function doesn't exist.

Furchee 12-04-15 04:18 PM

Just did what you've suggested and it still has no functionality.
Oddly enough I do not get any lua errors from it at all.

I suppose the code itself is fine but it simply does not auto-loot.

semlar 12-04-15 05:23 PM

Might have to replace "this:RegisterEvent" with "self:RegisterEvent".

If you look under "help" in the interface menu there's an option to display lua errors, they're probably turned off since this should definitely be throwing errors.

SDPhantom 12-04-15 07:01 PM

It that all the code or do you have an XML file with the frame in it?

In all honesty, for a simple addon like this, you could just hook LootFrame itself.
Lua Code:
  1. local ItemList={
  2.     [774]   =true,--    Malachite
  3.     [818]   =true,--    Tigerseye
  4.     [1210]  =true,--    Shadowgem
  5. --  etc...
  6. };
  7.  
  8. LootFrame:HookScript("OnEvent",function(self,event,...)
  9.     if event=="LOOT_OPENED" then
  10.         for i=1,GetNumLootItems() do
  11.             local id=tonumber((GetLootSlotLink(i) or ""):match("|Hitem:(%d+)")) or 0;
  12.             if ItemList[id] then LootSlot(i); end
  13.         end
  14.     end
  15. end);
Note: Line 12 uses a casting method to insure id is given a number to index the lookup table. This is given the inherent behavior of X or Y in which if X evaluates to a false condition (false or nil), Y is used.



PS: From the code example, it appears to be mixed with code from vanilla WoW. Globals like this are no longer in use.

Furchee 12-04-15 07:02 PM

Quote:

Originally Posted by semlar (Post 312152)
Might have to replace "this:RegisterEvent" with "self:RegisterEvent".

If you look under "help" in the interface menu there's an option to display lua errors, they're probably turned off since this should definitely be throwing errors.

Oh I do in fact have them set on, it just never prompts me with a window. Is there a way to bring up the window without forcing an error ?
With that said, I just swapped out that piece of info and got this:
Code:

Message: Interface\AddOns\FastDisenchant\FastDisenchant.lua:120: attempt to index global 'self' (a nil value)
Time: 12/04/15 17:01:43
Count: 1
Stack: Interface\AddOns\FastDisenchant\FastDisenchant.lua:120: in function `FastDisenchant_OnLoad'
[string "*:OnLoad"]:1: in function <[string "*:OnLoad"]:1>

Locals: (*temporary) = nil
(*temporary) = nil
(*temporary) = nil
(*temporary) = "attempt to index global 'self' (a nil value)"


Furchee 12-04-15 07:12 PM

Quote:

Originally Posted by SDPhantom (Post 312155)
It that all the code or do you have an XML file with the frame in it?

In all honesty, for a simple addon like this, you could just hook LootFrame itself.
[[Snipped]]
Note: Line 12 uses a casting method to insure id is given a number to index the lookup table. This is given the inherent behavior of X or Y in which if X evaluates to a false condition (false or nil), Y is used.



PS: From the code example, it appears to be mixed with code from vanilla WoW. Globals like this are no longer in use.

Yes actually, there is a frame file that I see calls out the two functions.
With your code I do not see a way to call the functions with the xml file though? -if I'm understanding this right.
XML file :
Code:

<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
        <Script file="FastDisenchant.lua"/>

        <Frame name="FastDisenchant_Frame">
                <Scripts>
                        <OnLoad>
                                FastDisenchant_OnLoad();
                        </OnLoad>
                        <OnEvent>
                                FastDisenchant_OnEvent(event);
                        </OnEvent>
                </Scripts>
        </Frame>
</Ui>


Edit: Fixed! I simply replaced FastDisenchant_OnLoad(); with LootFrame:HookScript(); and removed the <OnEvent> section of the code.
Thank you so much!

SDPhantom 12-04-15 09:20 PM

Quote:

Originally Posted by Furchee (Post 312157)
With your code I do not see a way to call the functions with the xml file though?

The XML file isn't needed since it doesn't create its own frame to run the Lua code. It simply hooks into the original frame that responds to the event and runs itself after that frame is done with its own code. This is what LootFrame:HookScript() is doing. The only thing needed is to reference the Lua file directly from your ToC instead of going through the XML file.

For future reference, you should avoid using XML as it's exceedingly difficult to debug. If something is wrong with your syntax, the entire file fails to load with no notice. There are very few examples where XML is necessary. You can do almost everything using pure Lua.

Furchee 12-05-15 12:15 AM

Quote:

Originally Posted by SDPhantom (Post 312159)
The XML file isn't needed since it doesn't create its own frame to run the Lua code. It simply hooks into the original frame that responds to the event and runs itself after that frame is done with its own code. This is what LootFrame:HookScript() is doing. The only thing needed is to reference the Lua file directly from your ToC instead of going through the XML file.

For future reference, you should avoid using XML as it's exceedingly difficult to debug. If something is wrong with your syntax, the entire file fails to load with no notice. There are very few examples where XML is necessary. You can do almost everything using pure Lua.

Thanks for the clarification on that. I will apply what you've said.
Glad to be learning more about this!


All times are GMT -6. The time now is 09:48 PM.

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