Jump to content
Sign in to follow this  
wyattwic

Arma 2 - My time management script

Recommended Posts

Hello everyone!

Just for the hell of it, I wanted to create my own fast time script. At the time of this posting, I have not tested it yet, but I will have it tested in a hour or so.

If anyone sees any issues, please let me know!

//[AWG] Wyatt's time management script
/*	Disambiguation:
	This script is made to manage a few key game play features.
		- Game starting time
		- Fast time (We will use setdate to avoid clouds skipping around)

	Start time:  I want to keep this option simple.   I will give them the options of 
	sunrise, noon, sunset, midnight.

	Fast time: I know there has to be over a dozen different published ways to forward
	through time.  This script uses the more complex setdate wich in contrast to skiptime, advances players through time 
	without the lower clouds jumping around.   Forecast and clouds stay the same.

Important notes and operation methodology:
	This script must be started via the global init file as it must be ran on the
	server as well as the client.
	Clients will check with the server every 10 minutes to make sure that the client
	time is correct and to avoid dsync.
*/
private ["_run","_startdate"];
_run = true;
_startdate = date;

//Set game time in accordance to parameters.
setdate [(_startdate select 0),(_startdate select 1),(_startdate select 2),E_starttime,(_startdate select 4)];
_startdate = "";


//Fast time
private ["_date","_tm","_ct","_min","_hour","_day","_month","_year"];
if (E_fasttime == 0) then {  /*Parameters requested no fast time.   24 hours in real life, 24 hours in game.  This if statement is here for good coding practices and debug log purposes.*/
if (rundebug) then {diag_log text format["timekeeper.sqf - Fasttime parameter returned %1.  Fast time will not run.",E_fasttime];};
} else {
if (rundebug) then {diag_log text format["timekeeper.sqf - Fast time is running with a modifier of 1 to %1.",E_fasttime];};
_tm = E_fasttime;	/*Set time multiplier into local variable.*/
_ct = 0;				/*loop counter.  Used for counting the minutes since last server sync.*/
	while {_run} do {
		sleep 60; 				/*Sleep one minute*/
		_date = date;			/*Get the date/time*/

		_min = _date select 4;	/*Turn the date array into something we can easily manipulate.*/
		_hour = _date select 3;
		_day = _date select 2;
		_month = _date select 1;
		_year = _date select 0;

		_min = _min + _tm;

		//The following are setdate syntax checks.
		if (_min > 59) then {_min = _min - 60; _hour = _hour + 1;/*If minutes added go out of date range, modify hours as needed.*/
			if (_hour > 23) then {_hour = _hour - 24; _day = _day + 1;/*If hours go out of date range, modify days as needed.*/
				if (_day > 31) then {_day = _day - 30;_month = _month + 1;/*If days go out of date range, modify months as needed.*/
					if (_month > 12) then {_month = _month - 12; _year = _year + 1;/*If months go out of range, modify year as needed.*/
		};	};	};	};   /*If statement, inside if statement, etc.   Thought process is, if we don't have to fix minutes, we don't have to fix hours and so on.*/

		setdate [_year,_month,_day,_hour,_min]; /*Use setdate to set the manipulated date.*/

		/*everything from this point on is to prevent clients from dsyncing too much.*/
		_ct=_ct+1; /*This is the master sync control counter.  Adds 1 every cycle.*/
		if (_ct >= 10) then {  
			if (isDedicated && isServer) then {PublicServerTime = date; publicvariable "PublicServerTime"; if (rundebug) then {diag_log text format["timekeeper.sqf - Server - Time sync has been pushed to clients."];};};
			sleep (random 15);
			if (!isDedicated && !isServer) then {setdate PublicServerTime; if (rundebug) then {diag_log text format["timekeeper.sqf - Client - Time sync completed with server"];};};
			_ct = 0;
		};
	};
};

Share this post


Link to post
Share on other sites

Updated and working version.

Works flawlessly on JIP!

DEDICATED SERVER ONLY!

