From 5e8578454a8c613097bdc2e2ceb72fea2d7774d3 Mon Sep 17 00:00:00 2001 From: atomaka Date: Wed, 29 Jun 2011 19:42:08 -0400 Subject: [PATCH] Use CHAT_MSG_LOOT as event. --- GemStacker.lua | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/GemStacker.lua b/GemStacker.lua index 744d8dc..1d34b9b 100644 --- a/GemStacker.lua +++ b/GemStacker.lua @@ -1,40 +1,27 @@ GemStacker = LibStub('AceAddon-3.0'):NewAddon('GemStacker','AceConsole-3.0','AceEvent-3.0'); local core = GemStacker; -core.gems = {}; -core.lastGem = false; function core:OnInitialize() end function core:OnEnable() - core.gems['Puissant Dream Emerald'] = true; - --use chat_msg_loot later - self:RegisterEvent('UNIT_SPELLCAST_SUCCEEDED','FindGemCast'); + self:RegisterEvent('CHAT_MSG_LOOT','StackGems'); end -function core:FindGemCast(_,unitId,spell,...) - print('GemStacker: Casted ',spell); +function core:StackGems(_,message) --should receive something like "player","Reckless Ember Topaz","",2,73369 - if(unitId ~= 'player') then return end; - if(not core.gems[spell]) then return end; - - core.lastGem = spell; - self:RegisterEvent('BAG_UPDATE','StackGem'); -end + if(not string.find(message,'You create')) then return end; + local gem = message:match("%[(.-)%]"); -function core:StackGem(...) - print('GemStacker: StackGem'); - if(not core.lastGem) then return end; - local sourceContainer,sourceSlot,destContainer,destSlot = -1,-1,-1,-1; for bag = 0,4 do for slot = 1,GetContainerNumSlots(bag) do itemId = GetContainerItemID(bag,slot) if(itemId) then itemName = GetItemInfo(itemId); - if(core.lastGem == itemName) then + if(gem == itemName) then local _,count = GetContainerItemInfo(bag,slot); if(count == 1 and sourceContainer < 0) then sourceContainer = bag; @@ -51,8 +38,5 @@ function core:StackGem(...) if(sourceContainer ~= -1 and destContainer ~= -1) then PickupContainerItem(sourceContainer,sourceSlot); PickupContainerItem(destContainer,destSlot) - end - - core.lastGem = false; - self:UnregisterEvent('BAG_UPDATE'); + end end \ No newline at end of file