John

Dynamic Weather script

9 posts in this topic

All credit goes to the original creator of the script, I take no credit for anything, I simply modified it slightly to integrate more detailed fog values -

Regarding syncing issues to clients - From experience on my server, this script is pretty good. Weather has been synced within a couple of minutes max to all clients, I don't claim its perfect, im really not sure however research led me to believe weather syncing was fixed by Bohemia not long ago, don't shoot the messenger.

Server will dynamically change weather every 15 minutes and transition smoothly. During the hours of 5am and 10am game time, there will be a low lying fog that will roll in. Looks really cool..

Not sure if this is required, however I think it is - In your exile server config.cpp, located inside your exile_server_config.pbo  

Line - 1890 

interval = 30; -- Change this to a time that is greater than your server session to ensure exile's code does not interfere with the script. So if your server session is 3 hours, set to to 180. 

Installation -

Create a file called "real_weather.sqf" and place it in your mission folder. Inside the "real_weather.sqf" place this code, If you are experienced you can modify the values below the "DO NOT EDIT BELOW THIS LINE" .

/*
	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 = false;

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

	// 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 is 25/09/2013 at 12:00
	_startingdate = [2015, 04, 25, 6+floor (random 13), 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 {

		_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;
	};

In your initServer.sqf place this at the top -

if (isServer) then {
[] execVM "real_weather.sqf";};

 

Edited by John
2 people like this

Share this post


Link to post
Share on other sites
Advertisement

If it's standard config, it's not line 1890, but 2574 for interval = 60; :)

Thanks for the script, will make the 6h session a lot more dynamic ^_^

Share this post


Link to post
Share on other sites

@John i really like and use the script for quite some time now, but since exile will introduce their own system your script needs to be removed i guess.

as a request, i love the low laying fog. think you could make that some kind of a standalone? im not really good with the weather in arma so i would screw the script up most probably when trying to do that =P anyways, thanks for sharing all your work!

greets

Share this post


Link to post
Share on other sites

This script is still fine for use with the upcoming update. EXILE is introducing a temperature system, not a weather system. AFAIK

Share this post


Link to post
Share on other sites

hi,

some help with value ?

wcweather = [0.0,[0,0,0],0, [random 3, random 3, true], date];

i want to remove sunny/shinny ambiance... more postapo

thx

Share this post


Link to post
Share on other sites

I tossed this on my server, works perfectly, no issues so far.

Share this post


Link to post
Share on other sites

the day stormy and cloudy weather. Sunny weather at night, how we'll set it up

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.