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:
Music = "Interface\\AddOns\\FreeBird\\freebird.mp3"
local Falling
local function freeBird_Loop()
if IsFalling() == false then
StopMusic()
Falling = false
end
if Falling then C_Timer.After(0.5, freeBird_Loop) end
end
local AuraInstanceID
local function testFalling()
if IsFalling() then
PlayMusic(Music)
Falling = true
freeBird_Loop()
end
end
local function freeBird_onEvent(self, event, unit, info)
if info.addedAuras then
for _, v in pairs(info.addedAuras) do
if v.spellId == 40120 then -- cata swift flight form
AuraInstanceID = v.auraInstanceID
StopMusic()
break
end
end
end
if info.removedAuraInstanceIDs then
for _, v in pairs(info.removedAuraInstanceIDs) do
if v == AuraInstanceID then
AuraInstanceID = nil
RunNextFrame(testFalling)
break
end
end
end
end
SLASH_FREEBIRD1 = "/fb1"
SlashCmdList["FREEBIRD"] = function(msg)
if msg == "original" then
Music = "Interface\\AddOns\\FreeBird\\freebird.mp3"
elseif msg == "harmonica" then
Music = "Interface\\AddOns\\FreeBird\\FreeBirdHarmonica.mp3"
else
print("/fb1 original, /fb1 harmonica")
end
end
local f = CreateFrame("Frame")
f:RegisterUnitEvent("UNIT_AURA", "player")
f:SetScript("OnEvent", freeBird_onEvent)