Adding action sounds to unit animations

frekk

Scourge of St. Lawrence
Joined
Jun 21, 2003
Messages
3,151
Location
Kingston, Ontario
I didn't see this covered anywhere else, and I had a devil of a time figuring it out by myself, so I thought I'd add it.

For starters, this tutorial isn't about adding selection or order sounds to units (the sounds that units make when you click on them). That's covered elsewhere.

This tutorial is intended to show how to change the sounds that units make during various animations. You can change the sound workers make when they dig, or change the sneeze a rifleman makes during a fidget animation to a cough.

The tutorial presumes a basic level of familiarity with adding new units. You will also need Nifscope, and the wav files you intend to use. You may need some method of converting wav formats, depending on whether or not they are in the right format and what your OS is (the Sound Recorder in some versions of Windows can convert wav formats; this functionality has been removed in Vista and possibly XP).

The first thing you need to do is make sure you have all the animation files you need for your unit. Many custom units use the animations from other units. You can tell if the unit you want to change is using another units animations because it will have no .kfm file and no .kf files in the folder that contains the art for the unit.

If this is the case, you will need to figure out what animations it's using. Usually, the unit creator will tell you, or if you're borrowing a unit from another mod, you will be able to see what animations the unit is using from where <KFM> is pointing in Civ4ArtDefinesUnit.xml.

So, go to the folder where the animations you need are, and copy the .kfm and all the .kf files. If the name of the .nif file is different, you should copy that too, just to be safe - sometimes the animations will want the original .nif file.

When you're setting up the unit in Civ4ArtDefinesUnit.xml, be sure to point the <KFM> to the right location in your unit folder, and not to the animations for some other unit.

Now that we have all the animations for the unit and it's been added properly in xml, we can get down to business.

For this example we're going to add some different vocal sounds to the attack animations of a custom swordsman unit. We'll call him a "Swordguy" and presume he's using the vanilla swordsman animations, which we've copied to our Swordguy folder.

First, you'll need your wav file, and you'll need to convert it to a format Civ4 can use. I think other formats can be used, but I use PCM 22.050 kHz, 16 Bit, Mono. Put your wav file in assets/sounds/units.

The naming of the file is important. You can add a number of different sounds for the same thing, for instance, we could have 5 different kinds of grunts that the Swordguy makes when he attacks. Each time he's supposed to make a vocalization during an attack, the computer will randomly pick one of the sounds. The first one must end in "-000.wav" and the next one ends in "-001.wav" and so on. If you have just one sound, you may or may not need to do this, but I do it anyway just to be on the safe side. So, I'm going to name the file SwordguyAttkVox-000.wav. If I had 3 different grunts to be used when he attacks, I would name the files SwordguyAttkVox-000.wav, SwordguyAttkVox-001.wav, and SwordguyAttkVox-002.wav.

XML/Audio/Audio3DScripts.xml

Now, open up assets/XML/Audio/Audio3DScripts.xml. Find any entry that begins with "AS3D_UN" (these are unit sounds, though not all unit sounds use the UN part). Copy the entry and paste it at the end. Now we change the first two lines of the entry, from something like this:

PHP:
		<ScriptID>AS3D_UN_MATCH_STRIKE</ScriptID>
		<SoundID>SND_MATCH_STRIKE</SoundID>

To a new entry, something like this:

PHP:
		<ScriptID>AS3D_SWORDGUY_ATTK_VOX</ScriptID>
		<SoundID>SND_SWORDGUY_ATTK_VOX</SoundID>

Save and close.

XML/Audio/AudioDefines.xml

Open up AudioDefines.xml. Search for SND_TUTORIAL_COMPLETE_0. Any new entries must be after this, but before the part that starts with <ContextTypes>. Copy and paste the tutorial entry. Change:

PHP:
			<SoundID>SND_TUTORIAL_COMPLETE_0</SoundID>
			<Filename>Sounds/Tutorial/Tut_66A</Filename>

To match your new custom sound, using the <SoundID> entry you used in Audio3DScripts; and point it to your custom wav file.

PHP:
			<SoundID>SND_SWORDGUY_ATTK_VOX</SoundID>
			<Filename>Sounds/Units/SwordguyAttkVox</Filename>

IMPORTANT: note how the filename isn't the full filename. Our wav file is actually named "SwordguyAttkVox-000.wav". Note how, in the xml, there is no .wav extension, and the "-000" part mentioned earlier isn't present. Do not include the file extension here, and do not put the "-000" part either.

Save and close.

Animation Files

When a unit makes a sound during animation, it has been instructed to do so by one of the .kf files, which cover animations for various actions. You can usually tell what these actions are just by the name of the file - for instance, swordsman_md_fidget.kf covers the fidget animation, swordsman_md_run.kf covers the walking animation, and so on. Sometimes there will be multiple animations with similar names, for instance, for attack there is swordsman_md_strikea.kf, swordsman_md_strikeb.kf, swordsman_md_strikec.kf. You may need to use a little experimentation and intuition to discover which animations are controlling the sound you want to change. It is possible that you may need to change the sound in several similar animation files (that happens to be the case here). You can also look up the sound definitions in xml and navigate to the vanilla sounds/units folder and have a listen to the wavs.

