Jump to content
Sign in to follow this  
wyattwic

[Script] Wyatt's time management script

Recommended Posts

Hey guys,

 

Today I am releasing the stable version of my simple time management script.

 

 

This script provides three functions.

  1. Synchronize client date/time every ten minutes to avoid day/night mismatch.
  2. "Short days".   This allows you speed up night or day independently.
  3. "Fast time".  Allows you speed up time.

Here is the download link for the SQF file.

https://dl.dropboxusercontent.com/u/61911880/timekeeper2.sqf

 

Version 1, Does not work but is here for historical.

https://dl.dropboxusercontent.com/u/61911880/timekeeper2.sqf

 

Please, any errors or improvement suggestions would be awesome!

 

-Wyatt

 

 

Here is the code, if you want to look at it without downloading.

//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 generated by the default weather system are not effected.
    
    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.
        
        This script causes the server and clients to calculate the required advance in time every minute.
        Every ten minutes the server pushes its time to the clients to insure everyone sees the same time.
        JIP clients will start at the time last broadcasted and will be updated on the next broadcast.
                
    To operate, the following variables are required.  They are not defined in this script.
    
        starttime - Starting hour.  This should be between 0 and 23.  Suggested intergers are 6,12,18,0.  Sunrize, Midday, Sunset, Midnight.
        fasttime - Time acceleration.  This can be any positive intiger.  Suggested values are 0,4,8,24,48.   Disabled, 6 hour days, 3 hour days, 1 hour days, half hour days.
        shorttime - This option allows you to shorten days or nights in specific.   Allowed values are 0,1,2.  Normal, Half days, Half nights.
        rundebug - This option allows the script to dump error messages in relation to its operation into the rpt file.
*/
private ["_date","_tm"];//Set game time in accordance to parameters.  JIP ready! XD
if (isServer) then {
    PublicServerTime = date;
    PublicServerTime set [3,starttime];
    publicvariable "PublicServerTime";
    setdate PublicServerTime;
    settimemultiplier fasttime;
    if (rundebug) then {diag_log text format["timekeeper.sqf - Server - Initial time sync has been pushed to clients as hour %1.  Fast time is %2 ",PublicServerTime select 3,fasttime];};
    };
    
    
if (!isServer) then {
    waituntil {!isnil "PublicServerTime"};
    setdate PublicServerTime;
    "PublicServerTime" addPublicVariableEventHandler {
    setdate PublicServerTime; if (rundebug) then {diag_log text format["timekeeper.sqf - Client - Time sync completed with server"];};
    };
   if (rundebug) then {diag_log text format["timekeeper.sqf - Client - Initial time sync completed with server - %1", PublicServerTime select 3];};
    };

if (isserver) then {
    _ct = 0;    
    
    if (shorttime == 0) then {
        if (rundebug) then {diag_log text format["timekeeper.sqf - Server - Short time has been disabled. - TM %1 - FT %2",timeMultiplier,fasttime];};
    };

    while {isserver} do {
        _ct = _ct + 1;
        sleep 60;
        
        //Every 10 minutes, the server will trigger the clients to update their time.
        if (_ct >= 10) then {
            PublicServerTime = date;
            publicVariable "PublicServerTime";
            setdate PublicServerTime;
            if (rundebug) then {diag_log text format["timekeeper.sqf - Server - Time sync has been pushed to clients as hour %1.",PublicServerTime select 3];};
        };
        
        //Short days
        if (shorttime == 1) then {
            if (daytime > 6 && daytime < 18) then {
            //The sun is up
            _ft = fasttime + fasttime;
            setTimeMultiplier _ft;
            if (rundebug) then {diag_log text format["timekeeper.sqf - Server - Short day has been activated. - TM %1 - FT %2",timeMultiplier,fasttime];};
            } else {
            //The sun is down
            setTimeMultiplier fasttime;
            if (rundebug) then {diag_log text format["timekeeper.sqf - Server - Short day has been de-activated. - TM %1 - FT %2",timeMultiplier,fasttime];};
            };
        };
        
        //Short Nights
        if (shorttime == 2) then {
            if (daytime > 6 && daytime < 18) then {
            //The sun is up
            setTimeMultiplier fasttime;
            if (rundebug) then {diag_log text format["timekeeper.sqf - Server - Short night has been de-activated. - TM %1 - FT %2",timeMultiplier,fasttime];};
            } else {
            //The sun is down
            _ft = fasttime + fasttime;
            setTimeMultiplier _ft;            
            if (rundebug) then {diag_log text format["timekeeper.sqf - Server - Short night has been activated. - TM %1 - FT %2",timeMultiplier,fasttime];};
            };
        };
        
        if (rundebug) then {diag_log text format["timekeeper.sqf - Server - Server loop completed - TM %1 - FT %2 - CT %3",timeMultiplier,fasttime,_ct];};    
    };
};    


  • Like 2

Share this post


Link to post
Share on other sites

Script looks very helpful, thanks for posting. Two questions  though:

 

 

Synchronize client date/time every ten minutes.   Handy for servers that don't restart often, prevents one player from seeing day while the other sees night.

 

 

I thought the issue with time not beeing sycned between players was fixed during the Alpha stage? Very odd.

 

"Fast time" based on setdate.  This allows you to speed up time without the eyesore of clouds and weather jumping around.   This only moves the sun, moon and stars.

 

What's the reason you're not using setTimeMultiplier? Can't remember any cloud or weather issues.

Share this post


Link to post
Share on other sites

Ill have to do some research on settimemultiplier.  This script was from my archives (dated 1/22/2014).

 

I did some testing on it and it appears that the inital set system time does not work well.  Ill have to re-code it some.

 

In the meantime guys, I would not consider this a working script.

Share this post


Link to post
Share on other sites

Here is the updated version.  Its tested and appears to be working.   I hope it helps someone.

  • Like 1

Share this post


Link to post
Share on other sites

Here is the updated version.  Its tested and appears to be working.   I hope it helps someone.

 

Looks way better now, and I like the short night feature. Thanks!

  • Like 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
Sign in to follow this  

×