Jump to content

[WIP] Musical Radios


CartoonrBOY

Recommended Posts

I'm developing a music mod that plays from a radio. At present I can play music using a radio but the music does not get quieter further from the source.This is due to the sound being linked to the player. Other players can hear the music but it does not repeat.

 

Unpack your mission.pbo. Create a 2 folders in the root. One called: sound (you may already have this), the other called: fixes, or use your custom mod folder (edit the code in the fn_selfActions file accordingly).

 

Download the file.

 

Copy the sound file (battery.ogg) into the sound folder.

 

Copy the battery folder into the fixes (mod) folder.

 

In your fn_selfActions file add to the bottom:

private["_ismammoth"];

_ismammoth = cursorTarget isKindOf "MAP_radio";

if (_ismammoth) then {
	dayz_addbattery = player;
	if (s_player_battery_on < 0) then {
        s_player_battery_on = player addAction ["Listen...","fixes\battery\radio_on.sqf",dayz_addbattery, 2, false, true, "", ""];
		};
    } else {
        dayz_addbattery removeAction s_player_battery_on;
        s_player_battery_on = -1;
	};

In your description.ext add into the class CfgSounds section before the closing quotes:

class battery
{
    name = "battery";
    sound[] = {\sound\battery.ogg, 0.4, 1.0};
    titles[] = {};
	};

And add in this section:

class CfgSounds
{
  sounds[]={battery};

Note: you only need to add the word: battery, into this section if you already have other sounds.

 

Next you will have to add the item: MAP_radio, into the map. Either use the editing tool or as I do use the mod. The radio is the small white radio in the misc section.

 

When you look at the radio you'll see the option to: Listen... Selecting: Listen... plays the track once.

 

Note: You can change the track using Easy MP3 Cutter to sample the new file into the .ogg format.

 

File: MusicalRADIOS

 

Ideally I'd like the sound to repeat play from the radio without the switch, and to get quieter the further from the source you go. If anyone has any advice or comments they'd be gratefully received.

Link to comment
Share on other sites

This is my progress so far. To get the music to repeat; the last sleep command must be the exact length of the track. As the sleep command is not in seconds it takes a little trial and error to make it fit seamlessly. I'm hoping there's a better way for the repetition:

_musicrange = 100;
_radio = _cursorTarget;

PLAYMUSIC = true;

while {true} do {
    _nul = [objNull, _radio, rSAY, "battery", _musicrange] call RE;
    sleep 70.1;
};

To stop the music it may be necessary to create another fn_selfActions file which states:

PLAYMUSIC = false;

The range of the track does not have to be limited to 100, it could be any figure.

Link to comment
Share on other sites

If u want the sound to fade away the further you go, use someting like: _radio say [songname, 1000];

1000 being the distance. Ill explain better later, at my phone atm.

 

Thanks. I added a parameter called; _musicrange = 100. This sets the distance of the sound to that range which works great. It even simulates the doppler effect which is impressive.

 

The repetition of the track is controlled by the sleep command, but it must be exactly the same length as the track which can be difficult to get right as the sleep command is not in seconds.

 

I'm curious whether there's a better way to repeat the track?

Link to comment
Share on other sites

Thanks. I added a parameter called; _musicrange = 100. This sets the distance of the sound to that range which works great. It even simulates the doppler effect which is impressive.

 

The repetition of the track is controlled by the sleep command, but it must be exactly the same length as the track which can be difficult to get right as the sleep command is not in seconds.

 

I'm curious whether there's a better way to repeat the track?

If you want to repeat track(s) would this work?

REPEAT_MUSIC = {
playSound "blah";
sleep 12537365545;
playSound "fdds";
// And So on...
if(_stop == 1) then { exitWith "";};
} call REPEAT_MUSIC;

Then make the _stop a global variable, and call it through fn_selfActions.sqf or something similiar.
Link to comment
Share on other sites

 

If you want to repeat track(s) would this work?

REPEAT_MUSIC = {
playSound "blah";
sleep 12537365545;
playSound "fdds";
// And So on...
if(_stop == 1) then { exitWith "";};
} call REPEAT_MUSIC;

Then make the _stop a global variable, and call it through fn_selfActions.sqf or something similiar.

Umm, and what did you mean by the "sleep" command? It is in seconds... [delay: Number of seconds].

All you need is here.

Link to comment
Share on other sites

Umm, and what did you mean by the "sleep" command? It is in seconds... [delay: Number of seconds].

All you need is here.

 

Thanks. From experience the sleep command is unreliable as a timer, but I totally appreciate your advice. I'll experiment as I know the track length, but as you stated it should therefore work as intended.

 

I'll also give yer script a run. At the last test, each player that triggers the music eventually made a cacophony. Do have any idea how to make the music play one at a time, despite the number of players in the vicinity? Otherwise I may have to swap the track for thrash metal...

Link to comment
Share on other sites

Thanks. From experience the sleep command is unreliable as a timer, but I totally appreciate your advice. I'll experiment as I know the track length, but as you stated it should therefore work as intended.

 

I'll also give yer script a run. At the last test, each player that triggers the music eventually made a cacophony. Do have any idea how to make the music play one at a time, despite the number of players in the vicinity? Otherwise I may have to swap the track for thrash metal...

Got it sort-of working. Are you making it so the player can "listen" to the music from his radio so everyone hears it? Or are you trying to make it so the entity "Radio" plays music?

Link to comment
Share on other sites

Got it sort-of working. Are you making it so the player can "listen" to the music from his radio so everyone hears it? Or are you trying to make it so the entity "Radio" plays music?

 

The radio needs to know it's playing a track so that, if another player chooses to listen it does not play the same track over itself. At present it's possible to listen to several tracks at once. Do you think this would require a public event handler of sorts?

Link to comment
Share on other sites

The radio needs to know it's playing a track so that, if another player chooses to listen it does not play the same track over itself. At present it's possible to listen to several tracks at once. Do you think this would require a public event handler of sorts?

I still don't know how you are executing this. Why not just create a helihempty and make it rSay "battery" ??? Then add a if (RADIO_PLAYING) exitWith {} else { scripts here };

Link to comment
Share on other sites

This is the code with the problem: drunkmusic.sqf:

_musicdist = 100;
_coords = [4079.77675, 2738.2970, 4.3325453];
_music = createVehicle ["HeliHEmpty", _coords,[], 0, "NONE"];

REPEATMUSIC = true;

while {true} do {
    _nul = [objNull, _music, rSAY, "danceMusic", _musicdist] call RE;
    sleep 49.8;
};

I had an init.sqf to initiate the loading of the mod but all it did was check for the player spawn then load the file. I've combined this into one file.

 

I think if I add:

waitUntil {!isNil "dayz_animalCheck"};

_musicdist = 100;
_coords = [4079.77675, 2738.2970, 4.3325453];
_music = createVehicle ["HeliHEmpty", _coords,[], 0, "NONE"];

REPEATMUSIC = true;

while {true} do {
    _nul = [objNull, _music, rSAY, "battery", _musicdist] call RE;
    sleep 49.8;
};

if (REPEATMUSIC) exitWith {
	} 
	else
	{
	execVM "drunkard\drunkmusic.sqf"};

This should check whether the track is already playing if another player enters its range and exit if it is.

 

I'm yet to test this until the next restart. I'll post whether it's correct. Thank you muchly for your input Spodermayt.

Link to comment
Share on other sites

  • 2 months later...
  • 2 months later...

Hello. I do not understand a little. How it should work? Like, it is established, the file is loaded, errors aren't present. I should create in the menu craft radio. And then that? Scrolling by the mouse castor? Or how that in options it is necessary to include radio?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...