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

Mission Timer help

Recommended Posts

I need a way to have a timer top right of screen as i am wanting to set a mission MAX time of 2 hours before it finishes, If I run a timer from the server will it sync so all players see the same timer ?

Would this have any impact of performance , and suggestions on best way to do it

I did come across this but not sure of Impact or is there a neater / better way ?


//nul = [7200, "Mission Time left:", ""] execVM "timer.sqf"

private ["_remaining", "_ref", "_timer", "_msg1", "_msg2"];
_timer = _this select 0;
_msg1 = _this select 1;
_msg2 = _this select 2;
_ref = time;
"glt_timerMsg" addPublicVariableEventHandler {[] call glt_showCountdown};
if (isnil "glt_timeFormat") then {
glt_timeFormat = {
	private ["_hours", "_minutes", "_seconds"];
	_hours = 0;
	_minutes = 0;
	_seconds = 0;
	_seconds = _this;
	if (_seconds > 59) then {
		_minutes = floor (_seconds / 60);
		_seconds = _seconds - (_minutes * 60);
	};
	if (_minutes > 59) then {
		_hours = floor (_minutes / 60);
		_minutes = _minutes - (_hours * 60);
	};
	if (_seconds < 10) then {
		_seconds = format ["0%1", _seconds];
	};
	if (_minutes < 10) then {
		_minutes = format ["0%1", _minutes];
	};
	[_hours, _minutes, _seconds]
};
};

if (isnil "glt_showCountdown") then {
glt_showCountdown = {
	hintsilent glt_TimerMsg;
};
};

if (isServer) then {
while {_timer > 0} do {
	_remaining = _timer call glt_timeFormat;
	glt_timerMsg = format ["%1\n\n%2:%3:%4",_msg1, (_remaining select 0), (_remaining select 1), (_remaining select 2)];
	publicVariable "glt_timerMsg";
	if (local player) then {[] call glt_showCountdown};
	_timer = _timer - 1;
	sleep 1;
};
};
glt_timerMsg = _msg2;
publicVariable "glt_timerMsg";
if (local player) then {[] call glt_showCountdown};

////////END mission below when timer is up and show scores//////////////////////

Share this post


Link to post
Share on other sites

Here you go mate works fine for me on MP

INIT.SQF

               if (isServer) then     //RUN IT ON SERVER IT SYNC'S ON ALL CLIENTS 
               {
                     execVM "timer.sqf";
               };


TIMER.SQF


_hour = 2;
_minute = 0;
_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;
};
hintSilent format["Timeleft = %1 : %2 : %3",_hour, _minute,_second];
sleep 1;
if (_hour == 0 and _minute == 0 and _second == 0) exitWith {endmission "END1";
};

_countdown = _totalTime - time + _serverTime;
while {sleep 0.5; _countdown > 0} do {
   //Find how much time is left
   _countdown = _totalTime - time + _serverTime;
   if (_countdown > 0) then {
       hintSilent parseText format ["<t size='2' color='#ffffba0c'>%1</t>", ([floor (_countdown / 60), _countdown mod 60] call _numbersToTimeString)];
   };
}; 

Share this post


Link to post
Share on other sites
Here you go mate works fine for me on MP

INIT.SQF

               if (isServer) then     //RUN IT ON SERVER IT SYNC'S ON ALL CLIENTS 
               {
                     execVM "timer.sqf";
               };


TIMER.SQF


_hour = 2;
_minute = 0;
_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;
};
hintSilent format["Timeleft = %1 : %2 : %3",_hour, _minute,_second];
sleep 1;
if (_hour == 0 and _minute == 0 and _second == 0) exitWith {endmission "END1";
};

_countdown = _totalTime - time + _serverTime;
while {sleep 0.5; _countdown > 0} do {
   //Find how much time is left
   _countdown = _totalTime - time + _serverTime;
   if (_countdown > 0) then {
       hintSilent parseText format ["<t size='2' color='#ffffba0c'>%1</t>", ([floor (_countdown / 60), _countdown mod 60] call _numbersToTimeString)];
   };
}; 

Top Man works a treat !

Share this post


Link to post
Share on other sites

Hi guys Im trying to make this work on a mission but I cant seem to make it work what if done

Make a INIT.SQF and copy init code

make a TIMER.SQF and copy code

Cant make it work tried with caps or not and few other thing but dont work. Not a very good scripter I am.

Thanks for the help

Share this post


Link to post
Share on other sites
Hi guys Im trying to make this work on a mission but I cant seem to make it work what if done

Make a INIT.SQF and copy init code

make a TIMER.SQF and copy code

Cant make it work tried with caps or not and few other thing but dont work. Not a very good scripter I am.

Thanks for the help

Thanks for the script, works great!

Jaimie: just add }; at the very end of the script - its missing for the very first while loop.

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  

×