Play a sound file when you're mounted?
Hey,
I want to make an addon that plays "On the road again" when you mount. Then stops when you're unmounted, I want it to work it all kinds of mounts. Now, how would I go about doing this? Could someone help me? I've never made an addon before, I just think that sounds like an awesome idea. Thanks! |
Really simple. Just write a simple addon to check "IsMounted()" and "not IsMounted()".
www.wowwiki.com |
Hi!
You can make it like this: -- the file that will call your files: MyAddon.toc -- add the next code line MyAddon.lua -- the file that will contain the code: MyAddon.lua -- add the following code: -- create your addon's name space MyAddon = {} -- create a simple frame local frame = CreateFrame("Frame"); -- register event, might be another better to make this but this one was the nicest I've found frame:RegisterEvent("PLAYER_AURAS_CHANGED"); -- set the trigger to catch the event and call your function frame:SetScript("OnEvent", function(this, event, ...) MyAddon[event](MyAddon, ...) end; ); -- your function function MyAddon:PLAYER_AURAS_CHANGED() if(IsMounted()) then -- since this event triggers so many times, we better declare anything inside the case we want local soundFile = "path"; -- path is where your music will be -- Ex:Interface\\AddOns\\YourAddon\\YourMusic.mp3 PlayMusic(soundFile); else StopMusic(); end; end; I didnt test this, so no clue if is working. One drawback is that else clause, it will trigger the stopmusic() everytime. There might be a way to get from chat msgs the right place to put the ismount and the else clause. Anyway, I hope it helps. Cheers |
Quote:
|
Thanks for the tip Shirik :P
Stonedpossum, I forgot to add some important info that you'll need in your toc file: MyAddon.toc ## Interface: 20300 ## Title: My Addon ## Notes: This is my first AddOn. MyAddon.lua The explanation: ## Interface: 20300 -- is were u type current game version ## Title: My Addon -- the name that ppl using ur addon will see in the addon options ## Notes: This is my first AddOn. -- info -- the next session is where u put the files to be loaded, .lua and/or .xml Now the explanation is complete ^^ If u into the addon development, check foruns here and http://www.wowwiki.com/ Cheers :P |
Thanks guys.
Now, one more question, can I just put this all in notepad and save it as the type of files needed, or do I need to download a program? |
Quote:
|
Hey. Sorry for all the questions, I feel so dumb. Haha, but this is my very first time doing any sort of programing and making WoW addons, so anyway, I did this:
Code:
MyAddon = {OnTheRoad} That's my Addon.lua file. The addon comes up on the list, but doesn't do anything. Also, is it best to make an addon in Lua or XML? |
Quote:
Addon.lua Code:
local f = CreateFrame("Frame") Code:
## Interface: 20300 replace "Interface\\AddOns\\OnTheRoad\\music.mp3" with the location of the mp3 you want to use. |
Don't I want it to stop the music when you unmount?
And also, what's wrong with the where the music file is? Because that's where it is... |
Stonedpossum... I love that nic! lol
|
Quote:
Code:
local f = CreateFrame("Frame") |
Hey, ok I think it worked. I logged on when i was mounted and it was playing, but when I unmounted and and remounted it didn't play. How can I make it play every time?
Addon.lua: Code:
MyAddon = {OnTheRoad} Code:
# Interface: 20300 Ok, here's something weird. It doesn't work if you mount, but it plays the music when you run into a building and get unmounted... WTF?!? Help please... Another UPDATE: Now it's just playing when I log on mounted... I'm so confused! |
Quote:
I'm not certain but maybe "PLAYER_AURAS_CHANGED" is called before IsMounted() will return true. If so try Code:
|
The value for IsMounted() is indeed delayed during PLAYER_AURAS_CHANGED. The event fires too fast. I came across this problem myself when creating the PlaySound addon. Using an OnUpdate handler is the best way to go.
|
Gah! Ok, I have,
Code:
local frame= CreateFrame("Frame") |
Quote:
put Code:
DEFAULT_CHAT_FRAME:AddMessage("Stopping music") Code:
DEFAULT_CHAT_FRAME:AddMessage("Playing music") Code:
t >= 1 Is Music enabled, in the sound options? And does <Your addon> appear in the addon list? |
Code:
local frame= CreateFrame("Frame") Yes, my sound is on. Yes, it does show up on the list. and you said something about changing the "t >= 1" what would I even change it to? I mean, what does that even mean... Sorry for being so stupid when it comes to this programing stuff, never done it before. |
Change it to this and see if it pops up any messages:
Code:
local frame= CreateFrame("Frame") Not to put a stopper to your learning experience, but you could just use my PlaySound addon (shameless plug, whoohoo!!). Good luck dood :) |
Hi.
First on my original post, I put a line with: MyAddon = {} and your using MyAddon = {OnTheRoad}, which is wrong. MyAddon = {} -- is used to create an empty table. You shouldn't put anything inside curly bracets. So, pls copy and paste the code as is and then test it. I also found this events that you can try to test and see if they fit best: CHAT_MSG_SPELL_PERIODIC_FRIENDLYPLAYER_BUFFS Check arg1 for "mount" and/or "mounted" strings. COMBAT_TEXT_UPDATE Check arg1 for "AURA_START", "AURA_END", "AURA_START_HARMFUL", "AURA_END_HARMFUL" strings. UNIT_AURA("player") Use this instead of "PLAYER_AURAS_CHANGED" MyAddon:UNIT_AURA(arg1, ...) if( IsMounted() and arg1 = "player" ) then .... U need to do some work here, I'm @ work and cant test it :D sssshhhhh dont tell my boss -------------------------------------------------------------------------- I like MyAddon = {} for 2 reasons, readability and u can add more functions if u like by using MyAddon:NEW_FUNCTION(args), avoinding the polution of the global enviroment and possible confiltcs between addons fucntions. But this is just my point of view, u should follow whatever u feel it fits best ur porposes. -------------------------------------------------------------------------- Hope I could give u a help Cheers |
All times are GMT -6. The time now is 11:25 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI