Jump to content
CrazyAirborne

Mission Countdown Timer w/ on screen time left?

Recommended Posts

I want to limit my mission to 25 minutes. This is a multiplayer mission. I would also like it to either stay on the screen the whole match, or pop up hints every 5-10 minutes, so for example. a hint would pop up and say 10 minutes left, 5 minutes left, etc.

This is what im using so far, but I dont see it actually doing anything.

INIT.SQF

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


I want everyone playing to have the same hints popping up, so I assume thats what the isServer part is for?

TIMER.SQF


_hour = 0;
_minute = 25;
_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)];
   };
}; 

this is an example I found in an old thread, i dont know if it works exactly like I want it to, but its what Im trying to work with. any help?

Share this post


Link to post
Share on other sites

Well for keeping track of the time accurately I'd recommend this that was given to me by mindstorm on here:



[] spawn {

START_TIME = diag_tickTime;
while {true} do
{
   ELAPSED_TIME = diag_tickTime - START_TIME;
   sleep 1;
}; 

}; 

Put that in your init.sqf and then when you want to use the time to end the mission or give a hint of how long is left you would put in the condition e.g. ELAPSED_TIME = 900 then in the onAct: hint "10 minutes remaining"

That would let you know when there is 10 minutes left of the 25, it seems the normal time variable can be quite inaccurate and drift alot between clients and the server, this way is meant to be more reliable. I wouldn't know how to make it show a constant timer though. One other thing to note with this is the timer starts as soon as you get to the map screen, not after you click continue.

Share this post


Link to post
Share on other sites

ok thanks! I think I understand the code im seeing here, but i wouldnt know where to put the elapsed_time = etc condition(s) exactly.

and having the timer start on the map screen makes a lot of sense. i was wondering about that.

Share this post


Link to post
Share on other sites

put the elapsed time >= 900 in the condition of a trigger then you can put whatever you like as the onAct (ending, hint etc.)

---------- Post added at 13:50 ---------- Previous post was at 13:40 ----------

I actually just PM'd mindstorm about this and I think for MP you need to have it so only the server runs this and publicVariables it, so it should be


[] spawn {

                if (isServer) then {
                                             START_TIME = diag_tickTime;
                                             while {true} do 
                                             {
                                                 ELAPSED_TIME = diag_tickTime - START_TIME;
                                                 publicVariable "ELAPSED_TIME";
                                                 sleep 1;
                                             };
                                   };

        };  

I'll give confirmation when i get it.

Share this post


Link to post
Share on other sites

My pm was a bit wrong.

Init.sqf

END_TIME = 3600; //When mission should end in seconds.

if (isServer) then {
[] spawn 
{
               ELAPSED_TIME  = 0;
	START_TIME = diag_tickTime;
	while {ELAPSED_TIME < END_TIME} do 
	{
		ELAPSED_TIME = diag_tickTime - START_TIME;
		publicVariable "ELAPSED_TIME";
		sleep 1;
	};
};
};


if!(isDedicated) then
{
[] spawn 
{
	while{ELAPSED_TIME < END_TIME } do
	{
		_time = END_TIME - ELAPSED_TIME;
		_finish_time_minutes = floor(_time / 60);
		_finish_time_seconds = floor(_time) - (60 * _finish_time_minutes);
		if(_finish_time_seconds < 10) then
		{
			_finish_time_seconds = format ["0%1", _finish_time_seconds];
		};
		if(_finish_time_minutes < 10) then
		{
			_finish_time_minutes = format ["0%1", _finish_time_minutes];
		};
		_formatted_time = format ["%1:%2", _finish_time_minutes, _finish_time_seconds];

		hintSilent format ["Time left:\n%1", _formatted_time];
		sleep 1;
	};
};
};

Then in the trigger with end set condition to:

ELAPSED_TIME > END_TIME 

Share this post


Link to post
Share on other sites
My pm was a bit wrong.

Init.sqf

END_TIME = 3600; //When mission should end in seconds.

if (isServer) then {
[] spawn 
{
               ELAPSED_TIME  = 0;
	START_TIME = diag_tickTime;
	while {ELAPSED_TIME < END_TIME} do 
	{
		ELAPSED_TIME = diag_tickTime - START_TIME;
		publicVariable "ELAPSED_TIME";
		sleep 1;
	};
};
};


if!(isDedicated) then
{
[] spawn 
{
	while{ELAPSED_TIME < END_TIME } do
	{
		_time = END_TIME - ELAPSED_TIME;
		_finish_time_minutes = floor(_time / 60);
		_finish_time_seconds = floor(_time) - (60 * _finish_time_minutes);
		if(_finish_time_seconds < 10) then
		{
			_finish_time_seconds = format ["0%1", _finish_time_seconds];
		};
		if(_finish_time_minutes < 10) then
		{
			_finish_time_minutes = format ["0%1", _finish_time_minutes];
		};
		_formatted_time = format ["%1:%2", _finish_time_minutes, _finish_time_seconds];

		hintSilent format ["Time left:\n%1", _formatted_time];
		sleep 1;
	};
};
};

