Jump to content
Sign in to follow this  
abs

Stop a UserAction

Recommended Posts

Hi all,

I am super inexperienced when it comes to this stuff, so I appreciate any answer to my basic questions, or even a slap upside the head telling me that I'm doing it wrong.

My goal is to make a 'Red Alert' klaxon, and have it started and stopped by the user. I have partially done this, as can be seen here:

IkeVYDfG6tw

The problem is that I don't know how to stop it. Any searching that I've done shows me the old part of the forums where the code is no longer displayed properly and the formatting is all fucked up making it very difficult to read.

Here is the relevant part of my config.cpp:

	class UserActions
	{
		class redalertstart {
			userActionID = 1;
			displayName = "Red Alert";
			position = "RedAlert";
			radius = 10;
			showWindow = 0;
			onlyForPlayer = false;
			shortcut = "reloadMagazine";
			condition = "(player in [gunner this, driver this]) && (alive this)";
			statement = "this execVM ""\STA3_F_Vehicles\Data\scripts\redalert.sqf"";_redalert = 1;";
		};

This is my script:

_red = _this;
// Code
while {true} do {
_red setObjectMaterial [59,"\STA3_F_Vehicles\Data\STA3_RedLight.rvmat"];
_red setObjectTexture [60,"\STA3_F_Vehicles\Data\screens\EngSOH2_ca.paa"];
playSound3D ["STA3_F_Vehicles\Data\sound\STA3_RedAlert.wav", player];
sleep 0.956;
_red setObjectMaterial [59,"\STA3_F_Vehicles\Data\vs0.rvmat"];
_red setObjectTexture [60,"\STA3_F_Vehicles\Data\screens\EngSOH_ca.paa"];
sleep 0.956;
};

What's the best way to get this done?

Thanks in advance!

Abs

Share this post


Link to post
Share on other sites

you could put exit; at the end of the do while

_red = _this;
// Code
setting = true;
while {setting} do {
_red setObjectMaterial [59,"\STA3_F_Vehicles\Data\STA3_RedLight.rvmat"];
_red setObjectTexture [60,"\STA3_F_Vehicles\Data\screens\EngSOH2_ca.paa"];
playSound3D ["STA3_F_Vehicles\Data\sound\STA3_RedAlert.wav", player];
sleep 0.956;
_red setObjectMaterial [59,"\STA3_F_Vehicles\Data\vs0.rvmat"];
_red setObjectTexture [60,"\STA3_F_Vehicles\Data\screens\EngSOH_ca.paa"];
sleep 0.956;
exit;
};

or you could have another user input like how you did above but it forces a name to be false like (im not totally good at this but understand what you mean)

_red = _this;
// Code
while {true} do {
_red setObjectMaterial [59,"\STA3_F_Vehicles\Data\STA3_RedLight.rvmat"];
_red setObjectTexture [60,"\STA3_F_Vehicles\Data\screens\EngSOH2_ca.paa"];
playSound3D ["STA3_F_Vehicles\Data\sound\STA3_RedAlert.wav", player];
sleep 0.956;
_red setObjectMaterial [59,"\STA3_F_Vehicles\Data\vs0.rvmat"];
_red setObjectTexture [60,"\STA3_F_Vehicles\Data\screens\EngSOH_ca.paa"];
sleep 0.956;
};

and some how change the variable setting to false by user input ?

Share this post


Link to post
Share on other sites

I thought about that too, but when I tried it I couldn't get it working. I think I don't get the logic or process of what needs to be done exactly.

I've added this in my config:

	class UserActions
	{
		class redalertstart {
			userActionID = 1;
			displayName = "Red Alert";
			position = "RedAlert";
			radius = 10;
			showWindow = 0;
			onlyForPlayer = false;
			shortcut = "reloadMagazine";
			condition = "(player in [gunner this, driver this]) && (alive this) && (setting == 0)";
			statement = "this execVM ""\STA3_F_Vehicles\Data\scripts\redalert.sqf"";";
		};
		class redalertstop : redalertstart {
			userActionID = 2;
			displayName = "Cancel Red Alert";
			condition = "(player in [gunner this, driver this]) && (alive this) && (setting == 1)";
			statement = "setting = false";
		};
	};

And used the script you mentioned in your post (the top one). I do not see the action, as I do not know where I should be defining "setting == 0" to get started.

Abs

Edited by Abs

Share this post


Link to post
Share on other sites

Hi Abs,

Try this to see if it works (ie disables and enables the actions). It's pretty ugly but should hopefully get the result you need - we can refine it later if all is well. Need to know if this is just for SP (easier) or for MP

class UserActions
{
class redalertstart 
{
	userActionID = 1;
	displayName = "Red Alert";
	position = "RedAlert";
	radius = 10;
	showWindow = 0;
	onlyForPlayer = false;
	shortcut = "reloadMagazine";
	condition = "(player in [gunner this, driver this]) && (alive this) && (isNil {this getVariable 'redAlertStarted'})";
	statement = "this setVariable ['redAlertStarted', true, true]";
};
class redalertstop : redalertstart
{
	userActionID = 2;
	displayName = "Cancel Red Alert";
	condition = "(player in [gunner this, driver this]) && (alive this) && (not isNil {this getVariable 'redAlertStarted'}";
	statement = "this setVariable ['redAlertStarted', nil, true]";
};
};

You should be able to cycle through on and off. If it all works ok, you can move the setVariables into your scripts and execVM the script from the statement (as you were doing).

Share this post


Link to post
Share on other sites

Das, this worked well so far! I can cycle through the red alert actions in the user menu. I've tried making it work with the script, but my skills have failed me. I've tried appending the execVM in the statement line. I've tried replacing the statement with the execVM and then placing your variable in the script as is. I've tried adding redAlertStarted = true in the script, but the last one just breaks the on/off actions.

What would be the next step?

Thanks for taking the time to help! :)

