View Single Post
07-31-19, 01:49 AM   #5
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,326
A simpler way would be to wait until later in the loading process to hook the tooltip and create a prehook the old fashioned way.
Lua Code:
  1. local loader=CreateFrame("Frame");
  2. loader:RegisterForEvents("PLAYER_LOGIN");-- Register for an event that appears late in the loading process. This makes it more likely our hook is the last to be set up
  3. loader:SetScript("OnEvent",function()
  4.     local oldscript=GameTooltip:GetScript("OnTooltipSetItem");--    Save any previously registered scripts
  5.     GameTooltip:SetScript("OnTooltipSetItem",function(self,...)--   Futureproofing, support extra args to pass to previous scripts
  6. --      Add your text here
  7.  
  8. --      Run any other addons' functions
  9.         if oldscript then return oldscript(self,...); end
  10.     end);
  11. end);
This is done because GameTooltip:HookScript() sets up a posthook, meaning the function you give it runs after any script that's already there. A prehook in contrast runs before any existing function. No protected function should be run from tooltip code, so taint shouldn't be an issue here.

In any occasion, trying to place your addon's text in a certain spot in the tooltip opens up race conditions competing with any other addon that might have that same design choice. The best and most efficient option is to let it be and do nothing.
__________________
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 : 07-31-19 at 02:02 AM.
  Reply With Quote