//[AWG] Wyatt's time management script
/*	Disambiguation:
	This script is made to manage a few key game play features.
		- Game starting time
		- Fast time (We will use setdate to avoid clouds skipping around)

	Start time:  I want to keep this option simple.   I will give them the options of 
	sunrise, noon, sunset, midnight.

	Fast time: I know there has to be over a dozen different published ways to forward
	through time.  This script uses the more complex setdate wich in contrast to skiptime, advances players through time 
	without the lower clouds jumping around.   Forecast and clouds stay the same.

Important notes and operation methodology:
	This script must be started via the global init file as it must be ran on the
	server as well as the client.
	Clients will check with the server every 10 minutes to make sure that the client
	time is correct and to avoid dsync.
*/
private ["_date","_tm","_ct","_min","_hour","_day","_month","_year","_time"];//Set game time in accordance to parameters.  JIP ready! XD
if (isDedicated && isServer) then {
PublicServerTime = date; 
PublicServerTime set [3,E_starttime];
publicvariable "PublicServerTime"; 
setdate PublicServerTime;
if (rundebug) then {_time = PublicServerTime select 3; diag_log text format["timekeeper.sqf - Server - Initial time sync has been pushed to clients as hour %1.",_time]; _time = "";};
};


if (!isDedicated && !isServer) then {
waituntil {!isnil "PublicServerTime"};
setdate PublicServerTime;
if (rundebug) then {diag_log text format["timekeeper.sqf - Client - Initial time sync completed with server - %1 - %2", PublicServerTime, E_starttime];};
};

//Fast time
if (E_fasttime == 0) then {  /*Parameters requested no fast time.   24 hours in real life, 24 hours in game.  This if statement is here for good coding practices and debug log purposes.*/
if (rundebug) then {diag_log text format["timekeeper.sqf - Fasttime parameter returned %1.  Fast time will not run.",E_fasttime];};
} else {
if (rundebug) then {diag_log text format["timekeeper.sqf - Fast time is running with a modifier of 1 to %1.",E_fasttime];};
_tm = E_fasttime;	/*Set time multiplier into local variable.*/
_ct = 0;				/*loop counter.  Used for counting the minutes since last server sync.*/
	while {true} do {
		sleep 60; 				/*Sleep one minute*/
		_date = date;			/*Get the date/time*/

		_min = _date select 4;	/*Turn the date array into something we can easily manipulate.*/
		_hour = _date select 3;
		_day = _date select 2;
		_month = _date select 1;
		_year = _date select 0;

		_min = _min + _tm;

		//The following are setdate syntax checks.
		if (_min > 59) then {_min = _min - 60; _hour = _hour + 1;/*If minutes added go out of date range, modify hours as needed.*/
			if (_hour > 23) then {_hour = _hour - 24; _day = _day + 1;/*If hours go out of date range, modify days as needed.*/
				if (_day > 31) then {_day = _day - 30;_month = _month + 1;/*If days go out of date range, modify months as needed.*/
					if (_month > 12) then {_month = _month - 12; _year = _year + 1;/*If months go out of range, modify year as needed.*/
		};	};	};	};   /*If statement, inside if statement, etc.   Thought process is, if we don't have to fix minutes, we don't have to fix hours and so on.*/

		setdate [_year,_month,_day,_hour,_min]; /*Use setdate to set the manipulated date.*/

		/*everything from this point on is to prevent clients from dsyncing too much.*/
		_ct=_ct+1; /*This is the master sync control counter.  Adds 1 every cycle.*/
		if (_ct >= 10) then {  
			if (isDedicated && isServer) then {PublicServerTime = date; publicvariable "PublicServerTime"; if (rundebug) then {diag_log text format["timekeeper.sqf - Server - Time sync has been pushed to clients."];};};
			sleep (random 15);
			if (!isDedicated && !isServer) then {setdate PublicServerTime; if (rundebug) then {diag_log text format["timekeeper.sqf - Client - Time sync completed with server"];};};
			_ct = 0;
		};
	};
};

Relevant description.ext entries.

	class E_starttime {
     	title="Time Of Day";
	values[]={6,12,18,0};
	texts[]={"Sunrise","Noon","Sunset","Midnight"};	
	default = 6;
};
class E_fasttime {
     	title="Fast Time";
	values[]={0,4,8,24,48};
	texts[]={"Disabled","6 Hour days","3 Hour days","1 Hour days","Half hour days"};	
	default = 8;
};

Share this post


Link to post
Share on other sites

Well done !

Well commented also.

I would love to see you develop this further into a tool you could use as an admin.

Like....

1. setting the time

2. fast forwarding at different rates.

3. Rewinding time !

:)

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  

×