Abs

Edit: Forgot that you asked which mode it's for. Ideally, I'd like it to work in MP as well...but locally to the vehicle (pilot, cargo, gunner, etc)...doesn't need to share state with side or other groups.

Edited by Abs

Share this post


Link to post
Share on other sites

I have to go to work in a few minutes but can have a look either tonight when I get in or more likely tomorrow (finish work at 8 tonight and start tomorrow at 9AM so not much free time tonight ) :)

Share this post


Link to post
Share on other sites

No problem. I'm on the road for work until the weekend so there's no rush. Thanks for everything so far. :)

Abs

Share this post


Link to post
Share on other sites

Okay, so I've made some progress thanks to the wonderful folks on Skype, but they disappeared before we got all the way to the finish line and so I'm back asking for more help!

So the current state of affairs is as follows:

- 'Red Alert' user action appears in the menu.

- When selected, it triggers the script.

- 'Cancel Red Alert' also appears, and kills the script when selected.

- 'Cancel Red Alert' action stays after selected. Desired behaviour is for the 'Red Alert' action to reappear so that the script can be run again.

Here is my current UserActions config.cpp:

	class UserActions 
	{ 
		class redalertstart  
		{ 
			userActionID = 1; 
			displayName = "Red Alert"; 
			position = "RedAlert"; 
			radius = 10; 
			showWindow = 0; 
			onlyForPlayer = false; 
			shortcut = "reloadMagazine"; 
			condition = "(player in [gunner this, driver this]) && (alive this) && (isNil {this getVariable 'redAlertStarted'})";
			statement = "this setVariable ['redAlertStarted', true, true]; this execVM ""\STA3_F_Vehicles\Data\scripts\redalert.sqf"";";
		}; 
		class redalertstop : redalertstart 
		{ 
			userActionID = 2; 
			displayName = "Cancel Red Alert"; 
			condition = "(player in [gunner this, driver this]) && (alive this) && (not isNil {this getVariable 'redAlertStarted'})"; 
			statement = "this setVariable ['redAlertStarted', false, true];"; 
		}; 
	};

Here is my current script:

_red = _this;
_started = _red getVariable ["redAlertStarted",true];


// Code
while {_started} do {
_red setObjectMaterial [59,"\STA3_F_Vehicles\Data\STA3_RedLight.rvmat"];
_red setObjectTexture [60,"\STA3_F_Vehicles\Data\screens\EngSOH2_ca.paa"];
playSound3D ["STA3_F_Vehicles\Data\sound\STA3_RedAlert.wav", player];
sleep 0.956;
_red setObjectMaterial [59,"\STA3_F_Vehicles\Data\vs0.rvmat"];
_red setObjectTexture [60,"\STA3_F_Vehicles\Data\screens\EngSOH_ca.paa"];
sleep 0.956;
_started = _red getVariable 'redAlertStarted';
// Can't seem to get this if statement working.
// if (isNil _started) then {_red setVariable ['redAlertStarted', false, true];};
};

Any suggestions??

Thanks in advance! :)

Abs

Share this post


Link to post
Share on other sites

Hey Abs,

Try this:

		class UserActions 
	{ 
		class redalertstart  
		{ 
			userActionID = 1; 
			displayName = "Red Alert"; 
			position = "RedAlert"; 
			radius = 10; 
			showWindow = 0; 
			onlyForPlayer = false; 
			shortcut = "reloadMagazine"; 
			condition = "(player in [gunner this, driver this]) && (alive this) && (isNil {this getVariable 'redAlertStarted'})";
			statement = "this setVariable ['redAlertStarted', true, true]; this execVM ""\STA3_F_Vehicles\Data\scripts\redalert.sqf"";";
		}; 
		class redalertstop : redalertstart 
		{ 
			userActionID = 2; 
			displayName = "Cancel Red Alert"; 
			condition = "(player in [gunner this, driver this]) && (alive this) && (not isNil {this getVariable 'redAlertStarted'})"; 
			statement = "this setVariable ['redAlertStarted', nil, true];"; 
		}; 
	};

and for script:

_red = _this;
_started = _red getVariable "redAlertStarted";


// Code
while {not isNil {_started}} do
{
_red setObjectMaterial [59,"\STA3_F_Vehicles\Data\STA3_RedLight.rvmat"];
_red setObjectTexture [60,"\STA3_F_Vehicles\Data\screens\EngSOH2_ca.paa"];
playSound3D ["STA3_F_Vehicles\Data\sound\STA3_RedAlert.wav", player];
sleep 0.956;
_red setObjectMaterial [59,"\STA3_F_Vehicles\Data\vs0.rvmat"];
_red setObjectTexture [60,"\STA3_F_Vehicles\Data\screens\EngSOH_ca.paa"];
sleep 0.956;
_started = _red getVariable "redAlertStarted";
};

Share this post


Link to post
Share on other sites

That's worked! Thanks a lot for your help, man! :) You've made me so very happy (which makes me want to re-evaluate my life).

I usually offer anyone who helps me reach a goal access to early releases, so let me know if you're interested!

Abs

Share this post


Link to post
Share on other sites

Glad you got it sorted. :)

If it's no trouble I'd like to have a look at the ship (is it the 60's Enterprise you're doing)?

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  

×