Jump to content
Sign in to follow this  
OB1

Stop sound

Recommended Posts

Hia again.

Ok. Strait to it. I have a number of sound of class cfgsounds. No triggers are involved I am calling the sound from a script, using a simple

vehiclename say "nameofsound"

I need the sound to be stopped where I please and because I am not using triggers I cannot just delete it to stop it. Is there a script command to silence or stop all custom played sounds ?

thanks.

Share this post


Link to post
Share on other sites

Here's the trick to that:

The only way to interrupt the a say command is by deleting the unit "saying" the sound. If you do not want to delete a character unit, then spawn a game logic at the speaking unit's location and have that "say" the sound.

Share this post


Link to post
Share on other sites

thats the only way ? oh dear... thats not going to work for me at all.. any way around this ? using different class sound or music ?

Share this post


Link to post
Share on other sites

Create an invisible H (HeliHEmpty), attach it to the vehicle, make it say the sound and delete it (setDamage 1 might work as well) when you want the sound to stop.

Share this post


Link to post
Share on other sites

How is that not going to work? Using a gamelogic or helipad works for lots of people. :)

Share this post


Link to post
Share on other sites

yeah i have not explained completely how I am going to be using this :), the multiple sound will be controlled by the player and will have the option via an add action where the playing can start a sound and stop a sound and do it as many times as the player so desires... by creating, destroying and attaching seems rather uneconomical...

Share this post


Link to post
Share on other sites

Just move it than. Create a invis heli called 'siren'. Move it to [1,1,1].

start.sqf:

siren attachTo [player,[0,0,0]];
siren say "siren";

stop.sqf:

detach siren;
siren setPos [1,1,1];

Then

this addAction ["Start", "start.sqf"]; this addAction ["Stop", "stop.sqf"]; 

If you call it more than once in 30 seconds you'll get overlapping sounds, but with the siren it's kinda cool. :) It'll get more complicated of course if you want it to loop until you tell it to stop of course. Coz then you need to worry about if the player dies or if he told it to stop then making sure to readd the actions after death and all that. :)

Share this post


Link to post
Share on other sites

ok thanks ill give that a go.

---------- Post added at 01:25 PM ---------- Previous post was at 01:09 PM ----------

Hmm ok this is how I think I have to do it but im not sure how to go about it;

Create invisible H-pad from script and assign name eg heli;

heli attachto [vehiclename,[0,0,0]];

heli say "sound";

then either upon the creation of a new sound or just to stop sound

new sound;

delete vehicle heli;

Create invisible H-pad from script and assign same name again : heli;

heli attachto [vehiclename,[0,0,0]];

heli say "sound";

stop sound;

delete vehicle heli;

so the way i see it we only need 2 scripts. 1 for stop sound and another for start sound or over write with new sound, this can be the same script.. soo how would this look in a script ?

Share this post


Link to post
Share on other sites

Try it like this:

init of your vehicle:

this setVariable ["sirenOn", false, true];
this setVariable["currentSiren", objNull, true];
this addAction ["Siren On","sirenOn.sqf",[],1,false,true,"","(driver _target == _this) && !(_target getVariable ""sirenOn"")"]; 
this addAction ["Siren Off","sirenOff.sqf",[],1,false,true,"","(driver _target == _this) && (_target getVariable ""sirenOn"")"];

sirenOn.sqf:

_car = _this select 0;
_car setVariable["sirenOn", true, true];
_car setVariable["currentSiren", objNull, true];
_siren = "HeliHEmpty" createVehicle [1,1,1];
_siren attachTo [_car,[0,0,0]];
_car setVariable["currentSiren", _siren, true];

// loop code adapted from police_sirens.sqf by one or more of the following: Coldfuse, DaChevs, Dead3yez, Armatec, Killerc22
for [{_i=0}, {_i < 1}, {_i=_i}] do
{
_siren say "siren";

if(!alive _car)exitwith{};
if(!(_car getVariable "sirenOn"))exitwith{};
sleep 30;
};

