MajorXAcE

[Update] PTWS - Persistent Time and Weather System

69 posts in this topic

PTWS

Persistent Time and Weather System

PTWS is a script that I made for my Exile server that I host for some friends that allows time and weather to persist through server restarts. It also has seasons defined by months that will change the temperature.

Download

Source

 

Features:

  • Persistent time (year, month, day, hour, minute)
  • Time accleration
  • Persistent weather NEW
  • Dynamic weather (thanks to code34's Real weather) NEW
  • Seasons that change the temperature NEW
  • Snow based on temperature and current overcast NEW

To-do List:

  • Add Persistent weather
  • Configure seasons based on months
  • Make the seasons affect more than the temperature
  • ????

Bugs:

A script error occurs after every restart when PTWS is checking for the database entry, not sure why.

 

Future:

Spoiler

Welp the script is mostly done now, there are few more things that I want to do like make the seasons affect the weather in some way. I'm not sure how I want to do that yet, I'm leaning towards setting configurable min and max values for some of the weather parameters. 

Initial Release

I already have a few ideas on how to make the weather persist through restarts, I'm just not sure how I want to do it yet.

There are a few scripts out there already that manipulate weather and I'm wondering whether or not I should contact the authors to incorporate their work into this script or to make one from scratch. That's the main reason why I chose to release this before adding weather to it.

Once I make or use another script to control the weather, I'm going to define configurable seasons in the config and make the script check the month and choose the weather patterns that are defined for that season.

So this script is only 25% done but I wanted the community's opinion on how I should proceed.

 

Afterword: 

Spoiler

This is my first topic and, for the most part, my first original script. It may not seem like much but this is one of my first shots at Arma scripting so go easy on me :P. Any tips regarding this script or Arma coding in general would be appreciated. 

I had a hard time figuring out which object/namespace to use for the variables in this script, for every other item in the database has some player or object that it derives its ID from, this script doesn't have such an object so I went with missionNamespace. If I chose this in error, please enlighten me. 

Credits:

@second_coming - I used his occupation mod as an example for some of the settings and debug. I also used his config settings for the time acceleration.

@WolfkillArcadia - Thanks for the helpful tips, I was able to clean the code a good amount thanks to that.

@code34 - The creator of Real Weather, I'm using his script for the dynamic weather. 

Edited by MajorXAcE
Update 26AUG16
  • Like 6

Share this post


Link to post
Share on other sites

Interesting script. I was looking over the code and thought I would leave some hopefully helpful advice. 

startPTWS.sqf:

  • Change the DB call from selectFull to selectSingleField. Since you are only grabbing one column from the DB, there is no need to select the entire row. (This may be the cause of your error)
    Spoiler
    
    // OLD 
    _date = format ["getDate:%1", _dateID] call ExileServer_system_database_query_selectFull;
    _saveddate = (_date select 0) select 0;
    
    // NEW
    _saveddate = format ["getDate:%1", _dateID] call ExileServer_system_database_query_selectSingleField;
    
    if (!isNil "_saveddate") then
    {
    	diag_log format["PTWS - Loading last saved date : %1", _saveddate];
    	setDate _saveddate;
    }
    else
    {
    	setDate PTWS_StartingDate;
    	diag_log format["PTWS - No saved date found, loading PTWS_StartingDate:%1",PTWS_StartingDate];
    };

     

     

  • You have a pointless conditional. 
    if (true) then {};

    It will always run, no matter what. You can remove it. 

  • I saw that you tried to use threads, which is a better option. Try this below to see if it will work. 
     

    Spoiler
    
    [
        60, 
        {
            _dateID = missionNamespace getVariable "PTWS";
            _currentdate = date;
            _data = [_currentdate,_dateID];
            _extDB2Message = ["setDate", _data] call ExileServer_util_extDB2_createMessage;
            _extDB2Message call ExileServer_system_database_query_fireAndForget;
            //Borrowed the template from second_coming's occupation mod.
            if (PTWS_timeAcc) then
            {
                if (daytime > PTWS_timeAccNightStart || daytime < PTWS_timeAccDayStart) then 
                { 
                    _timeMultiplier = PTWS_timeAccMultiplierNight; 
                } 
                else  
                {
                    _timeMultiplier = PTWS_timeAccMultiplierDay;
                };
    
                if(timeMultiplier != _timeMultiplier) then { setTimeMultiplier _timeMultiplier; };
            };
        },
        [],
        true
    ] call ExileServer_system_thread_addTask;

     

    This is untested code, but I don't see why it wouldn't work. :) Let me know if you have issues. 

 

