Jump to content
Sign in to follow this  
clydefrog

Forcing a script to stop?

Recommended Posts

I know similar threads have been posted but they're all very old and don't look of much use.

Here is my situation:

I have added an action to an ammobox for Opfor to "place a charge" on it, this is the script run by that action:

_object = _this select 0;
_caller = _this select 1;

if ((side _caller) == west) exitWith {hint "You need to capture the box, not destroy it!"};


// This variable sets the action to be hidden as it has now been run

showAction2=false;
publicVariable "showAction2";



// play animation for player

player playmove "AidlPknlMstpSnonWnonDnon01";
sleep 5;



sleep 1;
_timeleft = 30;


	[[hint "Charge placed on Objective. Standby..."],"BIS_fnc_spawn",true,true] spawn BIS_fnc_MP;


sleep 0.5;
while {true} do {
hintsilent format ["Charge Explode in :%1", [((_timeleft)/60)+.01,"HH:MM"] call bis_fnc_timetostring];
if (_timeleft < 1) exitWith{};
 _timeleft = _timeleft -1;


sleep 1;
};
"M_Mo_82mm_AT" createvehicle getpos _object;
{_x setdamage 1} foreach crew _object + [_object];
deleteVehicle _object;


destroyed = true;
publicVariable "destroyed";

But I also want to add a "disarm the charge" action to the box after that script is executed so that if Blufor use the action, it will "disarm" the charge by stopping the above script running, and then re-add the "place a charge" action and script so Opfor again have a chance to place a charge.

So basically I need the "disarm" addaction script to stop the "place a charge" addaction script from running. I think I can hopefully get the rest of the stuff working by myself apart from this, anybody know how to do it?

Share this post


Link to post
Share on other sites
I know similar threads have been posted but they're all very old and don't look of much use.

Here is my situation:

I have added an action to an ammobox for Opfor to "place a charge" on it, this is the script run by that action:

_object = _this select 0;
_caller = _this select 1;

if ((side _caller) == west) exitWith {hint "You need to capture the box, not destroy it!"};


// This variable sets the action to be hidden as it has now been run

showAction2=false;
publicVariable "showAction2";



// play animation for player

player playmove "AidlPknlMstpSnonWnonDnon01";
sleep 5;



sleep 1;
_timeleft = 30;


	[[hint "Charge placed on Objective. Standby..."],"BIS_fnc_spawn",true,true] spawn BIS_fnc_MP;


sleep 0.5;
while {true} do {
hintsilent format ["Charge Explode in :%1", [((_timeleft)/60)+.01,"HH:MM"] call bis_fnc_timetostring];
if (_timeleft < 1) exitWith{};
 _timeleft = _timeleft -1;


sleep 1;
};
"M_Mo_82mm_AT" createvehicle getpos _object;
{_x setdamage 1} foreach crew _object + [_object];
deleteVehicle _object;


destroyed = true;
publicVariable "destroyed";

But I also want to add a "disarm the charge" action to the box after that script is executed so that if Blufor use the action, it will "disarm" the charge by stopping the above script running, and then re-add the "place a charge" action and script so Opfor again have a chance to place a charge.

So basically I need the "disarm" addaction script to stop the "place a charge" addaction script from running. I think I can hopefully get the rest of the stuff working by myself apart from this, anybody know how to do it?

There are several ways you could do it. The easiest would be to create a public variable such as charge_enabled, and make it true when the charge is placed. Your timer loop would then look like:

while {charge_enabled == true} do {
hintsilent format ["Charge Explode in :%1", [((_timeleft)/60)+.01,"HH:MM"] call bis_fnc_timetostring];
if (_timeleft < 1) exitWith{};
 _timeleft = _timeleft -1;
sleep 1;
};

Then your disarm addaction could just set charge_enabled to false.

I'm not in front of my Arma box so can't confirm. Hope this helps

Share this post


Link to post
Share on other sites
There are several ways you could do it. The easiest would be to create a public variable such as charge_enabled, and make it true when the charge is placed. Your timer loop would then look like:

while {charge_enabled == true} do {
hintsilent format ["Charge Explode in :%1", [((_timeleft)/60)+.01,"HH:MM"] call bis_fnc_timetostring];
if (_timeleft < 1) exitWith{};
 _timeleft = _timeleft -1;
sleep 1;
};

Then your disarm addaction could just set charge_enabled to false.

I'm not in front of my Arma box so can't confirm. Hope this helps

Cheers but the problem with this is that it goes straight out of the loop to the part where it creates the munition and explodes. I need it to completely exit the script before it gets to that point if charge_enabled becomes false.

Share this post


Link to post
Share on other sites

You *should* be able to solve this by shuffling your code up a bit, by changing this:

while {true} do {
hintsilent format ["Charge Explode in :%1", [((_timeleft)/60)+.01,"HH:MM"] call bis_fnc_timetostring];
if (_timeleft < 1) exitWith{};
 _timeleft = _timeleft -1;


sleep 1;
};
"M_Mo_82mm_AT" createvehicle getpos _object;
{_x setdamage 1} foreach crew _object + [_object];
deleteVehicle _object;


destroyed = true;
publicVariable "destroyed";

To something along these lines:

_isArmed = true; //Set whatever variable you have here to false in order to disarm
while {_isArmed} do { //_isArmed is added here
hintsilent format ["Charge Explode in :%1", [((_timeleft)/60)+.01,"HH:MM"] call bis_fnc_timetostring];
_timeleft = _timeleft -1; 

if (_timeleft < 1) then {
	"M_Mo_82mm_AT" createvehicle getpos _object;
	{_x setdamage 1} foreach crew _object + [_object];
	deleteVehicle _object;
	destroyed = true;
	publicVariable "destroyed";
	_isArmed = false; //_isArmed is added here
};
sleep 1;
};

With it rewritten this way, it will still detonate the same way at the same condition, but now it allows you to escape without detonation. Haven't tested it myself yet, but in theory should work.

I've noted the three instances where the one variable I've added are. You can either use _isArmed or replace it with whatever variable you want.

This should work, but if it doesn't, tell me and I'll look for what I did wrong.

Good luck!

Share this post


Link to post
Share on other sites

You can force a script to stop by using terminate

somerandomloop = [] spawn {
while {true} do {
	hintsilent format["Time: %1",time];
	sleep 1;
};
};

terminate somerandomloop;

Share this post


Link to post
Share on other sites

Thanks for the suggestions, the way I've done it for now which seems to work is the following:

while {true} do {

		hintsilent format ["Charge Explode in :%1", [((_timeleft)/60)+.01,"HH:MM"] call bis_fnc_timetostring];

	if (disarm) exitWith{};

if (_timeleft < 1) exitWith{};

 _timeleft = _timeleft -1;

sleep 1;

};

if (disarm) exitWith{hint "The charge has been disarmed"};


"M_Mo_82mm_AT" createvehicle getpos _object;
{_x setdamage 1} foreach crew _object + [_object];
deleteVehicle _object;


destroyed = true;
publicVariable "destroyed";

That "disarm" variable is set true and publicvariable'd through the script that's run by using the disarm action.

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  

×