Then in the trigger with end set condition to:

ELAPSED_TIME > END_TIME 

Cheers mindstorm, I take it the extra stuff in the first part with the END_TIME is mainly just for the timer hint script to work?

Share this post


Link to post
Share on other sites

wow! Thanks soo much guys, this is working and it even shows the timer on the screen which is exactly what i wanted. now Ill just have to test it on my dedi server and hope the timers snyc across the clients (or close to it :) but im sure itll be fine! thanks again!!!!

*that feel when you've been working on something for hours, and then you finally see the result you want in game , :yay:

  • Like 1

Share this post


Link to post
Share on other sites
wow! Thanks soo much guys, this is working and it even shows the timer on the screen which is exactly what i wanted. now Ill just have to test it on my dedi server and hope the timers snyc across the clients (or close to it :) but im sure itll be fine! thanks again!!!!

*that feel when you've been working on something for hours, and then you finally see the result you want in game , :yay:

CrazyAirborne I just tried out the timer hint on my dedicated server after disconnecting and reconnecting a few times too to join in progress, and i started a timer on my phone when the mission started (map screen) as well to check it against, it works great. Just remember if you have any hints coming up during your mission that people need to read they will barely see them because the of the timer hint updating constantly. So maybe put stuff like that into sidechat or something instead.

Edited by clydefrog

Share this post


Link to post
Share on other sites

if you need to get rid of hint usage - you can update a display - displayCtrl - stick it out of the way - i use if for displaying score and compass direction (fock cache hunt)

as for publicvariable every second - that may be costly if you have a full server. may worth using setvariable to the server, and then recalling the time with getvariable when a player joins and running the script from that? just a thought. nice script otherwise chaps

Share this post


Link to post
Share on other sites

can someone do a quick mod to this with a second loop so a trigger doesn't have to be used?

Share this post


Link to post
Share on other sites
if you need to get rid of hint usage - you can update a display - displayCtrl - stick it out of the way - i use if for displaying score and compass direction (fock cache hunt)

as for publicvariable every second - that may be costly if you have a full server. may worth using setvariable to the server, and then recalling the time with getvariable when a player joins and running the script from that? just a thought. nice script otherwise chaps

can you explain displayCtrl a bit more to me? or how I could use the script here to display with that, so i could free up my hints for other things?

Share this post


Link to post
Share on other sites

its similar to creating a dialog - Suggest you look at ICeman77 dialog tutorial first - then you can commands such as cutRsc to create your own resource -

if you download Fock cache hunt - look in the FOCKHUDS that will give you a good idea what i have done. Unfortunately its a bit too complex to answer in one go. Feel free to ask me any questions about i though

Share this post


Link to post
Share on other sites

What I did with DTAS is run the timer on both client and server, but synchronize it with publicVariable every 10 seconds. Of course the client's timer is display only and doesn't actually do anything, so if they counted the time wrong nothing bad actually happens (other than them not knowing the real time until the next sync comes from the server). There is also a simple display at the top center of the screen used rather than a hint.

Share this post


Link to post
Share on other sites
What I did with DTAS is run the timer on both client and server, but synchronize it with publicVariable every 10 seconds. Of course the client's timer is display only and doesn't actually do anything, so if they counted the time wrong nothing bad actually happens (other than them not knowing the real time until the next sync comes from the server). There is also a simple display at the top center of the screen used rather than a hint.

this sounds perfect. can I get an example or a link to where I can get something like this?

**nvm, i found your DTAS mission on armaholic. :)

Share this post


Link to post
Share on other sites
put the elapsed time >= 900 in the condition of a trigger then you can put whatever you like as the onAct (ending, hint etc.)

---------- Post added at 13:50 ---------- Previous post was at 13:40 ----------

I actually just PM'd mindstorm about this and I think for MP you need to have it so only the server runs this and publicVariables it, so it should be


[] spawn {

                if (isServer) then {
                                             START_TIME = diag_tickTime;
                                             while {true} do 
                                             {
                                                 ELAPSED_TIME = diag_tickTime - START_TIME;
                                                 publicVariable "ELAPSED_TIME";
                                                 sleep 1;
                                             };
                                   };

        };  

I'll give confirmation when i get it.

NOOB Question: why you make publicVariable every time?

publicVariable "ELAPSED_TIME"; should go out of the loop?

like this?

[] spawn {
    if (isServer) then {
         START_TIME = diag_tickTime;
         publicVariable "ELAPSED_TIME";
         while {true} do {
              ELAPSED_TIME = diag_tickTime - START_TIME;
              sleep 1;
          };
    };
};  

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

×