Jump to content
Sign in to follow this  
A-SUICIDAL

Need help with stopping a sound

Recommended Posts

I have an action added to a player to "Play Music" and then removes the action. What I would like to do is then add another action for "Stop Music". Basically the music is really a just a sound file using: playSound "track1";

I've tried the car radio addon, but I'm not really interested in all that, I just wanted to offer 1 sound file to be turned on or off when desired. I've searched a lot before asking for help here, but couldn't find anything to help me with this.

Share this post


Link to post
Share on other sites

Figured it out, you can do two actions, placed into the players init line. There is probably a prettier way of doing this but here we go:

this addAction ["Play Music", "playmusic.sqf"]; 

this addAction ["Stop Music", "stopmusic.sqf"]

playmusic.sqf

hintsilent "The muisc is playing";

playMusic "Track1";

stopmusic.sqf

hintsilent "The music has stopped.";

playmusic ""; 

If you want it to end abruptly then do the above method, if you want it fade then add in the fadeMusic command. You can also do random soundtracks rather than just the one using an array.

Edited by cobra4v320

Share this post


Link to post
Share on other sites

just an fyi:

if (true) exitwith {};

this code is not needed at the end of a sqf script.

a sqf script will exit on its own at the end.

Share this post


Link to post
Share on other sites

Will this work with a playSound? My Music is actually a sound file, so I use "playSound" to start playing the music. Normally I have my in-game music always turned off and I never add a jukebox module to my missions or use "playMusic" ever, because I don't like the music that comes with this game. lol. Most all of my friends always have their in-game music turned off too. So I figured by using playSound, I could force the music to be heard even if their in-game music volume is turned off, but if they really don't want to hear the music, I wanted to give them the option to turn it off. I've already tried Cobra's method, but I tried using "playSound" instead - and it does not work. Basically it gives me a missing sound error when I try to use playSound ""; I've even tried creating a blank sound file that plays 4 seconds of silence and named it blank.ogg and tried to stop the sound by using playSound "blank"; but it just keeps playing. I guess it's just not possible and the only alternative is to actually turn my music volume up in the game and start using playMusic instead of playSound. That sux, lol.

---------- Post added at 05:30 AM ---------- Previous post was at 05:27 AM ----------

In some missions I use:

plane1 say "track1";

and then the sound does stop when the vehicle is destroyed. And I was able to make the sound play again when the vehicle respawned.

---------- Post added at 05:43 AM ---------- Previous post was at 05:30 AM ----------

lol, soooo... I addAction "Music On" which creates and attaches a radio to the player and uses radio say "track1"; to make the sound(music) play - and removes the action while adding another action "Music Off" which when selected would delete the radio and stop the sound - and add the action back "Music On" again. Maybe attach the radio in such a way that it's hidden in the players rib cage, heh. Nah, then it would float in the air if the player were to go prone. Or better yet, attach the radio to the inside of the jet cockpit, yeah, that might work.

---------- Post added at 07:34 AM ---------- Previous post was at 05:43 AM ----------

Actually, my crazy idea works perfect, but better suited for the single player mission I am working on.

I added this to my vehicle's init:

this addAction ["Music On", "music_on.sqf", [], -1, false, true, "", "(_this in _target)"];

Then created a music_on.sqf:

_man = _this select 0;
_act = _this select 2;
if (alive _man) then
{
_man removeAction _act;

radio = "Radio" createVehicle [0,0,0];
radio attachTo [plane1,[0,2,-1]];
radio say "track1";

p1 addAction ["Music Off", "music_off.sqf", [], -1, false, true, "", "(_this in _target)"]; 
};

Then I created a music_off.sqf:

_man = _this select 0;
_act = _this select 2;
if (alive _man) then
{
_man removeAction _act;

deleteVehicle radio;

p1 addAction ["Music On", "music_on.sqf", [], -1, false, true, "", "(_this in _target)"]; 
};

Basically when I get in my F-16 it gives me the option "Music On" and when I select it - it removes the action and attaches a radio inside my plane and the radio says the sound file and adds the action "Music Off". When I choose "Music Off" it deletes the radio which stops the sound and adds back the option "Music On".

Since my single player mission does have respawn in it for the player, the AI and vehicles, I also added an empty trigger (0 radius, activation none) and in the "Condition" I put:

!alive plane1

and in the "On Act." I put:

deleteVehicle radio

Which deletes the radio if the plane is destroyed.

Again, I don't like any in-game music turned on, so this is one way to get my sound to stop when I want it too. It also seems kind of cool when I eject and hear the music fade away as my plane descends towards the ground, except the pitch increases and starts sounding like it mickey mouse, like it sucked some helium. Is there a way to fix that by adjusting the class CfgSounds and editing the number that comes after the volume number?

sound[]={"sound\track1.ogg",1,1};

---------- Post added at 07:53 AM ---------- Previous post was at 07:34 AM ----------

Ok, that's the pitch I guess.

Edited by A-SUICIDAL

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  

×