Thread Tools Display Modes
04-14-24, 01:56 PM   #1
Benalish
A Flamescale Wyrmkin
 
Benalish's Avatar
Join Date: Dec 2012
Posts: 123
Spell power increase message and animation

Hello,
I created this script for display a message whenever spell power get increased. I'd like to make the animation repeat only once. Are there better methods than the ones I'm using? What about spell power 'ping'?


Lua Code:
  1. local fs = UIParent:CreateFontString(nil, "OVERLAY", "GameTooltipText")
  2. fs:SetPoint("CENTER")
  3. fs:SetFont("Fonts\\FRIZQT__.TTF", 24, "OUTLINE")
  4. fs:SetText("Spell power increased!")
  5. fs:SetAlpha(0)
  6. fs.flasher = fs:CreateAnimationGroup()
  7.  
  8. fs.flasher:SetLooping("NONE")
  9.  
  10. fs.flasher:SetScript(
  11.     "OnUpdate",
  12.     function()
  13.         if fs:GetAlpha() == 0 and fs.flasher:IsPlaying() then
  14.             fs:Hide()
  15.         end
  16.     end
  17. )
  18.  
  19. local fade = fs.flasher:CreateAnimation("Alpha")
  20. fade:SetDuration(5)
  21. fade:SetChange(-1)
  22. fade:SetOrder(1)
  23.  
  24. local spellDmg = GetSpellBonusDamage(6)
  25.  
  26. local onupdate = CreateFrame("Frame")
  27.  
  28. local spellDmg = GetSpellBonusDamage(6)
  29.  
  30. onupdate:SetScript("OnUpdate", function(self,elapsed)
  31.     if GetSpellBonusDamage(6) > spellDmg then
  32.         fs:SetAlpha(1)
  33.         fs:Show()
  34.         fs.flasher:Play()
  35.     end
  36.     spellDmg = GetSpellBonusDamage(6)
  37. end)
  Reply With Quote
04-14-24, 04:37 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,327
This seems to work. I changed it to initialize on PLAYER_LOGIN and listen for SPELL_POWER_CHANGED. Many character-related data functions don't return meaningful values on load and require initial data from the server. This is what PLAYER_LOGIN signifies. Blizzard's PaperDollFrame reacts to PLAYER_DAMAGE_DONE_MODS along with a handful of others. As these events tend to fire in rapid bursts, Blizzard opts to hand the events off to an OnUpdate script in order to consolidate these bursts into a single update call for performance reasons. This code doesn't do any significant processing, so it isn't really a problem for us.

I utilize the AnimationGroup's OnPlay and OnFinished scripts to trigger show/hide. It may not be necessary. I didn't find documentation on AlphaAnimation:SetChange() existing. It may be a depreciated function. :SetFromAlpha() and :SetToAlpha() work fine. I added a short fade in animation to smooth out the effect. This also uses Blizzard's EventRegistry instead of creating an invisible frame to handle events.

This was tested on Wrath Classic, other clients may need further adjustments.

Lua Code:
  1. local AlertText=UIParent:CreateFontString(nil,"OVERLAY","GameTooltipText");
  2. AlertText:SetPoint("CENTER");
  3. AlertText:SetFont("Fonts\\FRIZQT__.TTF",24,"OUTLINE");
  4. AlertText:SetText("Shadow power increased!");
  5. AlertText:SetAlpha(0);
  6. AlertText:Hide();
  7.  
  8. local AlertAnimationGroup=AlertText:CreateAnimationGroup();
  9. AlertAnimationGroup:SetLooping("NONE");
  10. AlertAnimationGroup:SetScript("OnPlay",function() AlertText:Show(); end);
  11. AlertAnimationGroup:SetScript("OnFinished",function() AlertText:Hide(); end);
  12.  
  13. local AlertAnimationFadeIn=AlertAnimationGroup:CreateAnimation("Alpha");
  14. AlertAnimationFadeIn:SetOrder(1);
  15. AlertAnimationFadeIn:SetDuration(0.5);
  16. AlertAnimationFadeIn:SetFromAlpha(0);
  17. AlertAnimationFadeIn:SetToAlpha(1);
  18.  
  19. local AlertAnimationFadeOut=AlertAnimationGroup:CreateAnimation("Alpha");
  20. AlertAnimationFadeIn:SetOrder(2);
  21. AlertAnimationFadeIn:SetDuration(4.5);
  22. AlertAnimationFadeIn:SetFromAlpha(1);
  23. AlertAnimationFadeIn:SetToAlpha(0);
  24.  
  25. local OnShadowPowerChanged; do
  26.     local ShadowPowerCache;
  27.     function OnShadowPowerChanged()
  28.         local bonus=GetSpellBonusDamage(6);
  29.         if ShadowPowerCache and bonus>ShadowPowerCache then
  30.             if AlertAnimationGroup:IsPlaying() then
  31.                 AlertAnimationGroup:Restart();
  32.             else AlertAnimationGroup:Play(); end
  33.         end
  34.  
  35.         ShadowPowerCache=bonus;
  36.     end
  37. end
  38.  
  39. EventRegistry:RegisterFrameEventAndCallback("PLAYER_LOGIN",OnShadowPowerChanged);
  40. EventRegistry:RegisterFrameEventAndCallback("SPELL_POWER_CHANGED",OnShadowPowerChanged);
__________________
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 : 04-14-24 at 04:44 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Spell power increase message and animation


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