Thread Tools Display Modes
12-04-15, 07:15 AM   #1
Furchee
A Murloc Raider
 
Furchee's Avatar
Join Date: Dec 2015
Posts: 5
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
  Reply With Quote
12-04-15, 09:56 AM   #2
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
You could try replacing LootSlotIsItem with LootSlotHasItem, it should be throwing an error since that function doesn't exist.
  Reply With Quote
12-04-15, 04:18 PM   #3
Furchee
A Murloc Raider
 
Furchee's Avatar
Join Date: Dec 2015
Posts: 5
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.
  Reply With Quote
12-04-15, 05:23 PM   #4
semlar
A Pyroguard Emberseer
 
semlar's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 1,060
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.
  Reply With Quote
12-04-15, 07:01 PM   #5
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
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.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 12-04-15 at 07:07 PM.
  Reply With Quote
12-04-15, 07:02 PM   #6
Furchee
A Murloc Raider
 
Furchee's Avatar
Join Date: Dec 2015
Posts: 5
Originally Posted by semlar View Post
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)"
  Reply With Quote
12-04-15, 07:12 PM   #7
Furchee
A Murloc Raider
 
Furchee's Avatar
Join Date: Dec 2015
Posts: 5
Originally Posted by SDPhantom View Post
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!

Last edited by Furchee : 12-04-15 at 07:17 PM.
  Reply With Quote
12-04-15, 09:20 PM   #8
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by Furchee View Post
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.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 12-04-15 at 09:22 PM.
  Reply With Quote
12-05-15, 12:15 AM   #9
Furchee
A Murloc Raider
 
Furchee's Avatar
Join Date: Dec 2015
Posts: 5
Originally Posted by SDPhantom View Post
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!
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Old Addon Help! (FastDisenchant)

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