Thread Tools Display Modes
05-30-24, 06:22 PM   #1
Txeptsyip
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Jun 2021
Posts: 3
Can i check to see if a player has landed?

and also how can I check to see if a specific aura getting removed or added (druid flight form) is the one that just triggered the unit_aura event?

I'm basically trying to write an addon that plays the free bird solo when I cancel flight form in order to lose height quickly

here is what I have so far (the runnextframe is because otherwise you haven't had time to start falling when the isfalling check happens)

Lua Code:
  1. function freebird_onEvent (self, event, unit, info)
  2.     Unit = unit
  3.    
  4.     RunNextFrame(function() freebird_dothing() end)
  5. end
  6.  
  7. function freebird_dothing ()
  8.     if Unit == "player" then
  9.         if IsFalling() then
  10.             print("falling")
  11.             PlayMusic"Interface\\AddOns\\FreeBird\\freebird.mp3"
  12.         else
  13.             print("not falling")
  14.             StopMusic()
  15.         end
  16.     end
  17. end
  18.  
  19. local f = CreateFrame("Frame")
  20. f:RegisterEvent("UNIT_AURA")
  21. f:SetScript("OnEvent", freebird_onEvent)


I did find this https://wowpedia.fandom.com/wiki/UNIT_AURA and modifying part of the script it has an example I can get a message to print the spellID but I am unsure how I just directly access the spell ID (just going into.addedAuras.spellId does not appear to work)
  Reply With Quote
05-30-24, 07:02 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,917
There's probably a better way but maybe something along the lines of:

Lua Code:
  1. local AuraInstanceID
  2. local function TestFalling()
  3.     if IsFalling() then
  4.         PlayMusic("Interface\\AddOns\\FreeBird\\freebird.mp3")
  5.     end
  6. end
  7.  
  8. local function freebird_onEvent (self, event, unit, info)
  9.     if info.addedAuras then
  10.         for k, v in pairs(info.addedAuras) do
  11.             if v.spellId == 783 then -- travel form
  12.                 AuraInstanceID = v.auraInstanceID
  13.                 StopMusic()
  14.                 break
  15.             end
  16.         end
  17.     end
  18.     if info.removedAuraInstanceIDs then
  19.         for k, v in pairs(info.removedAuraInstanceIDs) do
  20.             if v == AuraInstanceID then
  21.                 AuraInstanceID = nil
  22.                 RunNextFrame(TestFalling)
  23.                 break
  24.             end
  25.         end
  26.     end
  27. end
  28.  
  29. local f = CreateFrame("Frame")
  30. f:RegisterUnitEvent("UNIT_AURA", "player")
  31. f:SetScript("OnEvent", freebird_onEvent)
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 05-30-24 at 11:19 PM.
  Reply With Quote
05-31-24, 03:57 AM   #3
Txeptsyip
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Jun 2021
Posts: 3
ah i see so i have to use that odd "in pairs" thing to access those values (I'm not entirely sure what that is doing i'm new to LUA and it does things in ways I don't like why can't I just use something nice like C#?)

anyway so I had a thought about the detecting if on ground thing and decided to try making a while loop that would check if falling and if not falling stop the music

as you can imagine that crashed my game and that's how I found out that a while loop in an addon will stop the entire game while it does its whiling

so I spun that off into its own function and did a recursive C_Timer.After as shown here https://wowpedia.fandom.com/wiki/API_C_Timer.After

this is the code I have now after taking what you did and adding my loop to it (this is for cata classic so the spellID has been changed to that and I remembered to take out my debug print statements this time)

I also added some slash commands under /fb1 (/fb1 original and /fb1 harmonica) and updated the .toc to make Music a saved variable

Lua Code:
  1. Music = "Interface\\AddOns\\FreeBird\\freebird.mp3"
  2.  
  3. local Falling
  4. local function freeBird_Loop()
  5.     if IsFalling() == false then
  6.         StopMusic()
  7.         Falling = false
  8.     end
  9.     if Falling then C_Timer.After(0.5, freeBird_Loop) end
  10. end
  11.  
  12. local AuraInstanceID
  13. local function testFalling()
  14.     if IsFalling() then
  15.         PlayMusic(Music)
  16.         Falling = true
  17.         freeBird_Loop()
  18.     end
  19. end
  20.  
  21. local function freeBird_onEvent(self, event, unit, info)
  22.     if info.addedAuras then
  23.         for _, v in pairs(info.addedAuras) do
  24.             if v.spellId == 40120 then -- cata swift flight form
  25.                 AuraInstanceID = v.auraInstanceID
  26.                 StopMusic()
  27.                 break
  28.             end
  29.         end
  30.     end
  31.     if info.removedAuraInstanceIDs then
  32.         for _, v in pairs(info.removedAuraInstanceIDs) do
  33.             if v == AuraInstanceID then
  34.                 AuraInstanceID = nil
  35.                 RunNextFrame(testFalling)
  36.                 break
  37.             end
  38.         end
  39.     end
  40. end
  41.  
  42. SLASH_FREEBIRD1 = "/fb1"
  43. SlashCmdList["FREEBIRD"] = function(msg)
  44.     if msg == "original" then
  45.         Music = "Interface\\AddOns\\FreeBird\\freebird.mp3"
  46.     elseif msg == "harmonica" then
  47.         Music = "Interface\\AddOns\\FreeBird\\FreeBirdHarmonica.mp3"
  48.     else
  49.         print("/fb1 original, /fb1 harmonica")
  50.     end
  51. end
  52.  
  53. local f = CreateFrame("Frame")
  54. f:RegisterUnitEvent("UNIT_AURA", "player")
  55. f:SetScript("OnEvent", freeBird_onEvent)

Last edited by Txeptsyip : 05-31-24 at 09:45 AM.
  Reply With Quote
05-31-24, 10:15 AM   #4
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,336
Originally Posted by Txeptsyip View Post
ah i see so i have to use that odd "in pairs" thing to access those values (I'm not entirely sure what that is doing ...)
for ... in is a variant of for that loops through a given iterator to obtain one or more values.
pairs() returns an iterator that loops through a table, returning all of its key-value pairs.

The combination of these is the standard way to loop through tables.

For more information:
Lua 5.1 Reference Manual §2.4.5 - For Statement
Lua 5.1 Reference Manual - pairs()



On another note, you should choose a unique name for any global variables you create. The Lua environment is shared among the entire UI including other addons running and name collisions are a possibility. Common practice is to prefix your variable name with the name of your addon. For example, your SavedVariable should be named something like FreeBird_Music.
__________________
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 : 05-31-24 at 10:39 AM.
  Reply With Quote
05-31-24, 11:19 AM   #5
Txeptsyip
A Defias Bandit
AddOn Author - Click to view addons
Join Date: Jun 2021
Posts: 3
Originally Posted by SDPhantom View Post
On another note, you should choose a unique name for any global variables you create. The Lua environment is shared among the entire UI including other addons running and name collisions are a possibility. Common practice is to prefix your variable name with the name of your addon. For example, your SavedVariable should be named something like FreeBird_Music.
yes someone in my guild just pointed that out to me so I changed it to FreeBirdSavedMusic because its long and has more words
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Can i check to see if a player has landed?


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