Half-Life 2

Half-Life 2

View Stats:
Jake Jul 14, 2014 @ 1:35pm
How do I precache custom sound files?
I'm trying to replace a weapon sound, specifically that of the machine gun turret.

I've edited the weapon script to draw from a number of sounds each time the gun fires.

For example:

"Weapon_functank.Single"
{
"channel" "CHAN_WEAPON"
"soundlevel" "SNDLVL_GUNFIRE"
"pitch" "95,105"

"wave" "^weapons/ar1/1.wav"
"wave" "^weapons/ar1/2.wav"
"wave" "^weapons/ar1/3.wav"
"wave" "^weapons/ar1/4.wav"
}

The problem is that no sound plays when I fire the weapon, and the console says that my custom sounds haven't been precached. If this was Left 4 Dead 2, I'd use the 'snd_rebuildaudiocache' console command, but Half-Life 2 doesn't appear to have such a command. I can't for the life of me figure out how to cache custom sound files in this game.

If anyone knows how to get around this, I'd really appreciate your help.

Thanks.


EDIT:

Thought I'd update this in case anyone else is having trouble with the turret and comes across this on Google.

I never did figure out how to precache sounds, but I did get custom sounds working for the turret, or "functank".

You have to make sure that "Weapon_functank.Single" and "Weapon_AR2.NPC_Single" match up and use the same sound files. For example:

"Weapon_AR2.NPC_Single"
{
"channel" "CHAN_WEAPON"
"volume" "1"
"soundlevel" "SNDLVL_GUNFIRE"
"pitch" "95,105"

"wave" ")weapons/ar1/1.wav"
"wave" ")weapons/ar1/2.wav"
"wave" ")weapons/ar1/3.wav"
"wave" ")weapons/ar1/4.wav"

}

"Weapon_functank.Single"
{
"channel" "CHAN_WEAPON"
"volume" "1"
"soundlevel" "SNDLVL_GUNFIRE"
"pitch" "95,105"

"wave" ")weapons/ar1/1.wav"
"wave" ")weapons/ar1/2.wav"
"wave" ")weapons/ar1/3.wav"
"wave" ")weapons/ar1/4.wav"

}
Last edited by Jake; Feb 20, 2015 @ 5:42pm
< >
Showing 1-4 of 4 comments
A-06 Jul 15, 2014 @ 5:55am 
To replace the content of the game you must create a new folder in this directory:
Steam \ SteamApps \ common \ Half-Life 2 \ hl2

Rename this folder to "custom"
Create a new folder inside and give it a descriptive name (example: turret_sounds).

All the files inside this folder are used instead of the original ones when the game is booted up, so this is where you should place your new files, but you have to follow the same structure used by the game.

Example:
If you're replacing the model of the crowbar, the folder structure should look like this:
custom / new_crowbar / models / weapons / <model files>

If you are replacing the textures of the crowbar, the structure should be this:
custom / new_crowbar / materials / models / weapons / v_crowbar / <texture files>

Given that you're replacing sound files, the structure should be something like this:
custom / turret_sounds / sound / ar1 / <sound files>

Your files must have the same name of the original files, otherwise the game won't use them.

Now you only have to open the game.
Last edited by A-06; Jul 15, 2014 @ 5:57am
Jake Jul 15, 2014 @ 12:30pm 
Thanks for the reply, but it doesn't solve the issue I'm having.

You say that my files must use the same names, but that's where the problem lies.

The turrest uses only one sound file for its firing sound. I can replace that file with my own custom sound easily enough and have it working, but I'd like to have the script draw from a pool of sounds.

In the script I posted above, every time the gun fires a bullet it will randomly select one of the four sounds listed and use that as the firing sound. I prefer this to using just the one sound as it results in much more dynamic, less repetitive audio.

However, as the turret only uses the one firing sound, I can't use the original file names because there aren't enough files there originally for me to use my four custom sounds.

The script I posted above would work if there was a way I could add my custom sounds to the sound cache.

In Left 4 Dead 2 you can add custom sound files (with custom names) to the sound cache with the snd_rebuildaudiocache command, and that allows the script technique I posted above to work without issues. However, there doesn't seem to be any console command to add sounds to the cache in Half-Life 2.

What I'm trying to figure out here is how to add custom files to the sound cache.

What's really odd is that I'm using multiple sound files and the script technique above for the Pistol, SMG, and AR2, and they're all working fine. I'm not sure what exactly happened to make them work but not the turret though.
A-06 Jul 16, 2014 @ 5:34am 
The files CAN have their own name as long as it is specified somewhere else (like the script in your post).

My main work with Source is model/texture replacement, so I can't really help much in this area. However, I've noticed that when a vpk file is placed in the "custom" folder, after you run the game, a sound cache is created for that file.

Like in this image.[k42.kn3.net]

You don't even have to pack them as vpk, just put your files in the "custom" folder following the right structure and keeping your original names, when you start the game a cache file should be created in this folder: custom / my_new_sounds / Sound

Like in this image.[k45.kn3.net]

I hope this is useful for you.
________________________________________

In any case, you might find this intresting/helpful.

Soundcache - VDC
Precaching Assets - VDC
PrecacheScriptSound - VDC
Jake Jul 18, 2014 @ 12:14pm 
The custom folder stuff doesn't seem to work, unfortunately.

However, upon further investigation I found that I could get my custom sounds working if I used them for the AR2 instead.

I'm using some custom models I downloaded for the AR2, Pistol, and SMG, so that could have something to do with the fact that my custom sounds are working for those weapons but not the turret.

Perhaps something goes in the .qc file for these weapons that enables the use of custom sounds rather than just the default ones?
< >
Showing 1-4 of 4 comments
Per page: 1530 50

Date Posted: Jul 14, 2014 @ 1:35pm
Posts: 4