Jump to content

All my products and services are free. All my costs are met by donations I receive from my users. If you enjoy using any of my products, please donate to support me. My bare hosting costs are currently not met so please consider becoming a contibuting member by either clicking this text or the Patreon link on the right.

Patreon

Recommended Posts

Posted

Tempest,

Just pursuing the post from earlier about wanting to be able to have gameex randomly choose a game launch audio file. You said that there was a script available that could achieve what I'm looking to do?

Thanks,

~Underhill

Posted

I found this on the AutoHotKey site. I don't know who to give credit to, but the idea was not mine.

The script is pretty simple:

 

musicdir := "C:\MyMusic"
total = 0
Loop, %musicdir%\*.mp3
total += 1

Random, select, 1, %total%

Loop, %musicdir%\*.mp3
IfEqual, A_Index, %select%, Setenv, file, %A_LoopFileFullPath%

FileCopy, %file%, C:\Music\IntroSong.mp3, 1

I will post the code again now, with comments. Sometimes the forum messes things up, so use the code above.

 

musicdir := "C:\MyMusic"; music dir is the path to your audio files.
total = 0
Loop, %musicdir%\*.mp3;Make sure and use the correct extension if not .mp3
total += 1; count how many files in your directory

Random, select, 1, %total%; pick a random number between 1 and the total number of files

Loop, %musicdir%\*.mp3; Loop thru your music directory
IfEqual, A_Index, %select%, Setenv, file, %A_LoopFileFullPath%;Find the n'th file in your directory

FileCopy, %file%, C:\Music\IntroSong.mp3, 1;Copy the n'th file to wherever you have told GameEx to find your file.

You will need to download and Install AutoHotKey

Copy and paste the text from the first codebox into notepad. Save as RandomMusic.ahk

Right-Click on "RandomMusic.ahk", and choose "Compile Script". A new file named "RandomMusic.exe" will be created.

In GameEx, point to RandomMusic.exe in the appropriate places. IE:

1. Tweaks Performance > Launch on Startup Don't Wait

2. Emulator > Also Launch

If you want seperate directories for different things, then repeat the process, adjusting the paths, and giving the script a unique name each time.

Posted

The funny thing is, I think I posted this or a very similar script over a year ago for someone else. They didn't seem that interested, so I dropped the suggestion and moved on. Hopefully Underhill will be more receptive to the idea than the last person was. I think this is a very good solution.

On the other hand, this could also be dealt with via a GameEx plugin. The code would do basically the same thing, but it would be triggered by GameEx actions rather than setting this script up in a startup event. I don't know the plugin system, so I can't even begin to look into it. The script is very viable as is as well as being easy to update/maintain, though.

Posted

Thank you, I'll give this a try. It's something I've been wanting to do for a little while since I finally figured out I could change the audio in theme editor a while back. If I knew "anything" about writing a plug in, I'd be all over it.

I've got to run right now but I'll give this a shot when I get back. Can't wait to try it out. Until something else comes around I'm more than happy to use this if does what it needs and it sounds like it does.

Thanks for the responses,

~Underhill

Posted

I messed with this for a little bit but I kept getting an error in gameex about not being able to find a file. I have a feeling it's something simple I overlooked. I know I should post the error but it was another busy day and I had to run. If I can't find what I've missed I'll post the error for some help.

Just a couple questions though...

How much of that script do I need to change? I know I have to change the paths to where the audio files are and the .mp3 to .wav but do I need to change anything else like the total? When I run the script by itself it creates the audio file with one chosen in the directory. But with each additional run the file never changed to a different one.

In the theme folders the default intro file is labeled introsound.wav The script looks to save as introsong.mp3 Should I leave this alone or change it to what the default name is? ......Hmm, more I think about it, that's something I can just point to in theme editor isn't it?

Anyway I just wanted to let you know I'm still working to get this going. Hopefully I'll have a moment of clarity and I'll find my mistakes.

