View Single Post
04-16-24, 06:43 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,950
It might be because it is processing things a bit too soon.

You could see if using the MERCHANT_UPDATE event ( at least the first time around ) will be the best time to do any semi automatic transactions.

Looking at the MerchantFrame Blizzard code ( https://github.com/Gethe/wow-ui-sour...chantFrame.lua ) The updating of the merchant frame doesn't occur until the end of the Merchant_Show function. So it is possible that the following is happening.



Lua Code:
  1. function MerchantFrame_MerchantShow()
  2.     ShowUIPanel(MerchantFrame);
  3.  
  4. >>>> MERCHANT_SHOW triggers here perhaps
  5.  
  6.     if ( not MerchantFrame:IsShown() ) then
  7.         CloseMerchant();
  8.         return;
  9.     end
  10.     MerchantFrame.page = 1;
  11.     MerchantFrame_UpdateCurrencies();
  12.     MerchantFrame_Update();
  13.  
  14. >>>> MERCHANT_UPDATE triggers here perhaps
  15.  
  16. end

Depending on how often MERCHANT_UPDATE triggers, you might need to UnRegister it when it first triggers and have registering it happen when the MERCHANT_SHOW event triggers.


For example:
Lua Code:
  1. local addonName, addon = ...
  2.  
  3. -- Whatever Data or Functionality that needs to be available before
  4. -- It is accessed in AutoPurchaseSelectedItems function
  5. -- Either in this file or in a file listed earlier in the toc file
  6.  
  7. local function AutoPurchaseSelectedItems()
  8.     -- Whatever Buying from Merchant processing you wanted to do
  9. end
  10.  
  11. local function OnEvent(self,event,...)
  12.     if event == "MERCHANT_SHOW" then
  13.         self:RegisterEvent("MERCHANT_UPDATE")
  14.     elseif event == "MERCHANT_UPDATE" then
  15.         self:UnregisterEvent(event)
  16.         AutoPurchaseSelectedItems()
  17.     end
  18. end
  19.  
  20. local eventWatcher = CreateFrame("Frame")
  21. eventWatcher:RegisterEvent("MERCHANT_SHOW")
  22. eventWatcher:SetScript("OnEvent",OnEvent)


-- OR --

If that doesn't work. You could try hooking into the MerchantFrame_MerchantShow function to add your functionality in place.

For example:

Lua Code:
  1. local addonName, addon = ...
  2.  
  3. -- Whatever Data or Functionality that needs to be available before
  4. -- It is accessed in AutoPurchaseSelectedItems function
  5. -- Either in this file or in a file listed earlier in the toc file
  6.  
  7. local function AutoPurchaseSelectedItems()
  8.     -- Whatever Buying from Merchant processing you wanted to do
  9. end
  10.  
  11. hooksecurefunc("MerchantFrame_MerchantShow", AutoPurchaseSelectedItems)
  12.  
  13. -- What this does is execute the Blizzard MerchantShow function and immediately execute your function.  You won't have access to any variables inside the Blizzard function but it might allow you to access the Merchant in the same way you are doing already, just after it does that initial update.
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote