Jump to content
Sign in to follow this  
spades_neil

Play sounds/music from a radio prop

Recommended Posts

A couple other threads touch on this topic, but one of them links the solution to a dead forum and the other doesn't exactly answer the question--and the thread was locked for being in the wrong section.

If I want a radio (or any other object) to play a music on a loop, with said radio being the source of the sound, how can I achieve this? Like I want it to be dynamic so as a player walks closer or farther, the music gets louder or quieter.

Let's assume the prop's name is MusicRadio. Let's assume also that I already know how to add custom sounds to my mission, so we can skip that part. So can anyone help me out?

Other applications of this may include a loudspeaker, a propaganda tower, etc.

Share this post


Link to post
Share on other sites
If I want a radio (or any other object) to play a music on a loop, with said radio being the source of the sound, how can I achieve this?

while {(alive MusicRadio)} do
{
MusicRadio say3D "Track1";
sleep 180;//track length + some few seconds here
};

Where "Track1" is name of the class defined eg in Description.ext under class CfgSounds and musicRadio is an object. Of course list can be longer, like:

while {off == 0} do
{
radio1 say3d "bushes";
sleep 107;
radio1 say3d "Vintner";
sleep 18;
radio1 say3d "autumn";
sleep 322;
radio1 say3d "Vintner";
sleep 18;
};

 Like I want it to be dynamic so as a player walks closer or farther, the music gets louder or quieter.

Arma's engine will provide this by itself when say3D command is used. Note also in exemplary sound register:

class CfgSounds
{
sounds[] = {};
 class Track1
 {
  name = "Track1";   
  sound[] = {"Sounds\Track1.ogg", db+0, 1, [color="#FF0000"]50[/color]};   
  titles[] = {};
 };
};

red value. Seems, that this is distance from the source defined in meters, above which sound will rapidly fade away with further distance growing.

Edited by Rydygier

Share this post


Link to post
Share on other sites
while {(alive MusicRadio)} do
{
MusicRadio say3D "Track1";
sleep 180;//track length + some few seconds here
};

Where "Track1" is name of the class defined eg in Description.ext under class CfgSounds and musicRadio is an object. Of course list can be longer, like:

while {off == 0} do
{
radio1 say3d "bushes";
sleep 107;
radio1 say3d "Vintner";
sleep 18;
radio1 say3d "autumn";
sleep 322;
radio1 say3d "Vintner";
sleep 18;
};

 Like I want it to be dynamic so as a player walks closer or farther, the music gets louder or quieter.

Arma's engine will provide this by itself when say3D command is used. Note also in exemplary sound register:

class CfgSounds
{
sounds[] = {};
 class Track1
 {
  name = "Track1";   
  sound[] = {"Sounds\Track1.ogg", db+0, 1, [color="#FF0000"]50[/color]};   
  titles[] = {};
 };
};

red value. Seems, that this is distance from the source defined in meters, above which sound will rapidly fade away with further distance growing.

OoooOOOoooo... So I can set up a whole playlist if I like?

The above two scripts, depending on which one I choose, do they go into my init.sqf? Or do I drop them elsewhere and write [] execVM "whatever-path-the-radio-config-uses.sqf"; in my init.sqf file?

I already know the third one belongs in description.ext

Share this post


Link to post
Share on other sites

Yep. You only must to know length of each track to set sleep length properly after it. Any particular playlist loop of that kind can be left in init.sqf directly, at the very end or spawned there in separate scope, or in separate sqf file, only execVM-ed from init.sqf. With more scripting playlist can be randomized/shuffled as well. In fact second example comes from some my never finished mission project, where indeed was radio object that played listed tracks (one as jingle) plus some static radio hum in the background.

So perhaps some untested examples of init.sqf:

//any other stuff

[] spawn
{
while {(alive RadioMusic)} do
	{
	RadioMusic say3d "Track1";
	sleep 120;
	RadioMusic say3d "Track2";
	sleep 180;
	RadioMusic say3d "Track3";
	sleep 90;
	RadioMusic say3d "Track4";
	sleep 150;
	}
};

