Jump to content
Golden Knee

[SOLVED] Canceling a say3D sound loop

Recommended Posts

I'm trying to stop a say3D sound loop when the player uses the action. Here's what I have so far:

 

_generator1 = (_this select 0);

 

glb_Turn_Off_Generator = false;

 

publicVariable "glb_Turn_Off_Generator";

 

_answerAction = _generator1 addAction ["Turn Off Generator", 

{ glb_Turn_Off_Generator = true; publicVariable "glb_Turn_Off_Generator"; }, 

[], 6, true, true, "", "_this distance _target < 3"

];

 

while {!glb_Turn_Off_Generator} do

{

    _generator1 say3D "sound2";

    sleep 7; 
 
};


Player SwitchMove "AinvPercMstpSrasWrflDnon_Putdown_AmovPercMstpSrasWrflDnon";

deleteVehicle _generator1;
_generator1 removeAction _answerAction;

 

My problem is that the animation is delayed until the sound file completes its last loop. I have tried deleteVehicle, say3D "", setDamage 1. Nothing seems to interrupt the sound.

I could just reduce the sound file to one second but would be a last resort. Any ideas?

 

 

Share this post


Link to post
Share on other sites

You should put the animation portion into the activation statement of the addAction. By doing this, the animation will run when the action is activated and it will not have to wait until the last round of the sound loop (the codes run in separate threads).

 

Like so:

Spoiler

_generator1 = (_this select 0);
 
glb_Turn_Off_Generator = false;
 
publicVariable "glb_Turn_Off_Generator";
 
_answerAction = _generator1 addAction ["Turn Off Generator", 
"generator_off.sqf", [], 6, true, true, "", "_this distance _target < 3"];

while {!glb_Turn_Off_Generator} do
{
    _generator1 say3D "sound2";
    sleep 7; 
};

 

 

Spoiler

generator_off.sqf


_generator = _this select 0;

// This unit turned off the generator
_unit = _this select 1;
_action_id = _this select 2;

_unit SwitchMove "AinvPercMstpSrasWrflDnon_Putdown_AmovPercMstpSrasWrflDnon";
deleteVehicle _generator;

glb_Turn_Off_Generator = true;
publicVariable "glb_Turn_Off_Generator";

_generator removeAction _action_id;

 

You'll need to create the file generator_off.sqf. Note, you could've put all the code in generator_off.sqf into the activation statement directly but I did this for the sake of clarity.

  • Like 1

Share this post


Link to post
Share on other sites

Dude you don't know how happy you've made me. I've been banging my head against the wall trying to figure it out 

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

×