Jump to content
Sign in to follow this  
Ombra_ita

[Ombra] Random weather script/function

Recommended Posts

Hi everyone, 

I've created this script to create a random weather and random forecasts each time you start a mission.

It automatically passes all weather data to clients.

The script is able to filter different kinds of weather based on supported terrain position:

- Mediterranean islands;

- Europe;

- Middle east;

Just put the script in the mission directory with the name you prefer and call it from the init.sqf file with the following.

 

init.sqf

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

 

Hope you enjoy.

 

randomWeather.sqf

/* Sets random weather and forecasts based on "real" world positioning. It supports add-ons maps.
 * Ombra 12/06/2020
 * latest update 18/02/2022
*/

CONST_MAX_RAIN_LEVEL = 0.6; //To avoid fps issues
CONST_MAX_FOG_LEVEL = 0.6; //To prevent annoying fog
_currentMap = worldName;
_probabilityFog = random[0,0.5,1];
_probabilityRain = random[0,0.5,1];

//Declaring variables
_currentOvercastCoef = 0;
_forecastOvercastCoef = 0;
_currentRainCoef = 0;
_forecastRainCoef = 0;
_currentFogCoef = 0;
_forecastFogCoef = 0;
_windSpeedN = 0;
_windSpeedE = 0;
_windDirection = 0;

switch (_currentMap) do
{ //Calculating weather for desert terrains
  case "MCN_Aliabad";
  case "takistan";
	case "zargabad";
	case "Mountains_ACR";
	case "fallujah";
	case "kunduz";
	case "Shapur_BAF":
	{
		//Probability of 30% for deserts to encounter overcast (and therefore rain)
		if (_probabilityRain > 0.7) then { _currentOvercastCoef = random[0,0.5,1]; } else { _currentOvercastCoef = random[0,0.2,0.5]; };
		_forecastOvercastCoef = random[0,0.5,1];
		//Current rain only if overcast > 0.6
		if (_currentOvercastCoef > 0.6) then { _currentRainCoef = random[0, CONST_MAX_RAIN_LEVEL/2, CONST_MAX_RAIN_LEVEL]; } else { _currentRainCoef = 0; };
		_forecastRainCoef = random[0, CONST_MAX_RAIN_LEVEL/2, CONST_MAX_RAIN_LEVEL];
		_currentFogCoef = 0;
		_forecastFogCoef = 0;
		//Some wind like sandstorms
		_windSpeedN = random[0,10,30];
		_windSpeedE = random[0,10,30];
		_windDirection = random[0, 180, 360];
	}; //Calculating weather for european terrains (Vanilla and CUP)
	case "Bootcamp_ACR";
	case "Woodland_ACR";
	case "chernarus";
	case "chernarus_summer";
	case "Chernarus_Winter";
	case "ProvingGrounds_PMC";
	case "Enoch":
	{
		//Probability of 60% for northern EU to encounter overcast (and therefore rain)
		if (_probabilityRain > 0.4) then { _currentOvercastCoef = random[0,0.5,1]; } else { _currentOvercastCoef = random[0,0.2,0.5]; };
		_currentOvercastCoef = random[0,0.5,1];
		_forecastOvercastCoef = random[0,0.5,1];
		if (_currentOvercastCoef > 0.6) then { _currentRainCoef = random[0, CONST_MAX_RAIN_LEVEL/2, CONST_MAX_RAIN_LEVEL]; } else { _currentRainCoef = 0; };
		_forecastRainCoef = random[0, CONST_MAX_RAIN_LEVEL/2, CONST_MAX_RAIN_LEVEL];
    //Probability of 30% for northern EU to encounter fog
    if (_probabilityFog > 0.7) then { _currentFogCoef = random[0, CONST_MAX_FOG_LEVEL/2, CONST_MAX_FOG_LEVEL]; } else { _currentFogCoef = 0; };
    _forecastFogCoef = random[0, CONST_MAX_FOG_LEVEL/2, CONST_MAX_FOG_LEVEL];
		//Not much wind in continental land
		_windSpeedN = random[0,10,20];
		_windSpeedE = random[0,10,20];
		_windDirection = random[0, 180, 360];
	}; //Calculating weather for mediterranean terrains
	case "Stratis";
	case "Altis";
	case "Malden":
	{
		//Probability of 50% for northern EU to encounter overcast (and therefore rain)
		if (_probabilityRain > 0.5) then { _currentOvercastCoef = random[0,0.5,1]; } else { _currentOvercastCoef = random[0,0.2,0.5]; };
		_currentOvercastCoef = random[0,0.5,1];
		_forecastOvercastCoef = random[0,0.5,1];
		if (_currentOvercastCoef > 0.6) then { _currentRainCoef = random[0, CONST_MAX_RAIN_LEVEL/2, CONST_MAX_RAIN_LEVEL]; } else { _currentRainCoef = 0; };
		_forecastRainCoef = random[0, CONST_MAX_RAIN_LEVEL/2, CONST_MAX_RAIN_LEVEL];
		_currentFogCoef = random[0, CONST_MAX_FOG_LEVEL/2, CONST_MAX_FOG_LEVEL];
		_forecastFogCoef = random[0, CONST_MAX_FOG_LEVEL/2, CONST_MAX_FOG_LEVEL];
		//Islands are windy
		_windSpeedN = random[0,20,40];
		_windSpeedE = random[0,20,40];
		_windDirection = random[0, 180, 360];
	};
	case "Tanoa":
	{
		//Probability of 80% for jungle areas to encounter overcast (and therefore rain)
		if (_probabilityRain > 0.2) then { _currentOvercastCoef = random[0,0.5,1]; } else { _currentOvercastCoef = random[0,0.2,0.5]; };
		_currentOvercastCoef = random[0,0.5,1];
		_forecastOvercastCoef = random[0,0.5,1];
		if (_currentOvercastCoef > 0.5) then { _currentRainCoef = random[0, CONST_MAX_RAIN_LEVEL/2, CONST_MAX_RAIN_LEVEL]; } else { _currentRainCoef = 0; };
		_forecastRainCoef = random[0, CONST_MAX_RAIN_LEVEL/2, CONST_MAX_RAIN_LEVEL];
    //Probability of 20% for jungle areas to encounter fog
    if (_probabilityFog > 0.8) then { _currentFogCoef = random[0, CONST_MAX_FOG_LEVEL/2, CONST_MAX_FOG_LEVEL]; } else { _currentFogCoef = 0; };
		_forecastFogCoef = random[0, CONST_MAX_FOG_LEVEL/2, CONST_MAX_FOG_LEVEL];
		//Islands are windy
		_windSpeedN = random[0,20,40];
		_windSpeedE = random[0,20,40];
		_windDirection = random[0, 180, 360];
	};
	default
	{
		//Probability of 50% as default
		if (_probabilityRain > 0.5) then { _currentOvercastCoef = random[0,0.5,1]; } else { _currentOvercastCoef = random[0,0.2,0.5]; };
		_currentOvercastCoef = random[0,0.5,1];
		_forecastOvercastCoef = random[0,0.5,1];
		if (_currentOvercastCoef > 0.5) then { _currentRainCoef = random[0, CONST_MAX_RAIN_LEVEL/2, CONST_MAX_RAIN_LEVEL]; } else { _currentRainCoef = 0; };
		_forecastRainCoef = random[0, CONST_MAX_RAIN_LEVEL/2, CONST_MAX_RAIN_LEVEL];
    //Probability of 30% to encounter fog
		if (_probabilityFog > 0.7) then { _currentFogCoef = random[0, CONST_MAX_FOG_LEVEL/2, CONST_MAX_FOG_LEVEL]; } else { _currentFogCoef = 0; };
		_forecastFogCoef = random[0, CONST_MAX_FOG_LEVEL/2, CONST_MAX_FOG_LEVEL];
		_windSpeedN = random[0,10,20];
		_windSpeedE = random[0,10,20];
		_windDirection = random[0, 180, 360];
	};
};

