Jump to content
Sign in to follow this  
1para{god-father}

How to work out how much time is left

Recommended Posts

I have a timer that I am using that Ends the mission when it runs out however, If they finish it before the times runs out I need to know how long they took , how would I be able to work that out ?

If they finish before the timer runs out i execute "timerout.sqf" that simply displays stats using Titletext, so i need to pass the remaining time to that , just not sure how ?

////run from SERVER not client as using marker/////
_hour = 2;
_minute = 30;
_second = 0 ;

while {true} do {
if (_second == 0 AND (_minute > 0 OR _hour > 0)) then {
	_second = 59;
	if (_minute > 0) then {
		_minute = _minute - 1;
	} else {
		if (_hour > 0) then {
			_hour = _hour - 1;
			_minute = 59;
		};
	};
} else {
	_second = _second - 1;
};
"Time_left" setMarkerText format["Timeleft = %1 : %2 : %3",_hour, _minute,_second];
sleep 1;
if (_hour == 0 and _minute == 0 and _second == 0) THEN {
	////END mission and show Scores as no time left no need to work out time taken ////
	[]execVM "timerout.sqf";

};
}; 

Share this post


Link to post
Share on other sites

Hi there.

You don't even need a second file if you make use of the while condition.

////run from SERVER not client as using marker/////
_hour = 2;
_minute = 30;
_second = 0;
mission_accomplished = false;

while {((_hour > 0) or (_minute > 0) or (_second > 0)) and !(mission_accomplished)} do {

if (_second == 0 AND (_minute > 0 OR _hour > 0)) then {
	_second = 59;
	if (_minute > 0) then {
		_minute = _minute - 1;
	} else {
		if (_hour > 0) then {
			_hour = _hour - 1;
			_minute = 59;
		};
	};
} else {
	_second = _second - 1;
};
"Time_left" setMarkerText format["Timeleft = %1 : %2 : %3",_hour, _minute,_second];
sleep 1;
};

if (mission_accomplished) then {
titleText [format["Mission accomplished! You had %1 hour(s), %2 minute(s) and %3 second(s) left!",_hour, _minute,_second], "PLAIN"];
} else {
titleText ["Mission failed!", "PLAIN"];
};

You see, just set mission_accomplished or whatever variable you want to use, to true, once all tasks are done.

Or, if you want to show how long the mission was running:

////run from SERVER not client as using marker/////
_hour = 2;
_minute = 30;
_second = 0;
_runtime = 0;
mission_accomplished = false;

while {((_hour > 0) or (_minute > 0) or (_second > 0)) and !(mission_accomplished)} do {

if (_second == 0 AND (_minute > 0 OR _hour > 0)) then {
	_second = 59;
	if (_minute > 0) then {
		_minute = _minute - 1;
	} else {
		if (_hour > 0) then {
			_hour = _hour - 1;
			_minute = 59;
		};
	};
} else {
	_second = _second - 1;
};
"Time_left" setMarkerText format["Timeleft = %1 : %2 : %3",_hour, _minute,_second];
sleep 1;
_runtime = _runtime + 1;
};


if (mission_accomplished) then {
//titleText [format["Mission accomplished! It took you %1 seconds to finish the mission!", _runtime], "PLAIN"];
titleText [format["Mission accomplished! It took you %1 minutes to finish the mission!", floor(_runtime / 60)], "PLAIN"];
} else {
titleText ["Mission failed!", "PLAIN"];
};

Or you might want to combine both :)


if (mission_accomplished) then {
titleText [format["Mission accomplished! It took you %1 minutes to finish the mission!\nYou had %2 hour(s), %3 minute(s) and %4 second(s) left!", floor(_runtime / 60), _hour, _minute,_second,], "PLAIN"];
} else {
titleText ["Mission failed!", "PLAIN"];
};


For multiplayer you would have to broadcast everything at the end instead.

if (mission_accomplished) then {
mission_end_array = ["accomplished", _runtime, _hour, _minute, _second]; publicVariable "mission_end_array"
} else {
mission_end_array = ["failed", _runtime, _hour, _minute, _second]; publicVariable "mission_end_array"
};

To return that on the client side, simply put that into your init.sqf:

[] spawn {

waitUntil {!(isNil "mission_end_array")};

if ((mission_end_array select 0) == "accomplished") then {
	titleText [format["Mission accomplished! It took you %1 minutes to finish the mission!\nYou had %1 hour(s), %3 minute(s) and %4 second(s) left!", floor((mission_end_array select 1) / 60), (mission_end_array select 2), (mission_end_array select 3), (mission_end_array select 4)], "PLAIN"];
} else {
	titleText ["Mission failed!", "PLAIN"];
};

};

Edited by sxp2high
Multiplayer

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  

×