Editors Depot - Mission Editing and Scripting > Arma2 - Editing/Scripting General

Making a script so it activates and de-activates with a user action?

(1/1)

konyo:
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?

Here's the radiochatter.sqs.

--- Code: ---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";
--- End code ---

& here's the user action that's in my helicopters config.


--- Code: ---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;
};
--- End code ---

h-:
I'm not going to go into all the things I don't really get in your script (like why you're passing a boolean into it which is never used..), but:


--- Code: ---(this getVariable [""kyo_Chatter"", false])
--- End code ---
AFAIK it should be this getVariable ""kyo_Chatter"" instead.
Or better yet, this getVariable {kyo_Chatter} (prettier syntax)..

And if you're using that syntax you have to 'init' the variable in the vehicles init with:
_heli setVariable ["kyo_Chatter",false,true]; //that last true is for MP making the variable broadcast, or whatever. Use false if you need to..

In your script do something like:

--- Code: ---private ["_heli", "_sound", "_sounddata", "_oldsound"];

_heli = _this select 0;
_heli setVariable ["kyo_Chatter",true,true];

... //this just demonstrates all the script between these lines..

private["_handle"];
_handle = [_heli] execVM "\kyo_MH47E\scr\radioChatter.sqf";
_heli setVariable ["kyo_chatterscript_handle",_handle];

--- End code ---

Chatter on action:

--- Code: ---condition = "(player == (driver this)) && (alive this) && !(this getVariable {kyo_Chatter})";
statement = "kyo_chatterhandle = [this, true] execVM ""\kyo_MH47E\scr\radioChatter.sqf""; this setVariable [{kyo_chatterscript_handle},kyo_chatterhandle,true]";
--- End code ---

Then in the Chatter off action:

--- Code: ---condition = "(player == (driver this)) && (alive this) && (this getVariable {kyo_Chatter})";
statement = "terminate (this getVariable {kyo_chatterscript_handle})";
--- End code ---

Might work :dunno: :dunno:

F2kSel:
using (this getVariable [""kyo_Chatter"", false]) will return false if it hasn't been defined that's what the second parameter is doing it's in effect giving it a default variable.

konyo:
Thanks for your replys guys, bewteen the time I posted this and you both replying I had been fixed, I just came back here to put that in the post. Thank you both for your time and effort though :)

Navigation

[0] Message Index

Go to full version