silentfart

day/night cycle

17 posts in this topic

Ok been trying to get this to work, but no luck.. I did find that part of my issue was I am running a random weather script that had a static time section. so i did away with the custom script for time and included into the weather script. But the acceleration section seems right but never happens.  Here is the whole script. if someone could help me figure out why it doesn't work.  Also, I am running several mods. maybe they have something in conflict. ie: DMS, infistar. What i do to determine other than seeing the day turn to night, is pull up the watch and look at the second hand, it should run fast during acceleration correct?

Correction, this did work, just not on the minute.. i need to learn patients.

update: For anyone who had issue like me, let me see if this will help you.
this line - if (daytime >= 17 || daytime < 5) then  // Adjust these for when you want "night time" works so long as you don't change the "5" value
if like me, you only wanted to accelerate from 17 to 24hrs, that || needs to be && like if (daytime >= 17 && daytime < 24) then  // Adjust these for when you want "night time"

 

Spoiler

/*
Author: code34 nicolas_boiteux@yahoo.fr
Copyright (C) 2013 Nicolas BOITEUX

Real weather for MP GAMES v 1.3

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

private ["_lastrain", "_rain", "_fog", "_mintime", "_maxtime", "_overcast", "_realtime", "_random","_startingdate", "_startingweather", "_timeforecast", "_timeratio", "_timesync", "_wind"];

// Real time vs fast time
// true: Real time is more realistic weather conditions change slowly (ideal for persistent game)
// false: fast time give more different weather conditions (ideal for non persistent game)
_realtime = true;

// Random time before new forecast
// true: forecast happens bewteen mintime and maxtime
// false: forecast happens at mintime
_random = true;

// Min time seconds (real time) before a new weather forecast
_mintime = 900;

// Max time seconds (real time) before a new weather forecast
_maxtime = 2400;

// If Fastime is on
// Ratio 1 real time second for x game time seconds
// Default: 1 real second = 6 second in game
_timeratio = 6;

// send sync data across the network each xxx seconds
// 60 real seconds by default is a good value
// shortest time do not improve weather sync
_timesync = 60;

// Mission starting date
_startingdate = [2039,10,24,15,00];

// Mission starting weather "CLEAR|CLOUDY|RAIN";
_startingweather = ["CLEAR","CLOUDY","RAIN"] call BIS_fnc_selectRandom; // Selects a random weather setting on reset.
//_startingweather = "CLEAR"; //Remove comments on this line if you want a fixed setting each server reset. Be sure to comment out the above line.
 
/////////////////////////////////////////////////////////////////
// Do not edit below
/////////////////////////////////////////////////////////////////

if(_mintime > _maxtime) exitwith {hint format["Real weather: Max time: %1 can no be higher than Min time: %2", _maxtime, _mintime];};
_timeforecast = _mintime;

setdate _startingdate;
switch(toUpper(_startingweather)) do {
    case "CLEAR": {
        wcweather = [0.0,[0,0,0],0, [random 3, random 3, true], date];
    };
    
    case "CLOUDY": {
        wcweather = [0.3,[0.3,0,0],0.5, [random 3, random 3, true], date];
    };
    
    case "RAIN": {
        wcweather = [0.3,[0.5,0.01,15],1, [random 3, random 3, true], date];
    };

    default {
        // clear
        wcweather = [0, 0, 0, [random 3, random 3, true], date];
        diag_log "Real weather: wrong starting weather";
    };
};

// add handler
if (local player) then {
    wcweatherstart = true;
    "wcweather" addPublicVariableEventHandler {
        // first JIP synchronization
        if(wcweatherstart) then {
            wcweatherstart = false;
            skipTime -24;
            86400 setRain (wcweather select 0);
            86400 setfog (wcweather select 1);
            86400 setOvercast (wcweather select 2);
            skipTime 24;
            simulweatherSync;
            setwind (wcweather select 3);
            setdate (wcweather select 4);
        }else{
            wcweather = _this select 1;
            60 setRain (wcweather select 0);
            60 setfog (wcweather select 1);
            60 setOvercast (wcweather select 2);
            setwind (wcweather select 3);
            setdate (wcweather select 4);
        };
    };
};

// SERVER SIDE SCRIPT
if (!isServer) exitWith{};

if(!_realtime) then { setTimeMultiplier _timeratio; };

// apply weather
skipTime -24;
86400 setRain (wcweather select 0);
86400 setfog (wcweather select 1);
86400 setOvercast (wcweather select 2);
skipTime 24;
simulweatherSync;
setwind (wcweather select 3);
setdate (wcweather select 4);

// sync server & client weather & time
[_timesync] spawn {
    private["_timesync"];
    _timesync = _this select 0;

    while { true } do {
        wcweather set [4, date];
        publicvariable "wcweather";
        uiSleep _timesync;
    };
};

_lastrain = 0;
_rain = 0;
_overcast = 0;
_fogValue = 0;
_fogDecay = 0;
_fogHight =0;

while {true} do {
    // ACCELERATE FOR DAY/NIGHT SHIFT.
    if (daytime >= 17 || daytime < 5) then  // Adjust these for when you want "night time"
    {
        setTimeMultiplier 20                  // adjust this value for slower or faster night cycle
    }
    else
    {
        setTimeMultiplier 1                  // adjust this value for slower or faster day cycle  
    };

    _overcast = random 1;
    if(_overcast > 0.5) then {
        _rain = random 0.5;
    } else {
        _rain = 0;
    };
    
    if((date select 3 > 5) and (date select 3 <10)) then {
        _fogValue = 0.2 + (random 0.8);
        _fogDecay = 0.2;
        _fogHight = random 20;
    } else {
        if((_lastrain > 0.6) and (_rain < 0.2)) then {
            _fogValue = random 0.4;
            _fogDecay = 0;
            _fogHight = 0;
        } else {
            _fogValue = 0;
            _fogDecay = 0;
            _fogHight = 0;
        };
    };
    
    if(random 1 > 0.5) then { "wind case 1";
        _wind = [random 7, random 7, true];
    } else {
        _wind = [random 3, random 3, true];
    };
    _lastrain = _rain;

    wcweather = [_rain, [_fogValue,_fogDecay,_fogHight], _overcast, _wind, date];
    60 setRain (wcweather select 0);
    60 setfog (wcweather select 1);
    60 setOvercast (wcweather select 2);
    setwind (wcweather select 3);
    if(_random) then {
        _timeforecast = _mintime + (random (_maxtime - _mintime));
    };
    uiSleep _timeforecast;
};

 

Edited by geekm0nkey

Share this post


Link to post
Share on other sites
Advertisement
On 2/15/2018 at 8:23 AM, Redbeard_Actual said:

I have a solution for this that I tested tonight.

If anyone is still interested.

im intrested

Share this post


Link to post
Share on other sites
if(isServer) then
{
	fnc_MultiplierCheck = "
	if (daytime > 18 || daytime < 6) then 
	{ 
		_timeMultiplier = 10; 
	} 
	else  
	{
		_timeMultiplier = 0;
	};

	if(timeMultiplier != _timeMultiplier) then { setTimeMultiplier _timeMultiplier; };
	";


	fnc_MultiplierChecker = compile fnc_MultiplierCheck;
	[60, fnc_MultiplierChecker, [], true] call ExileServer_system_thread_addTask;
};

I've not tested the above, but it should work if you put it in your init.sqf and doesn't add unnecessary threads to the server. It should run every 60 seconds.

Edited by second_coming
  • Like 2

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.