We're going to open the swordsman_md_strikea.kf file in Nifscope and see what's in there.

In the upper left box, called "block list", you'll see a list of things like NiTransformer, NiBSpline, etc.

Scroll down to the bottom of this list. The last entry should say "NiFooter". Just above this, the second last entry, should be NiTextKeyExtraData. Expand it by clicking on the plus sign. Inside, you'll see "Text Keys". Expand that one too.



The first and last text keys will not usually contain any sound data. So, if you open a file and there are only two, you know it doesn't contain any sounds. If you open the others, you will see that some (often all) will contain an entry SOUND, followed by something like AS3D_UN_FOOT_UNIT_LOW.

All vocal sounds for units end with "VOX", unless perhaps the animations are custom and the creator hasn't followed the naming conventions used for sounds. So, we're trying to find something that ends in VOX. Note that sometimes there will be a long line of sounds separated by commas and you won't be able to see them all unless you click on it.



We go through the text keys, and on the third one we come to AS3D_SWDMN_ATTK_VOX, which, intuitively, we can tell is the correct sound that we're looking for. "VOX" means its a vocalization (rather than footsteps, or the sound of weapons clinking or something), so it's the attack vocalizations for the swordsman. Most of the time, you'll probably just want to change vocalizations rather than the other sounds, so this naming convention makes it a little easier to find what you're looking for.



We double click on it, and change it to AS3D_SWORDGUY_ATTK_VOX, being careful not to delete any other entries that might be there (in this case there aren't) and making sure we don't erase any commas or the beginning part (SOUND: ).

Now, we Save As, being careful to select .kf from "save as file of type" drop-down ... otherwise it will save it as a nif.

Then, we check swordsman_md_strikeb.kf and swordsman_md_strikec.kf. We notice that they are both the same - each has the attack vocals in the third text key. So we change those too.

That's it! We're done.
 
Spartaaaa!!!

I'll can't wait to see the first unit with this attacking sound :D.

-> :goodjob:.

Now i know, where to look. Because one of the units in my mod has a wrong sound, and i don't know what unit, and didn't know where to look. So it's a bit faster.
 
This was helpful. Im trying to make a custom sound work for a jet fighter custom model (A-10) The custom sound I made works fine in air bomb mode (attacking city defenses) but it dont work in air strike mode (attacking units). It just plays the original attack sound. So I know the sound file is right because it works in air bomb mode, but its like I cant find where to connect this same sound to an air strike.

Ive search all over for help on this havent found any.
 
I was just curious about adding sounds. I have tried adding sounds to a modmod, and I notice that they did not put the new sounds after the Tutorial 0 like you suggest in the AudioDefines xml. In fact, they all seem to come before. I am specifically looking at FfH as an example. I added a sound for a new spell and it worked at first, the next time, I tried the game, I could not get the game to load. Restoring the AuidoDefines and Audio3DScripts to the early state and my modmod works again. Should I still put everything after the Tut o entry or not?
 
I was just curious about adding sounds. I have tried adding sounds to a modmod, and I notice that they did not put the new sounds after the Tutorial 0 like you suggest in the AudioDefines xml. In fact, they all seem to come before. I am specifically looking at FfH as an example. I added a sound for a new spell and it worked at first, the next time, I tried the game, I could not get the game to load. Restoring the AuidoDefines and Audio3DScripts to the early state and my modmod works again. Should I still put everything after the Tut o entry or not?

Have you added comments to the AuidoDefines or Audio3DScripts file? Comments in those files cause the game to crash, don't ask me why. :crazyeye:
 
I was just curious about adding sounds. I have tried adding sounds to a modmod, and I notice that they did not put the new sounds after the Tutorial 0 like you suggest in the AudioDefines xml. In fact, they all seem to come before. I am specifically looking at FfH as an example. I added a sound for a new spell and it worked at first, the next time, I tried the game, I could not get the game to load. Restoring the AuidoDefines and Audio3DScripts to the early state and my modmod works again. Should I still put everything after the Tut o entry or not?

I don't know ... FFH is such a huge reworking of the game. It might parse the files differently.

I have made a few alterations to some unit sounds in Fall Further Plus, and I've got my custom definitions after the tutorial stuff, but before <ContextTypes> and it works fine.

You'll have to experiment and see.
 
This was helpful. Im trying to make a custom sound work for a jet fighter custom model (A-10) The custom sound I made works fine in air bomb mode (attacking city defenses) but it dont work in air strike mode (attacking units). It just plays the original attack sound. So I know the sound file is right because it works in air bomb mode, but its like I cant find where to connect this same sound to an air strike.

Ive search all over for help on this havent found any.

It's possible that the air strike sound isn't to be found in the unit animations. Or it's governed by a different text entry in the same animation file, or a different animation file. I haven't done a fighter before so I can't say.

The only thing you could do is determine how the original sound is called, and then duplicate that (or alternatively, discover the name of the original wav file, and rename your new sound as a substitution).
 
Top Bottom