//Setting weather
0 setOvercast _currentOvercastCoef;
0 setRain _currentRainCoef;
0 setFog _currentFogCoef;
setWind [_windSpeedN, _windSpeedE, false];
0 setWindDir _windDirection;
forceWeatherChange;
//Setting forecast
3600 setOvercast _forecastOvercastCoef;
3600 setRain _forecastRainCoef;
3600 setFog _forecastFogCoef;

Up here it is posted as script but it can also be used as function:

[] spawn YourTAG_fnc_randomWeather;

Call the script file fn_randomWeather.sqf and place it in a scenario subfolder names functions.

Then edit the description.ext file by putting standard function declaring:

 

description.ext

class CfgFunctions
{
	class YourTAG
	{
		tag = "YourTAG";
		class functions
		{
			file = "functions";
			class randomWeather {};
		};
	};
};

If you use it in a function way you MUST call it from init.sqf in this way:

 

if (isServer) then { [] spawn OFF_fnc_randomWeather; };

 

  • Like 3

Share this post


Link to post
Share on other sites

You have an undefined variable

_forecastRainCoef

 

in the above code FYI. Also throwing an error when executing from init.sqf

if (isServer) { [] execVM "scripts\RandomWeather.sqf"; };

Says line is missing a ";"

  • Like 1

Share this post


Link to post
Share on other sites

@handlebar Thank you for sharing your comment.

As reported I fixed the code by adding the initialization on _forecastRainCoef.

 

The if clause was missing "then" as edited above.

  • 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  

×