View Single Post
10-20-16, 10:56 PM   #20
Krainz
A Wyrmkin Dreamwalker
Join Date: Oct 2016
Posts: 57
lua Code:
  1. local addon = CreateFrame("Frame");
  2. addon:RegisterEvent("PLAYER_LOGIN");
  3. addon:RegisterEvent("PLAYER_REGEN_DISABLED");
  4. addon:RegisterEvent("PLAYER_REGEN_ENABLED");
  5. addon:RegisterEvent("PLAYER_STARTED_MOVING");
  6. addon:RegisterEvent("PLAYER_STOPPED_MOVING");
  7.  
  8.  
  9. addon:SetScript("OnEvent", function(self, event, ...)
  10.  
  11.     if event == "PLAYER_LOGIN"
  12.     or event == "PLAYER_REGEN_DISABLED"
  13.     or event == "PLAYER_STOPPED_MOVING" then
  14.        
  15.         if not UnitAffectingCombat("player") then
  16.             C_Timer.After(3, UIFrameFadeOut(UIParent, 3, UIParent:GetAlpha(), 0));
  17.         end;
  18.     else
  19.         UIParent:SetAlpha(1);
  20.     end;
  21.    
  22.     if UnitAffectingCombat("player") then
  23.         UIParent:SetAlpha(1);
  24.     end;
  25. end);
  26.  
  27. addon:SetScript("OnUpdate", function(self, elapsed)
  28.  
  29.     local speed = GetUnitSpeed("player");
  30.     if speed ~=0 then
  31.         UIParent:SetAlpha(1);
  32.     else
  33.         if GetMouseFocus() then
  34.             if GetMouseFocus():GetName() ~= "WorldFrame" then
  35.                 UIParent:SetAlpha(1);
  36.             else
  37.                 if not UnitAffectingCombat("player") then
  38.                 C_Timer.After(3, UIFrameFadeOut(UIParent, 3, UIParent:GetAlpha(), 0))
  39.                 end;
  40.             end;
  41.         end;
  42.     end;
  43.    
  44.     if UnitName("mouseover") then
  45.         UIParent:SetAlpha(1);
  46.     end;
  47. end);

I also tried to work around the "timer" solution through C_Timer, but then I realized that the interaction was already happening after out of combat, but just delayed. The user must STAY idle for that amount of time in order for the interaction to be optimal.

It ended up working like a delayed time bomb. Very, very clunky.
  Reply With Quote