Jump to content
Sign in to follow this  
clydefrog

play a sound for everybody when a script is run but volume is effected by distance

Recommended Posts

Long title but I don't know how to word it any simpler. I'm using a script that opens the ramp on an aircraft, I have got that script to play a sound when the ramp opens. To do this I have just used the "say" command in the script with an .ogg file. The problem with this was only the person running the script could hear it. I then tried using CBA function GlobalSay and GlobalSay3D, both of these made the sound global so now everybody hears it as I want.

The problem now is they hear it when the script runs wherever they are on the map at full volume, I only want them to be able to hear it if they are near the aircraft and preferably the further they get away from it the quieter it gets until it's not audible to them. Anybody know how to do this?

Thanks.

Share this post


Link to post
Share on other sites

Code? Also your cfgSounds in description.ext

Share this post


Link to post
Share on other sites
Code? Also your cfgSounds in description.ext

This is the script I'm running the sound from as it is currently (using that CBA function):

// openRamp.sqf
// © JUNE 2009 - norrin ([email protected])

_vcl = _this select 0;

_vcl animate ["ramp_top",1];
_vcl animate ["ramp_bottom",1];

sleep 0.1;
_vcl setVariable ["NORRN_openRamp", true, true];

[_vcl, "power_down"] call CBA_fnc_globalSay3d;


if (true) exitWith {};

(this script is called from another one, see spoiler if you need to see that too)

// openDoor_init.sqf
// © JUNE 2009 - norrin ([email protected])

_vcl 		= _this select 0;
_c 			= 0;
_cc			= 0;
_openDoor = _vcl addAction ["Open C-130 doors", "C130_openDoor\openDoor.sqf", "", 0, false, true];
_closeDoor = _vcl addAction ["Close C-130 doors", "C130_openDoor\closeDoor.sqf","", 0, false, true];
_openRamp = _vcl addAction ["Open C-130 ramp", "C130_openDoor\openRamp.sqf", "", 0, false, true];
_closeRamp = _vcl addAction ["Close C-130 ramp", "C130_openDoor\closeRamp.sqf","", 0, false, true];
_toAttach 	= objNull;
_vcl removeAction _openDoor;
_vcl removeAction _closeDoor;
_vcl removeAction _openRamp;
_vcl removeAction _closeRamp;

if (isServer) then
{
_vcl setVariable ["NORRN_openDoor", false, true];
_vcl setVariable ["NORRN_openRamp", false, true];
sleep 2;
};

while {alive _vcl} do
{ 	
// Door action
if (!(_vcl getVariable "NORRN_openDoor") && _c == 0) then
{	
	_openDoor = _vcl addAction ["Open C-130 doors", "C130_openDoor\openDoor.sqf", "", 0, false, true];
	_vcl removeAction _closeDoor;
	_c = 1;
};

if ((_vcl getVariable "NORRN_openDoor") && _c == 1) then
{	
	_closeDoor = _vcl addAction ["Close C-130 doors", "C130_openDoor\closeDoor.sqf","", 0, false, true];
	_vcl removeAction _openDoor;
	_c = 0;
};
// Ramp Action
if (!(_vcl getVariable "NORRN_openRamp") && _cc == 0) then
{	
	_openRamp = _vcl addAction ["Open C-130 ramp", "C130_openDoor\openRamp.sqf", "", 0, false, true];
	_vcl removeAction _closeRamp;
	_cc = 1;
};

if ((_vcl getVariable "NORRN_openRamp") && _cc == 1) then
{	
	_closeRamp = _vcl addAction ["Close C-130 ramp", "C130_openDoor\closeRamp.sqf","", 0, false, true];
	_vcl removeAction _openRamp;
	_cc = 0;
};
sleep 2;
};
if (!alive _vcl) exitWith {};

and here is the cfgsounds from description.ext:


class CfgSounds
{
// List of sounds (.ogg files without the .ogg extension)
sounds[] = {power_down};

// Definition for each sound
class power_down
{
	name = "power_down"; // Name for mission editor
	sound[] = {\sound\power_down.ogg, 1, 1};
	titles[] = {};
};
};

There is then a folder named sound with the power_down.ogg file inside it.

Edited by clydefrog

Share this post


Link to post
Share on other sites

I know I repeat that all the time, but check that your sound is in Mono (if you want the 3D stuff to work). Also, in your CfgSounds, you can add another parameter to tweak the hearing range of the sound:

sound[] = {\sound\power_down.ogg, 1, 1, 30};

Will be heard 30 meters around only.

Share this post


Link to post
Share on other sites
I know I repeat that all the time, but check that your sound is in Mono (if you want the 3D stuff to work). Also, in your CfgSounds, you can add another parameter to tweak the hearing range of the sound:

sound[] = {\sound\power_down.ogg, 1, 1, 30};

Will be heard 30 meters around only.

Thanks for that, the guy I've been trying to get it to work with has told me he's already changed that bit so it reads:

 sound[] = {"\sound\power_down.ogg",db-26.001,1}; 

and that has got it fine for how he wants it. What do the two 1's mean in the original piece of code ( sound[] = {\sound\power_down.ogg, 1, 1}; ), I'm told the 2nd one is pitch, is the first one volume but you can change it to an actual proper volume in decibels as he's done?

edit: nevermind, found the info about that here - http://community.bistudio.com/wiki/Description.ext#cfgSounds

Share this post


Link to post
Share on other sites
I know I repeat that all the time, but check that your sound is in Mono (if you want the 3D stuff to work). Also, in your CfgSounds, you can add another parameter to tweak the hearing range of the sound:

sound[] = {\sound\power_down.ogg, 1, 1, 30};

Will be heard 30 meters around only.

I've never seen any documentation on this and a small test did not change the distance at all. I put 1 as the volume and 1 as the "distance" and could still hear it miles away.

I know that say has a maxTitlesDistance but frankly I've never seen it do any change.

Thanks for that, the guy I've been trying to get it to work with has told me he's already changed that bit so it reads:

 sound[] = {"\sound\power_down.ogg",db-26.001,1}; 

and that has got it fine for how he wants it. What do the two 1's mean in the original piece of code ( sound[] = {\sound\power_down.ogg, 1, 1}; ), I'm told the 2nd one is pitch, is the first one volume but you can change it to an actual proper volume in decibels as he's done?

edit: nevermind, found the info about that here - http://community.bistudio.com/wiki/Description.ext#cfgSounds

Yeah that will lower the hearing range. It was explained for me that the thing about the "volume" is that you're not directly changing the volume, you're editing the loss of volume for the sound curve. Here's a badly drawn picture to explain it.

gFlMaN4.png

Share this post


Link to post
Share on other sites
I've never seen any documentation on this and a small test did not change the distance at all. I put 1 as the volume and 1 as the "distance" and could still hear it miles away.

Oh, it does work. Although it might not be in meters, but some kind of coefficient as well?

Also, I'm still not sure about that volume thing, as it can take both number and db values. Your picture concerns the latter, right?

Share this post


Link to post
Share on other sites

Both actually, I just find db values to be easier to work with.

db-30 would be a value of 0.05 or similar, just guessing.

I'm pretty sure it works like this since if you stand directly on the sound source with a low value, you can hear the sound almost at its 'real' volume.

Increase the volume value to say 1 and you can still hear it at roughly the same volume, just a lot further away

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×