Jump to content
Sign in to follow this  
konyo

Script Activates, but wont de-activate when useraction pressed.

Recommended Posts

Slight problem.. My Radio Chatter script activates fine when I press the User Action to turn the Chatter on, but as soon as I press it the Chatter Off option doesn't appear? It still says Chatter On, and when your press it again it then generates the script again running it twice, which causes loads of chatter at the same time? I'm guessing its because the script doesn't have an off variable? Any tips? :confused:

private ["_heli", "_sound", "_sounddata", "_oldsound"];

_heli = _this select 0;
_sounddata = ["radioChatter1","radioChatter2","radioChatter3","radioChatter4","radioChatter5","radioChatter6","radioChatter7","radioChatter8","radioChatter9","radioChatter10","radioChatter11","radioChatter12","radioChatter13","radioChatter14","radioChatter15","radioChatter16","radioChatter17","radioChatter18","radioChatter19"];
sleep 1;
if (isnil "kyo_chatter") then {kyo_chatter = [false, ""];};
if (isnil "kyo_chatterMinDelay") then {kyo_chatterMinDelay = 30;};
if (isnil "kyo_chatterMaxDelay") then {kyo_chatterMaxDelay = 60;};
if (isnil "kyo_chatterDisabled") then {kyo_chatterDisabled = false;};
if (isnil "_sound") then {_sound = "";};
if (isnil "_oldsound") then {_oldsound = "";};

waituntil {({alive _x} count (crew _heli)) > 0}; 

while {alive _heli && !(kyo_chatterDisabled)} do { 
if (isServer) then {
	if ({alive _x} count (crew _heli) > 0) then {
		sleep kyo_chatterMinDelay + (random kyo_chatterMaxDelay - kyo_chatterMinDelay);
		while {_sound == _oldsound} do {
			_sound = _sounddata select floor(random count _sounddata);
		};
		kyo_chatter = [true, _sound];
		publicVariable "kyo_chatter";
	};

};

waitUntil {kyo_chatter select 0};

if (vehicle player == _heli) then {
	_sound = kyo_chatter select 1;
	if (cameraOn == _heli && cameraView == "External") then {
		playSound format ["%1_L", _sound];
	} else {
		if (player == driver _heli || player == gunner _heli) then {
			playSound format ["%1_H", _sound];
		} else {
			playSound format ["%1_L", _sound];
		};
	};
};
sleep 2;
if (isServer) then {
	kyo_chatter set [0, false];
	publicVariable "kyo_chatter";
	_oldsound = _sound
};
sleep 1;
};

if (!alive _heli) exitWith {};
waituntil {!(kyo_chatterDisabled)};
[_heli] execVM "\kyo_MH47E\scr\radioChatter.sqf";

Share this post


Link to post
Share on other sites

I don't see you adding a user action to turn it off anywhere.

Share this post


Link to post
Share on other sites
I don't see you adding a user action to turn it off anywhere.

That's added in the config..

class ChatterOFF 
		{
			displayName = "Radio Coms Off";
			position = "Switch";
			radius = 2.5;
			condition = "(player == (driver this)) && (alive this) && (this getVariable [""kyo_Chatter"", false])"; 
			statement = "[this, false] execVM ""\kyo_MH47E\scr\radioChatter.sqf"";";
			onlyforplayer = 0;
			priority = 5;
			showWindow = 0;
		};

		class ChatterON 
		{
			displayName = "Radio Coms On";
			position = "Switch";
			radius = 2.5;
			condition = "(player == (driver this)) && (alive this) && !(this getVariable [""kyo_Chatter"", false])";
			statement = "[this, true] execVM ""\kyo_MH47E\scr\radioChatter.sqf"";";
			onlyforplayer = 0;
			priority = 5;
			showWindow = 0;
		};

Edited by konyo

Share this post


Link to post
Share on other sites

Hi Konyo,

Very exited about your MH-47.

In the config, the condition for the useraction is a variable attached to the MH-47 using getvaraible. In your script, nowhere do I see setvariable being used on _heli to set it's "kyo_Chatter" variable to true. Hence, the chatter off action will never appear because this getvariable["kyo_Chatter",false] will return false.

Perhaps I am missing something, but I believe that is the issue.

Share this post


Link to post
Share on other sites
Hi Konyo,

Very exited about your MH-47.

In the config, the condition for the useraction is a variable attached to the MH-47 using getvaraible. In your script, nowhere do I see setvariable being used on _heli to set it's "kyo_Chatter" variable to true. Hence, the chatter off action will never appear because this getvariable["kyo_Chatter",false] will return false.

Perhaps I am missing something, but I believe that is the issue.

Ok thanks, I have no scripting skill's so what would I add? & where? :p

Share this post


Link to post
Share on other sites
Ok thanks, I have no scripting skill's so what would I add? & where? :p

Hi Konyo,

Script to turn on radio chatter could look like this:

_heli = _this select 0;