sirenOff.sqf:

_car = _this select 0;
_car setVariable["sirenOn", false, true];
_currentSiren =  _car getVariable "currentSiren";
detach _currentSiren;
deleteVehicle _currentSiren;
_car setVariable ["currentSiren", objNull, true];

Share this post


Link to post
Share on other sites

thanks allot kylania, ill give that ago once I have woken up abit more :)

Share this post


Link to post
Share on other sites

Ok kylania it works great ! thanks. now trying to add more than one sound is.... almost working..

if I just use the example you posted, I add another addAction lets just say its "Siren On2".

this setVariable ["sirenOn", false, true];
this setVariable["currentSiren", objNull, true];
this addAction ["Siren On","sirenOn.sqf",[],1,false,true,"","(driver _target == _this) && !(_target getVariable ""sirenOn"")"];
[color="#008000"]this addAction ["Siren On2","sirenOn2.sqf",[],1,false,true,"","(driver _target == _this) && !(_target getVariable ""sirenOn"")"];[/color]
this addAction ["Siren Off","sirenOff.sqf",[],1,false,true,"","(driver _target == _this) && (_target getVariable ""sirenOn"")"];

the action menu inside the vehicle works what seems to be perfect.. you play either "Siren On" or "Siren On2" and the rest of the menu disappears and displayed an option to turn what your playing off.

in the "SirenOn2.sqf"

_car = _this select 0;
_car setVariable["sirenOn", true, true];
_car setVariable["currentSiren", objNull, true];
_siren = "HeliHEmpty" createVehicle [1,1,1];
_siren attachTo [_car,[0,0,0]];
_car setVariable["currentSiren", _siren, true];

// loop code adapted from police_sirens.sqf by one or more of the following: Coldfuse, DaChevs, Dead3yez, Armatec, Killerc22
for [{_i=0}, {_i < 1}, {_i=_i}] do
{
_siren say "[color="#008000"]siren2[/color]";

if(!alive _car)exitwith{};
if(!(_car getVariable "sirenOn"))exitwith{};
sleep 30;
};

The script works fine for "Siren On" but no sound for "Siren On2", it appears to work but I think the Helipad is not attaching. So what needs adjusting you think or does this not suit at all ?

Share this post


Link to post
Share on other sites

You could just use the same script for both just change them slightly.

this setVariable ["sirenOn", false, true];
this setVariable["currentSiren", objNull, true];
this addAction ["Siren On","sirenOn.sqf",[[color="#FF0000"]"siren"[/color]],1,false,true,"","(driver _target == _this) && !(_target getVariable ""sirenOn"")"];
[color="#FF0000"]this addAction ["Siren On 2","sirenOn.sqf",["siren2"],1,false,true,"","(driver _target == _this) && !(_target getVariable ""sirenOn"")"]; [/color]
this addAction ["Siren Off","sirenOff.sqf",[],1,false,true,"","(driver _target == _this) && (_target getVariable ""sirenOn"")"];

_car = _this select 0;
[color="#FF0000"]_sirenType = _this select 3 select 0;[/color]
_car setVariable["sirenOn", true, true];
_car setVariable["currentSiren", objNull, true];
_siren = "HeliHEmpty" createVehicle [1,1,1];
_siren attachTo [_car,[0,0,0]];
_car setVariable["currentSiren", _siren, true];

// loop code adapted from police_sirens.sqf by one or more of the following: Coldfuse, DaChevs, Dead3yez, Armatec, Killerc22
for [{_i=0}, {_i < 1}, {_i=_i}] do
{
_siren say [color="#FF0000"]_sirenType[/color];

if(!alive _car)exitwith{};
if(!(_car getVariable "sirenOn"))exitwith{};
sleep 30;
};

Make sure you have siren2 properly declared in your description.ext

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  

×