//more other stuff

same, but with shuffled order each time:

//other init stuff

[] spawn //spawn the loop in separate scope
{
while {(alive RadioMusic)} do //repeat cycles as long radio is not destroyed
	{
	_tracks = //playlist refilled each cycle - array of arrays
		[
		["Track1",120],//each element holds name and length of the one track
		["Track2",180],
		["Track3",90],
		["Track4",150]
		];

	while {((count _tracks) > 0)} do//internal loop - lasts as long as there is at least one not played yet track in the playlist
		{
		_selection = floor (random (count _tracks));//random playlist position number
		_track = _tracks select _selection;//pick random element from _tracks
		_sleep = _track select 1;//length
		_track = _track select 0;//name

		_tracks set [_selection,"Delete"];
		_tracks = _tracks - ["Delete"];//remove for now chosen track from the playlist, so will be not repeated in this cycle

		RadioMusic say3d _track;//let's play
		sleep _sleep;//let's wait, until played track is over

		if not (alive RadioMusic) exitWith {}//exit if radio destroyed
		}
	}
};

//more other stuff

Edited by Rydygier

Share this post


Link to post
Share on other sites

Where can I find a list of music tracks in ArmA 2? I want to go through them and find some that I like. More importantly, how do I attach the script here to the object in-game? Or is that already covered by me just naming the object MusicRadio? Although I don't see any indication in the script to that. I see RadioMusic, but not MusicRadio. Not sure if mere typo or something else.

Simply dropping the file in the init.sqf seems to accomplish nothing, however.

Edited by Spades_Neil

Share this post


Link to post
Share on other sites
Where can I find a list of music tracks in ArmA 2?

http://community.bistudio.com/wiki/ArmA_2:_Music

also in "effects" of any trigger in editor. Not sure, however I believe, that these tracks are registered in cfgMusic, not cfgSounds, so probably can't be used for 3D sound say3D command (?). If you know paths to sound files with these tracks (I don't), probably you can register them also under cfgSounds. Otherwise you need own music ogg or wss files somewhere in mission/addon folder.

I see RadioMusic, but not MusicRadio.

Typo. Just name in editor source object same way, as in the script, Name can be nearly any of course. RadioMusic is only an example.

Simply dropping the file in the init.sqf seems to accomplish nothing, however.

Without sound files porperly registered in Description.ext under CfgSounds, there will be no effect. This is also untested code, so syntax errors possible (there was one, corrected).

Check this demo:

RadioDemo

Edited by Rydygier

Share this post


Link to post
Share on other sites
http://community.bistudio.com/wiki/ArmA_2:_Music

also in "effects" of any trigger in editor. Not sure, however I believe, that these tracks are registered in cfgMusic, not cfgSounds, so probably can't be used for 3D sound say3D command (?). If you know paths to sound files with these tracks (I don't), probably you can register them also under cfgSounds. Otherwise you need own music ogg or wss files somewhere in mission/addon folder.

Typo. Just name in editor source object same way, as in the script, Name can be nearly any of course. RadioMusic is only an example.

Without sound files porperly registered in Description.ext under CfgSounds, there will be no effect. This is also untested code, so syntax errors possible (there was one, corrected).

Check this demo:

RadioDemo

It works! :D Now, a final question, is there any way to turn up the volume? Or do I have to manually edit the file? (Looks like the file its self is already a low volume.)

I also noticed it's possible to shoot the radio and knock it around. Any way to make it more static so it doesn't go anywhere?

Edited by Spades_Neil

Share this post


Link to post
Share on other sites

Volume better to have set directly in the sound file. You can also try to manipulate with first and third number in Description.ext entry, here:

sound[] = {"Sounds\Track1.ogg", db+0, 1, 50};

(I do not know, why there is "db+" part before 0). Frankly never noticed big effect with this number manipulation. More noticeable impact have third number (described earlier), but it is not directly volume controller, only for fading volume with distance. Second is for sound pitch.

If I remeber correctly, there was some tricks to "stick" the object. You can try attachTo a logic object placed in editor or, simplier, try enableSimulation (put: this enableSimulation false; into radio's init field, then you can't move it even with satchel charge).

