Home   Help Search Login Register  

Author Topic: Adding sounds to environment  (Read 1436 times)

0 Members and 1 Guest are viewing this topic.

Offline Hellbender

  • Members
  • *
Adding sounds to environment
« on: 19 Feb 2008, 02:01:22 »
In a mission I want to have a couple of guards sitting around a camp fire listening to music on the radio. I need to know how to add this music to "sounds" in the editor, or how to do it in another way. The important thing is of course that the music can only be heard near the radio and that it plays all the time (not just once). It only has to contain a single song.

What cfg subclass do I need to use to make this work?

I've tried cfgSounds which plays it everywhere and cfgEnvSounds which doesn't really play it at all. Is there another cfg subclass I can use to be able to play the music in "sounds"?

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Adding sounds to environment
« Reply #1 on: 19 Feb 2008, 09:06:38 »
Hi there!

CfgSounds is your best bet, together with say. However, you might need to use a program of some kind and re-format your music file : if it's stereo, it will be heard everywhere, whereas mono sounds will be properly directional. After that, you simply need to make the radio "say" the song!

You might want to play with the db+/- values in cfgSounds as well:

Code: [Select]
class YourSound
{
name = "MySound";
sound[] = {"sound\mysound.ogg", db-0, 1.0};
titles[] = {};
};

Lessening the db value won't make the sounds lower, but it'll make the distance they're heard at smaller. So play with that until you get a nice proper distance that the "say" is heard at.  :good:

Good luck!

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline Hellbender

  • Members
  • *
Re: Adding sounds to environment
« Reply #2 on: 19 Feb 2008, 11:39:03 »
Thanks Wolfrug!

Is there any way I can also make it loop so that the song plays over and over again? This is not for a cutscene but for in-game environment.

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Adding sounds to environment
« Reply #3 on: 19 Feb 2008, 15:19:44 »
Sure. Here's the easy way. First find out the lenght of the song (say, 3:40) ->

Change to seconds : 60 + 60 + 60 + 40 = 220 seconds.

Then write something like this in a trigger activated by, for instance, "true" (i.e., immediately -> another option might be to activate the trigger when the player gets close). Then, in the On Activation field write (radio1 being the name of the radio):

Code: [Select]
radioLoop = [radio1] spawn {while {alive _this} do {_this say "NameOfSong"; sleep 220}};
In the above example, once radio1 is dead, the music would stop playing. :) Then again, since you're using Say, the sound should stop anyway (since say only works with living critters, AFAIK).

 :good: Good luck!

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline Hellbender

  • Members
  • *
Re: Adding sounds to environment
« Reply #4 on: 20 Feb 2008, 00:05:09 »
Thanks Wolfrug!

It makes sense, but I'm having some trouble getting it to work!

Here's how it looks:

Condition:
Code: [Select]
alive radio1
On activation:
Code: [Select]
radioLoop = [radio1] spawn {while {alive _radio1} do {_radio1 say "Song1Mono"; sleep 195}};
And here's what I know is NOT wrong:

1. I made a test trigger that confirms "radio1" really is alive, so that's not the problem.

2. I know the radio trigger gets activated because I get an error when writing "this" like you did instead of radio1. (array, expected object)

3. I know the song is in the right place and that the game can find it because a simple say command like this:
Code: [Select]
Radio1 say ["Song1Mono",1], works just fine!

Can you help me out again?
« Last Edit: 20 Feb 2008, 00:07:41 by Hellbender »

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: Adding sounds to environment
« Reply #5 on: 20 Feb 2008, 02:10:37 »
I think you need to make up your mind whether it is called radio1 or _radio1 and then use the one you choose throughout the code.

As it is a trigger I would say you need it as radio1 and not _radio1.


Planck
I know a little about a lot, and a lot about a little.

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: Adding sounds to environment
« Reply #6 on: 20 Feb 2008, 10:06:15 »
Yes, Planck is correct: my mistake. :D

Basically, writing:

radioLoop = radio1 spawn {while {alive _this} do {_this say "Song1Mono"; sleep 195}};

(taking away the []'s around radio1) will work. _this inside the script always refers to whatever you used to call the script with: in my previous example, the ARRAY [radio1]. To access that array, you would've had to write: _this select 0 (selecting the first and only element of the [radio1] array) instead of just _this.

However, for the sake of simplicity, you can just use "radio1" (sans quotes) instead, to make things easier.  :cool2:

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline Hellbender

  • Members
  • *
Re: Adding sounds to environment
« Reply #7 on: 21 Feb 2008, 20:34:08 »
Okay, thanks guys!

It works fine now!