Jump to content
gutiarhero814

Display and record time for MP use

Recommended Posts

I have found a couple things on displaying the time, looking to try and modify this for multiplayer use. Wanting to start the clock, and freeze it to record the time and being displayed globally for all to see.
 
have come across this as a base

_seconds = 0;

_secondsTemp = 0;

_minutes = 0;

_hours = 0;

	

while {true} do

{	

	_timer = [] spawn

	{

		uiSleep 1; //uiSleep uses system time rather than in-game timekeeping (which is tied to framerate) and is therefore more accurate

	};

	_seconds = _seconds + 1;

	_hours = floor (_seconds / 3600);

	_minutes = floor((_seconds - (_hours * 3600)) / 60);

	_secondsTemp = floor (_seconds - (_hours * 3600) - (_minutes * 60));

	if (_hours < 10) then

	{

		_hours = "0" + (str _hours);

	};

	if (_minutes < 10) then

	{

		_minutes = "0" + (str _minutes);

	};

	if (_secondsTemp < 10) then

	{

		_secondsTemp = "0" + (str _secondsTemp);

	};

	

	waitUntil {scriptDone _timer}; //all math should be done before before the script has finished,

	//this prevents the CPU from simply sitting idle and then wasting time number crunching when it should be displaying information

	

	hint format ["%1:%2:%3", _hours, _minutes, _secondsTemp]; //after script is finished then the proper amount of time has passed, display the info

};

Share this post


Link to post
Share on other sites

//init.sqf
if (isServer) then
{
    [] spawn
    {
        //insert the script
    }
};

Change :
hint format ["%1:%2:%3", _hours, _minutes, _secondsTemp];
To:
_txt = format ["%1:%2:%3", _hours, _minutes, _secondsTemp];
_txt remoteExecCall ["hintSilent", -2]; //hint to everyone execpt server. for testing maybe use 0 instead of -2

You will only see a effect in MP and I don't know if uisleep works on the server.

I would also recommend to modify the script and leave out the seconds since it'll be a lot of traffic.

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

×