Just as an FYI since you said you are a bit new at this:

missionNameSpace setVariable ["BLAH",1];

is the same as

BLAH = 1;

Also, I would avoid using "ExileDatabaseID" as the variable name in the missionNamespace as that this could accidentally overridden by another script. Use "PTWS_DatabaseID" or something so it's unique. 

Good job, not a bad first script. :) 

Edited by WolfkillArcadia
  • Like 1

Share this post


Link to post
Share on other sites
Advertisement

Thanks, I will try your suggestions and see if they work.

Edit:

@WolfkillArcadia So everything worked except the thread, it's spitting out the error it gave me when I tried to use it the first time:

Spoiler

 0:19:34 Error in expression <thread_threadAdjust.sqf"

if (ExileSystemThreadDelays isEqualTo []) th>
 0:19:34   Error position: <ExileSystemThreadDelays isEqualTo []) th>
 0:19:34   Error Undefined variable in expression: exilesystemthreaddelays
 0:19:34 File exile_server\code\ExileServer_system_thread_threadAdjust.sqf, line 12
 0:19:34 Error in expression <hreadID = param [4, false];
_threadId = ExileSystemThreadID;
if(_pushBackThreadI>
 0:19:34   Error position: <ExileSystemThreadID;
if(_pushBackThreadI>
 0:19:34   Error Undefined variable in expression: exilesystemthreadid
 0:19:34 File exile_server\code\ExileServer_system_thread_addTask.sqf, line 18

Any ideas?

Here's the full edited code just in case it helps:

Spoiler

private["_dateID","_date","_saveddate","_currentdate","_data","_extDB2Message","_timeMultiplier"];
if (!isServer) exitWith {};

missionNamespace setVariable ["PTWS",PTWS_ID];

_dateID = missionNamespace getVariable "PTWS";
_saveddate = format ["getDate:%1", _dateID] call ExileServer_system_database_query_selectSingleField;

if (!isNil "_saveddate") then
{
	diag_log format["PTWS - Loading last saved date : %1", _saveddate];
	setDate _saveddate;
}
else
{
	setDate PTWS_StartingDate;
	diag_log format["PTWS - No saved date found, loading PTWS_StartingDate:%1",PTWS_StartingDate];
};


diag_log "PTWS - SaveDate Initialised";
//Thanks WolfkillArcadia!
[
    60, 
    {
        _dateID = missionNamespace getVariable "PTWS";
        _currentdate = date;
        _data = [_currentdate,_dateID];
        _extDB2Message = ["setDate", _data] call ExileServer_util_extDB2_createMessage;
        _extDB2Message call ExileServer_system_database_query_fireAndForget;
        //Borrowed the template from second_coming's occupation mod.
        if (PTWS_timeAcc) then
        {
            if (daytime > PTWS_timeAccNightStart || daytime < PTWS_timeAccDayStart) then 
            { 
                _timeMultiplier = PTWS_timeAccMultiplierNight; 
            } 
            else  
            {
                _timeMultiplier = PTWS_timeAccMultiplierDay;
            };

            if(timeMultiplier != _timeMultiplier) then { setTimeMultiplier _timeMultiplier; };
        };
    },
    [],
    true
] call ExileServer_system_thread_addTask;

/*
if (PTWS_timeAcc) then
{
	diag_log "PTWS - TimeAcc Initialised";
	//[60, PTWS_fnc_timeAcc, [], true] call ExileServer_system_thread_addTask; //Help please?
};
*/

 

 

Edited by MajorXAcE

Share this post


Link to post
Share on other sites
7 minutes ago, WolfkillArcadia said:

.... What? Was that message not in there?

It was, it just came after startPTWS tried to add a task so it made me think that I should have it wait a bit.

Share this post


Link to post
Share on other sites
7 minutes ago, MajorXAcE said:

It was, it just came after startPTWS tried to add a task so it made me think that I should have it wait a bit.

Oh I gotcha. Yeah, try making "exile_server" a required addon for PTWS. :)

Share this post


Link to post
Share on other sites
Advertisement

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.