Thanks again,

~Underhill

Posted

Just change the two paths and you should be good.

musicdir := "C:\MyMusic"; <------Change to where your music is stored
total = 0
Loop, %musicdir%\*.mp3
total += 1

Random, select, 1, %total%

Loop, %musicdir%\*.mp3
IfEqual, A_Index, %select%, Setenv, file, %A_LoopFileFullPath%

FileCopy, %file%, C:\Music\IntroSong.mp3; <--------Change to where you want the file to go

Posted

Thanks for covering for me BK, I went out of town for mother's day.

I bet the script is yours though. I downloaded it from somewhere, I'm guessing now, that it was from here. ;)

I officially give you credit! :P

Posted
Thanks for covering for me BK, I went out of town for mother's day.

I bet the script is yours though. I downloaded it from somewhere, I'm guessing now, that it was from here. ;)

I officially give you credit! :P

Mothers day eh? I think I may find this script useful too. But I'm not sure what for yet.

Posted

Naw, I don't want credit since I didn't write the script. I actually stole it from the AHK forums as I recall. However, I'm pretty sure you stole the same code from them as well :lol: Or maybe you stole my code that I stole from them. Either way, no worries! Hope Underhill got it working.

Posted

I did get it working.... halfway.

Got it working as far as GameEx playing it but it never changes. It won't copy over the previous file. But if I delete the audio file and run it again it will change. Possibly a problem with vista 64. Going to have to search for some answers to that little problem.

~Underhill

Posted

I should've seen that one coming...

Try:

FileCopy, %file%, C:\Music\IntroSong.mp3, 1

The 1 at the end tells it to overwrite any existing files.

Please post if you have more problems, or if it does work. It kinda bugs me when people don't... we never know if it worked, or if they just gave up.

Posted

Thanks Tempest that did it. Working like it should.

I may be asking for too much here but is there an option to run the script each time a game is launched? Currently, as I'm sure you probably know, the script will run on the start up of GameEx which then chooses the audio file and remains the same until the next start.

One other thing I noticed is the audio will play as long as the controls screen is up but if there is no controls screen at start up or if I close the controls screen the audio is cut off premature. I can understand this since the game sounds are going to take priority. But would be nice if it continued to play while the launched game is starting up.

Until the day someone more talented than I comes up with a solution, plugin or it's added to the features I can deal with these 2 minor things.

Thank you for your patience and effort helping me get this going.

~Underhill

Posted

There are 3 options here:

1) Write a plugin that will perform this copy each time a game is launched. This is the best solution, but requires knowing how to write plugins in C# or VB.NET.

2) Place this script in one of the launch before/after/also fields for each emulator/application. This is the easiest thing to do, but you might not have blank launch commands for every emulator/application. If not, you would probably need to use a batch file or something in order to run multiple processes.

3) Have the script watch for your emulator/application processes and run the script when it detects one. For this to work, you would need a list of all the processes (emulators/applications) you will be running, then have some logic set up to run the script when it sees the process for the first time (otherwise it will continually run while the process is active).

In short, there are a few ways to do it with varying levels of complexity.

Posted

Thanks for the reply bkenobi,

Yeah, with that info I think I will wait and hope one day a plugin gets written for this. The last time I did any programming was in Basic on my apple IIc in high school =P.

Thanks again for all the help.

~Underhill

Posted
Thanks Tempest that did it. Working like it should.

I may be asking for too much here but is there an option to run the script each time a game is launched? Currently, as I'm sure you probably know, the script will run on the start up of GameEx which then chooses the audio file and remains the same until the next start.

~Underhill

Just so we are clear, this can be handled easily using one of the suggestions that Bkenobi made. As he said, #2 is the easiest, since it is a built-in feature of GameEx.

The second problem would possibly require a change from Tom.

At any rate, glad you got it going, and if you are happy, we are happy.

Guest
This topic is now closed to further replies.
×
×
  • Create New...