_sounddata = ["radioChatter1","radioChatter2","radioChatter3","radioChatter4","radioChatter5","radioChatter6","radioChatter7","radioChatter8","radioChatter9","radioChatter10","radioChatter11","radioChatter12","radioChatter13","radioChatter14","radioChatter15","radioChatter16","radioChatter17","radioChatter18","radioChatter19"];

//Each CH-47 has a variable "kyo_chatter" attached to it which determines whether chatter is enabled for that aircraft

//_heli setvariable["kyo_Chatter",true] will set that variable to true

//_heli getvariable["kyo_Chatter",false]) will returnt eh value of kyo_chatter. If kyo_chatter is undefined, it will return false.

_chatter=_heli setvariable["kyo_Chatter",true];

//Keep running this loop until either the helo is destroyed or chatter is turned off. If chatter is turned off, action to turn it back on will be available again and will restart the script if used

while{(alive heli) && (_heli getvariable["kyo_Chatter",false])} do {

//Here put code to loop radio chatter.

};

Script to turn off radio chatter could look like this:

_heli = _this select 0;

_chatter=_heli setvariable["kyo_Chatter",false];

// now that Kyo_chatter is set to false for the MH-47, the loop that plays the chatter will exit and the action to turn chatter back on will be available again.

Share this post


Link to post
Share on other sites

So now my radioChatter.sqs looks like this? Is this correct?

If so the sounds aren't playing and the option to turn it off now wont disappear.

private ["_heli", "_sound", "_sounddata", "_oldsound"];

_heli = _this select 0;
_sounddata = ["radioChatter1","radioChatter2","radioChatter3","r adioChatter4","radioChatter5","radioChatter6","rad ioChatter7","radioChatter8","radioChatter9","radio Chatter10","radioChatter11","radioChatter12","radi oChatter13","radioChatter14","radioChatter15","rad ioChatter16","radioChatter17","radioChatter18","ra dioChatter19"];

//Each CH-47 has a variable "kyo_chatter" attached to it which determines whether chatter is enabled for that aircraft
//_heli setvariable["kyo_Chatter",true] will set that variable to true
//_heli getvariable["kyo_Chatter",false]) will returnt eh value of kyo_chatter. If kyo_chatter is undefined, it will return false.

_chatter=_heli setvariable["kyo_Chatter",true];

//Keep running this loop until either the helo is destroyed or chatter is turned off. If chatter is turned off, action to turn it back on will be available again and will restart the script if used
while{(alive heli) && (_heli getvariable["kyo_Chatter",false])} do {
sleep 1;
if (isnil "kyo_chatter") then {kyo_chatter = [false, ""];};
if (isnil "kyo_chatterMinDelay") then {kyo_chatterMinDelay = 30;};
if (isnil "kyo_chatterMaxDelay") then {kyo_chatterMaxDelay = 60;};
if (isnil "kyo_chatterDisabled") then {kyo_chatterDisabled = false;};
if (isnil "_sound") then {_sound = "";};
if (isnil "_oldsound") then {_oldsound = "";};

waituntil {({alive _x} count (crew _heli)) > 0}; 

while {alive _heli && !(kyo_chatterDisabled)} do { 
if (isServer) then {
	if ({alive _x} count (crew _heli) > 0) then {
		sleep kyo_chatterMinDelay + (random kyo_chatterMaxDelay - kyo_chatterMinDelay);
		while {_sound == _oldsound} do {
			_sound = _sounddata select floor(random count _sounddata);
		};
		kyo_chatter = [true, _sound];
		publicVariable "kyo_chatter";
	};

};

waitUntil {kyo_chatter select 0};

if (vehicle player == _heli) then {
	_sound = kyo_chatter select 1;
	if (cameraOn == _heli && cameraView == "External") then {
		playSound format ["%1_L", _sound];
	} else {
		if (player == driver _heli || player == gunner _heli) then {
			playSound format ["%1_H", _sound];
		} else {
			playSound format ["%1_L", _sound];
		};
	};
};
sleep 2;
if (isServer) then {
	kyo_chatter set [0, false];
	publicVariable "kyo_chatter";
	_oldsound = _sound
};
sleep 1;
};

if (!alive _heli) exitWith {};
waituntil {!(kyo_chatterDisabled)};
[_heli] execVM "\kyo_MH47E\scr\radioChatter.sqf"; 

Edited by konyo

Share this post


Link to post
Share on other sites

Not sure if this answers your question. I have a similar situation. The examples I based mine on used an animationState to set the userAction condition. I think the problem is that your variable is not available at the time that the condition is validated. This is my speculation, please don't shoot me if I'm wrong. :confused:

Share this post


Link to post
Share on other sites
So now my radioChatter.sqs looks like this? Is this correct?

I don't know anything about the syntax difference between sqs and sqf. I've only worked in SQF. In any case, if you'd like to talk more message me on steam and I can try to help.

Share this post


Link to post
Share on other sites

Solved! Thanks Shadow :D

Edited by konyo

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  

×