Using play-sound in Spring
Posted: 14 Oct 2005, 03:32
As we all know, Spring has supported the "play-sound" command in scripts since 0.63b1:
-Added support for loading TA:K COB files and implemented the TA:K-specific opcode play-sound.
This allows a unitmaker to play any sound he wants (a wav file in the /sounds/ directory) at any volume at any point in the script. This is useful, since now we can do things such as running engine sounds while units move, foot step noises, or anything else of that nature.
Getting it to work isn't as simple as that makes it appear, though. After bothering Fnordia for a while, we finally got it working nicely.
Since I use scriptor, that's all this little guide is written for. I don't think any other compilers would be up to this task anyway. First of all, you must be compiling in TA:K mode. You can either click the little green TAK button in the scriptor GUI or you can put the following line at the beginning of your script:
#define TAK
Secondly, you cannot use the stock SmokeUnit.h file. If your unit uses SmokeUnit and you want it to play sounds, you can't right off the bat. This is because TAK handled smoking units differently than TA, mainly with a different function, but the point is if you try to compile with the original SmokeUnit you will crash scriptor.
So, to rectify this, I've made a hacked up Spring-sound-ready Smokeunit.h. It's available for download by clicking here. Simply put this .h file in your Includes directory, and then change the line:
#include "smokeunit.h"
in any scripts you want to play sounds in with:
#include "springsmoke.h"
And everything will compile and work just fine (barring other errors on your part, of course). You don't have to make this change for units that don't use play-sound.
Then, to use play-sound, you just type in the following line:
play-sound("filename", 1);
where filename is the filename of the .wav file in the /sounds/ directory to play, and 1 is the volume. There is no limit to volume afaik. For reference, I had to use a volume value of 10 for the Raven's explosion sound to make it about the same volume as it is normally in game. There's no limit to what functions it can be played in, as far as I know, but I'm sure putting a play-sound in a repeating loop without a sleep wouldn't be a good thing.
-Added support for loading TA:K COB files and implemented the TA:K-specific opcode play-sound.
This allows a unitmaker to play any sound he wants (a wav file in the /sounds/ directory) at any volume at any point in the script. This is useful, since now we can do things such as running engine sounds while units move, foot step noises, or anything else of that nature.
Getting it to work isn't as simple as that makes it appear, though. After bothering Fnordia for a while, we finally got it working nicely.
Since I use scriptor, that's all this little guide is written for. I don't think any other compilers would be up to this task anyway. First of all, you must be compiling in TA:K mode. You can either click the little green TAK button in the scriptor GUI or you can put the following line at the beginning of your script:
#define TAK
Secondly, you cannot use the stock SmokeUnit.h file. If your unit uses SmokeUnit and you want it to play sounds, you can't right off the bat. This is because TAK handled smoking units differently than TA, mainly with a different function, but the point is if you try to compile with the original SmokeUnit you will crash scriptor.
So, to rectify this, I've made a hacked up Spring-sound-ready Smokeunit.h. It's available for download by clicking here. Simply put this .h file in your Includes directory, and then change the line:
#include "smokeunit.h"
in any scripts you want to play sounds in with:
#include "springsmoke.h"
And everything will compile and work just fine (barring other errors on your part, of course). You don't have to make this change for units that don't use play-sound.
Then, to use play-sound, you just type in the following line:
play-sound("filename", 1);
where filename is the filename of the .wav file in the /sounds/ directory to play, and 1 is the volume. There is no limit to volume afaik. For reference, I had to use a volume value of 10 for the Raven's explosion sound to make it about the same volume as it is normally in game. There's no limit to what functions it can be played in, as far as I know, but I'm sure putting a play-sound in a repeating loop without a sleep wouldn't be a good thing.