Thread Tools Display Modes
01-31-08, 10:43 PM   #1
Stonedpossum
A Murloc Raider
Join Date: Oct 2007
Posts: 8
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!
  Reply With Quote
02-01-08, 12:23 AM   #2
Sythalin
Curse staff
 
Sythalin's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 680
Really simple. Just write a simple addon to check "IsMounted()" and "not IsMounted()".

www.wowwiki.com
  Reply With Quote
02-01-08, 08:58 AM   #3
ProfOak
A Cyclonian
Join Date: Oct 2005
Posts: 47
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

Last edited by ProfOak : 02-01-08 at 09:02 AM.
  Reply With Quote
02-01-08, 10:13 AM   #4
Shirik
Blasphemer!
Premium Member
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2007
Posts: 818
Originally Posted by ProfOak View Post
-- set the trigger to catch the event and call your function
frame:SetScript("OnEvent", function(this, event, ...)
MyAddon[event](MyAddon, ...) end; );
While there's nothing wrong with what you did, I strongly advise that you use "self" instead of "this" when making these types of functions. This fits the standard Lua syntax, and you'll get less confusion when others are reading your code (and may save yourself some confusion as well).
__________________
たしかにひとつのじだいがおわるのお
ぼくはこのめでみたよ
だけどつぎがじぶんおばんだってことわ
しりたくなかったんだ
It's my turn next.

Shakespeare liked regexes too!
/(bb|[^b]{2})/
  Reply With Quote
02-01-08, 10:48 AM   #5
ProfOak
A Cyclonian
Join Date: Oct 2005
Posts: 47
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
  Reply With Quote
02-01-08, 01:30 PM   #6
Stonedpossum
A Murloc Raider
Join Date: Oct 2007
Posts: 8
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?
  Reply With Quote
02-01-08, 03:04 PM   #7
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
Originally Posted by Stonedpossum View Post
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?
Notepad/wordpad will do what you want.
  Reply With Quote
02-01-08, 05:40 PM   #8
Stonedpossum
A Murloc Raider
Join Date: Oct 2007
Posts: 8
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}
local frame = CreateFrame("Frame");
frame:RegisterEvent("PLAYER_AURAS_CHANGED");
frame:SetScript("OnEvent", function(this, event, ...)
OnTheRoad[event](OnTheRoad, ...) end; );
function MyAddon:PLAYER_AURAS_CHANGED()
if(IsMounted())
local soundFile = "Interface\\AddOns\\OnTheRoad\\music.mp3";
PlayMusic(music.mp3);
else
StopMusic();
end;
end;
It didn't work... haha... can someone tell me what I'm doing wrong. I bet it's something really easy :P

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?

Last edited by Stonedpossum : 02-01-08 at 05:49 PM.
  Reply With Quote
02-01-08, 05:55 PM   #9
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
Originally Posted by Stonedpossum View Post
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}
local frame = CreateFrame("Frame");
frame:RegisterEvent("PLAYER_AURAS_CHANGED");
frame:SetScript("OnEvent", function(this, event, ...)
OnTheRoad[event](OnTheRoad, ...) end; );
function MyAddon:PLAYER_AURAS_CHANGED()
if(IsMounted())
local soundFile = "Interface\\AddOns\\OnTheRoad\\music.mp3";
PlayMusic(music.mp3);
else
StopMusic();
end;
end;
It didn't work... haha... can someone tell me what I'm doing wrong. I bet it's something really easy :P
I would personally do

Addon.lua
Code:
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_AURAS_CHANGED");
f:SetScript("OnEvent", function()
   if IsMounted() then
      PlayMusic("Interface\\AddOns\\OnTheRoad\\music.mp3")
   end
end)
Addon.toc
Code:
## Interface: 20300
## Title: My Addon
## Notes: This is my first AddOn.
Addon.lua
Place both of these in a folder named Addon.


replace "Interface\\AddOns\\OnTheRoad\\music.mp3" with the location of the mp3 you want to use.

Last edited by Slakah : 02-01-08 at 06:00 PM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Play a sound file when you're mounted?


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