Jump to content
Stevan Corak

End task with a script.

Recommended Posts

Hello everyone I'm still new to arma3 scripting and I'm having problems with a mission countdown.

This is the On Activation callsing  [900] execVM "timer.sqf";

And this is the script

private "_time";
_time = _this select 0;

while {_time > 0} do {
_time = _time - 1;  
hintSilent format["Time Left: \n %1", [((_time)/60)+.01,"HH:MM"] call BIS_fnc_timetostring];    
sleep 1;
};

My question is  how do I end the task if the timer comes down to 0 

Share this post


Link to post
Share on other sites

I guess setTaskState is for doing this.

 

Also sleep 1 does not wait 1 second exactly it waits a minimum of 1 second and  the deviation adds up. Therefore it's better to compare to mission time:

private "_end_time";

_end_time = time + (_this select 0);

while { time < _end_time } do {
hintSilent format["Time Left: \n %1", [((_end_time - time)/60)+.01,"HH:MM"] call BIS_fnc_timetostring];    
sleep 1;
};

YOURTASK setTaskState "Failed";

Not tested...

Share this post


Link to post
Share on other sites

Think about something like this:

 

while { time < _end_time && ((YOURTASK call BIS_fnc_taskState) in ["CREATED","ASSIGNED"]) } do {

  hintSilent format["Time Left: \n %1", [((_end_time - time)/60)+.01,"HH:MM"] call BIS_fnc_timetostring]; sleep 1;

};

if (_time >= _end_time) then {YOURTASK setTaskState "Failed"};

 

  • Like 2

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

×