Jump to content
Sign in to follow this  
caseychapman

Day/Night Cycle Server Sync

Recommended Posts

Hello,

I am working on a script for an ArmA 2 Life roleplay mission. The idea of the script is to skip time when specified (every 15 seconds in this case) and it will skip ahead 1 hour 30 minutes. So far I have got the time changing however it is not in sync for all the clients on the server. I will post the script below. If anyone could tell me an easy way to sync the time it would be much appreciated (Please make the explanation as simple as possible I am new to this area of scripting)

The init file that is refered to by the main server init file:

uniqe_daynightenable = true; // Chance true to false to disable the cycle.

if(!uniqe_daynightenable) {
[] execVM "uniqechipmunk\daynight\main.sqf";
};
else {
};

The actual main script:


//1
setDate [2014, 6, 13, 12, 0] call broadcast;
sleep 15;
//2
setDate [2014, 6, 13, 13, 30] call broadcast;
sleep 15;
//3
setDate [2014, 6, 13, 15, 0] call broadcast;
sleep 15;
//4
setDate [2014, 6, 13, 16, 30] call broadcast;
sleep 15;
//5
setDate [2014, 6, 13, 18, 0] call broadcast;
sleep 15;
//5
setDate [2014, 6, 13, 19, 30] call broadcast;
sleep 15;
//6
setDate [2014, 6, 13, 21, 0] call broadcast;
sleep 15;
//7
setDate [2014, 6, 13, 22, 30] call broadcast;
sleep 15;
//8
setDate [2014, 6, 14, 00, 0] call broadcast;
sleep 15;
//9
setDate [2014, 6, 14, 01, 30] call broadcast;
sleep 15;
//10
setDate [2014, 6, 14, 03, 0] call broadcast;
sleep 15;
//11
setDate [2014, 6, 14, 04, 30] call broadcast;
sleep 15;
//12
setDate [2014, 6, 14, 06, 0] call broadcast;
sleep 15;
//13
setDate [2014, 6, 14, 07, 30] call broadcast;
sleep 15;
//14
setDate [2014, 6, 14, 09, 0] call broadcast;
sleep 15;
//15
setDate [2014, 6, 14, 10, 30] call broadcast;
sleep 15;
//16
setDate [2014, 6, 14, 12, 0] call broadcast;
sleep 15;
//17
setDate [2014, 6, 14, 13, 30] call broadcast;
sleep 15;
//18
setDate [2014, 6, 14, 15, 0] call broadcast;
sleep 15;
//19
setDate [2014, 6, 14, 17, 30] call broadcast;
sleep 15;
//20
setDate [2014, 6, 14, 19, 0] call broadcast;
sleep 15;
//21
setDate [2014, 6, 14, 20, 30] call broadcast;
sleep 15;
//22
setDate [2014, 6, 14, 22, 0] call broadcast;
sleep 15;
//23
setDate [2014, 6, 14, 23, 30] call broadcast;
sleep 15;
//24
setDate [2014, 6, 15, 01, 0] call broadcast;
sleep 15;
//25
setDate [2014, 6, 15, 02, 30] call broadcast;
sleep 15;
//26
setDate [2014, 6, 15, 04, 0] call broadcast;
sleep 15;
//27
setDate [2014, 6, 15, 05, 30] call broadcast;
sleep 15;
//28
setDate [2014, 6, 15, 07, 0] call broadcast;
sleep 15;
//29
setDate [2014, 6, 15, 08, 30] call broadcast;
sleep 15;
//30
setDate [2014, 6, 15, 10, 0] call broadcast;
sleep 15;
//31
setDate [2014, 6, 15, 11, 30] call broadcast;
sleep 15;
//32
setDate [2014 6, 15, 11, 30] call broadcast;

Share this post


Link to post
Share on other sites

Well a really simple way would be this:

//Run this on the client
"timeSync" addpublicvariableeventhandler {setDate (_this select 1);};

//Run this everytime you  change the date on the server
timeSync = date;
publicvariable "timeSync";

Just a bit of a warning, skipping time like that is not going to look pretty, and instead of having the server change the time and broadcasting it every time it does that, you could just use one "broadcast" from the server that initiates a script that smoothly changes the time on the client. Then afterwards you could check that the times match and sync them if they don't.

This is a part of a similar system I've used:

_overc = overcast;
5 setovercast 0;
sleep 5;
for "_i" from 1 to 315 do
{
skiptime 0.01111111;
sleep 0.2;
};
20 setovercast _overc;

It changes the time smoothly and hides the clouds before so they don't run wild either.

Share this post


Link to post
Share on other sites

So for the system you use I should just repeat that constantly to get the effect?

Share this post


Link to post
Share on other sites

Edit the amount of loops to do and time to skip so you get the desired amount of time you want to skip and at what pace.

Share this post


Link to post
Share on other sites

If you take Viba's code.

_overc = overcast;
5 setovercast 0;
sleep 5;
for "_i" from 1 to 315 do
{
skiptime 0.01111111;
sleep 0.2;
};
20 setovercast _overc;

When the script is triggered, overcast will transition to 0 (clear) in 5 seconds.

After 5 seconds, a loop that runs 315 times will skip time in-game by 0.01111111 hour, converted to seconds, this is 40 seconds. There is a 0.2 sec delay on this as well.

So every 0.2 sec, in-game time is skipped by 40 seconds, this is being done 315 times.

40 seconds * 315 times = 12600 secs aka 3,5 hour skipped in-game. Which (if I'm not hugely mistaken) takes 2520 seconds/42 mins to fulfill.

The overcast then slowly (takes 20 secs) returns to its' original state.


Anyway, all this seconds/minutes/hours math could easily be avoided by modifying the script.

From what I understand from your original post is that you seem to want a constant day/night cycle, but with an additional option to turn it off or on (at mission start?).

A code similar like this should do the job.

while {true} do 
{
if (uniqe_daynightenable) then {
timeSync = [date select 0, date select 1, date select 2, date select 3, (date select 4)+90];
setDate timeSync;
publicvariable "timeSync";
};
sleep 15;
};

Where sleep 15 indicates the 15 second wait, and +90 is the amount of minutes to skip. Like Viba said, it won't look smooth if you want it this way but even though this is untested scripting work, it should work.

uniqe_daynightenable = true; // true = cycle on, false = cycle off
"timeSync" addpublicvariableeventhandler {setDate (_this select 1);};

if(uniqe_daynightenable && isServer) 
{
[] execVM "uniqechipmunk\daynight\time.sqf";
};

Try this code. If there are any errors, post back.

Kind regards,

Sanchez

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  

×