Edited by Rydygier

Share this post


Link to post
Share on other sites
Volume better to have set directly in the sound file. You can also try to manipulate with first and third number in Description.ext entry, here:

sound[] = {"Sounds\Track1.ogg", db+0, 1, 50};

(I do not know, why there is "db+" part before 0). Frankly never noticed big effect with this number manipulation. More noticeable impact have third number (described earlier), but it is not directly volume controller, only for fading volume with distance. Second is for sound pitch.

If I remeber correctly, there was some tricks to "stick" the object. You can try attachTo a logic object placed in editor or, simplier, try enableSimulation (put: this enableSimulation false; into radio's init field, then you can't move it even with satchel charge).

Any particular codec that the music requires? Aside from OGG format--because I tried to play some other songs, and they didn't work.

Share this post


Link to post
Share on other sites

I'm not sure about that. Check ogg type in my demo - these are working for sure. :)

Share this post


Link to post
Share on other sites

Hi !

I don't wanna start a new thread, so i ask here. I need a simple script with i can turn on music in a vehicle (or better a whole list of music).

Conditions:

- Add action only when the player is in the vehicle

- The actions must be colored (maybe orange)

- Action name is just "play music"

Or better would be to add an action to turn on the radio and the player can choose from a tracklist in actionmenu.

Someone can help ? :)

maxx

PS: Im so confused about Arma scripts i have noone who can explain how to make those scripts and talk german. So my only hope is this forum :(

Share this post


Link to post
Share on other sites

Hi !

I tried the loudspeaker script. And i use it for my base now not for the vehicles (well i have to find another one for that problem ;) ). The only problem i had was...when a second player join the server, his music also start and i heared 2 songs the same time but delayed. That is a big problem...imagine when 10 players join the same time. So i tried to change the whole script. And i dont know if that will work correctly...maybe you can help ?

1. I placed an object:

- Name: loudspeaker

2. I placed a trigger with following conditions:

- Activation: anybody

- Once

- Condition: player == vehicle player

- On Act. : nul = execVM "loudspeaker\playlist.sqf"

3. My "playlist.sqf" look like this (I don't use an init.sqf entry for this, only activated by the trigger):

/////////////////////////////////////////////////////////////////////////////

while {true} do {

sleep 5;

radio_H = "HeliHEmpty" createVehicle (position loudspeaker);

radio_H attachTo [loudspeaker,[0,0,0]];

radio_H say3D "track1";

sleep 30; // <<======== Track 1 song length

deleteVehicle radio_H;

sleep 1;

radio_H = "HeliHEmpty" createVehicle (position loudspeaker);

radio_H attachTo [loudspeaker,[0,0,0]];

radio_H say3D "track2";

sleep 30; // <<======== Track 2 song length

deleteVehicle radio_H;

sleep 1;

radio_H = "HeliHEmpty" createVehicle (position loudspeaker);

radio_H attachTo [loudspeaker,[0,0,0]];

radio_H say3D "track3";

sleep 30; // <<======== Track 3 song length

deleteVehicle radio_H;

sleep 1;

radio_H = "HeliHEmpty" createVehicle (position loudspeaker);

radio_H attachTo [loudspeaker,[0,0,0]];

radio_H say3D "track4";

sleep 30; // <<======== Track 4 song length

deleteVehicle radio_H;

sleep 1;

radio_H = "HeliHEmpty" createVehicle (position loudspeaker);

radio_H attachTo [loudspeaker,[0,0,0]];

radio_H say3D "track5";

sleep 26; // <<======== Track 5 song length

deleteVehicle radio_H;

};

/////////////////////////////////////////////////////////////////////////////

The big question now is, will i have the same problem again ? I think the music will only be heared by the player who activated the script, not the others ?

By the way..when i join the server and activate the trigger, i can hear the music. When i join again the script start again with the first song.

But i think because of the "say3D" command for the object, the players can hear their music and the music from a player who join, or not ?

maxx

PS: Sorry im a total script noob :(

Edited by maxx2504

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  

×