clydefrog 3 Posted July 8, 2013 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
tpw 2315 Posted July 8, 2013 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
clydefrog 3 Posted July 9, 2013 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
Hypnomatic 10 Posted July 9, 2013 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
xyberviri 1 Posted July 9, 2013 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
clydefrog 3 Posted July 9, 2013 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