SHARE
TWEET

DynamicWeatherEffects.sqf

a guest Nov 30th, 2013 617 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* DynamicWeatherEffects.sqf version 1.01 by Engima of Ostgota Ops
  2.  * Description:
  3.  *   Script that generates dynamic (random) weather. Works in single player, multiplayer (hosted and dedicated), and is JIP compatible.
  4.  * Arguments:
  5.  *   [_initialFog]: Optional. Fog when mission starts. Must be between 0 and 1 where 0 = no fog, 1 = maximum fog. -1 = random fog.
  6.  *   [_initialOvercast]: Optional. Overcast when mission starts. Must be between 0 and 1 where 0 = no overcast, 1 = maximum overcast. -1 = random overcast.
  7.  *   [_initialRain]: Optional. Rain when mission starts. Must be between 0 and 1 where 0 = no rain, 1 = maximum rain. -1 = random rain. (Overcast must be greater than or equal to 0.75).
  8.  *   [_initialWind]: Optional. Wind when mission starts. Must be an array of form [x, z], where x is one wind strength vector and z is the other. x and z must be greater than or equal to 0. [-1, -1] = random wind.
  9.  *   [_debug]: Optional. true if debug text is to be shown, otherwise false.
  10.  */
  11.  
  12. private ["_initialFog", "_initialOvercast", "_initialRain", "_initialWind", "_debug"];
  13. private ["_minWeatherChangeTimeMin", "_maxWeatherChangeTimeMin", "_minTimeBetweenWeatherChangesMin", "_maxTimeBetweenWeatherChangesMin", "_rainIntervalRainProbability", "_windChangeProbability"];
  14. private ["_minimumFog", "_maximumFog", "_minimumOvercast", "_maximumOvercast", "_minimumRain", "_maximumRain", "_minimumWind", "_maximumWind", "_minRainIntervalTimeMin", "_maxRainIntervalTimeMin", "_forceRainToStopAfterOneRainInterval", "_maxWind"];
  15.  
  16. if (isNil "_this") then { _this = []; };
  17. if (count _this > 0) then { _initialFog = _this select 0; } else { _initialFog = -1; };
  18. if (count _this > 1) then { _initialOvercast = _this select 1; } else { _initialOvercast = -1; };
  19. if (count _this > 2) then { _initialRain = _this select 2; } else { _initialRain = -1; };
  20. if (count _this > 3) then { _initialWind = _this select 3; } else { _initialWind = [-1, -1]; };
  21. if (count _this > 4) then { _debug = _this select 4; } else { _debug = false; };
  22.  
  23. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  24. // The following variables can be changed to tweak weather behaviour
  25.  
  26. // Minimum time in minutes for the weather (fog and overcast) to change. Must be greater than or equal to 1 and less than or equal to
  27. // _maxWeatherChangeTimeMin. When weather changes, it is fog OR overcast that changes, not both at the same time. (Suggested value: 10).
  28. _minWeatherChangeTimeMin = 10;
  29.  
  30. // Maximum time in minutes for the weather (fog and overcast) to change. Must be greater than or equal to _minWeatherChangeTimeMin.
  31. // (Suggested value: 20).
  32. _maxWeatherChangeTimeMin = 20;
  33.  
  34. // Minimum time in minutes that weather (fog and overcast) stays constant between weather changes. Must be less than or equal to 0 and
  35. // greater than or equal to _minWeatherChangeTimeMin. (Suggested value: 5).
  36. _minTimeBetweenWeatherChangesMin = 5;
  37.  
  38. // Maximum time in minutes that weather (fog and overcast) stays unchanged between weather changes. Must be greater than or equal to
  39. // _minWeatherChangeTimeMin. (Suggested value: 10).
  40. _maxTimeBetweenWeatherChangesMin = 10;
  41.  
  42. // Fog intensity never falls below this value. Must be between 0 and 1 and less than or equal to _maximumFog
  43. // (0 = no fog, 1 = pea soup). (Suggested value: 0).
  44. _minimumFog = 0.3;
  45.  
  46. // Fog intensity never exceeds this value. Must be between 0 and 1 and greater than or equal to _minimumFog
  47. // (0 = no fog, 1 = pea soup). (Suggested value: 0.8).
  48. _maximumFog = 0.4;
  49.  
  50. // Overcast intensity never falls below this value. Must be between 0 and 1 and less than or equal to _maximumOvercast
  51. // (0 = no overcast, 1 = maximum overcast). (Suggested value: 0).
  52. _minimumOvercast = 0;
  53.  
  54. // Overcast intensity never exceeds this value. Must be between 0 and 1 and greater than or equal to _minimumOvercast
  55. // (0 = no overcast, 1 = maximum overcast). (Suggested value: 1).
  56. _maximumOvercast = 0;
  57.  
  58. // When raining, rain intensity never falls below this value. Must be between 0 and 1 and less than or equal to _maximumRain
  59. // (0 = no rain, 1 = maximum rain intensity). (Suggested value: 0);
  60. _minimumRain = 0;
  61.  
  62. // When raining, rain intensity never exceeds this value. Must be between 0 and 1 and greater than or equal to _minimumRain
  63. // (0 = no rain, 1 = maximum rain intensity). (Suggested value: 0.8);
  64. _maximumRain = 0;
  65.  
  66. // Wind vector strength never falls below this value. Must be greater or equal to 0 and less than or equal to _maximumWind.
  67. // (Suggested value: 0);
  68. _minimumWind = 0;
  69.  
  70. // Wind vector strength never exceeds this value. Must be greater or equal to 0 and greater than or equal to _minimumWind.
  71. // (Suggested value: 8).
  72. _maximumWind = 0;
  73.  
  74. // Probability in percent for wind to change when weather changes. If set to 0 then wind will never change. If set to 100 then rain will
  75. // change every time the weather (fog or overcast) start to change. (Suggested value: 25);
  76. _windChangeProbability = 0;
  77.  
  78. // A "rain interval" is defined as "a time interval during which it may rain in any intensity (or it may not rain at all)". When overcast
  79. // goes above 0.75, a chain of rain intervals (defined below) is started. It cycles on until overcast falls below 0.75. At overcast
  80. // below 0.75 rain intervals never execute (thus it cannot rain).
  81.  
  82. // Probability in percent (0-100) for rain to start at every rain interval. Set this to 0 if you don't want rain at all. Set this to 100
  83. // if you want it to rain constantly when overcast is greater than 0.75. In short: if you think that it generally rains to often then
  84. // lower this value and vice versa. (Suggested value: 50).
  85. _rainIntervalRainProbability = 0;
  86.  
  87. // Minimum time in minutes for rain intervals. Must be greater or equal to 0 and less than or equal to _maxRainIntervalTimeMin.
  88. // (Suggested value: 0).
  89. _minRainIntervalTimeMin = 0;
  90.  
  91. // Maximum time in minutes for rain intervals. Must be greater than or equal to _minRainIntervalTimeMin. (Suggested value:
  92. // (_maxWeatherChangeTimeMin + _maxTimeBetweenWeatherChangesMin) / 2).
  93. _maxRainIntervalTimeMin = (_maxWeatherChangeTimeMin + _maxTimeBetweenWeatherChangesMin) / 2;
  94.  
  95. // If set to true, then the rain is forced to stop after one rain interval during which it has rained (use this for example if you only want
  96. // small occational cloudbursts ). If set to false, then the rain may stop, but it may also just change intensity for an
  97. // immedeate new rain interval. (Suggested value: false).
  98. _forceRainToStopAfterOneRainInterval = false;
  99.  
  100.  
  101. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  102. // Don't touch anything beneath this line
  103.  
  104. drn_DynamicWeather_DebugTextEventArgs = []; // Empty
  105.  
  106. "drn_DynamicWeather_DebugTextEventArgs" addPublicVariableEventHandler {
  107.     drn_DynamicWeather_DebugTextEventArgs call drn_fnc_DynamicWeather_ShowDebugTextLocal;
  108. };
  109.  
  110. /*
  111.  * Summary: Shows debug text on local client.
  112.  * Arguments:
  113.  *   _text: Debug text.
  114.  */
  115. drn_fnc_DynamicWeather_ShowDebugTextLocal = {
  116.     private ["_minutes", "_seconds"];
  117.    
  118.     if (!isNull player) then {
  119.         player sideChat (_this select 0);
  120.     };
  121.    
  122.     _minutes = floor (time / 60);
  123.     _seconds = floor (time - (_minutes * 60));
  124.     diag_log ((str _minutes + ":" + str _seconds) + " Debug: " + (_this select 0));
  125. };
  126.  
  127. /*
  128.  * Summary: Shows debug text on all clients.
  129.  * Arguments:
  130.  *   _text: Debug text.
  131.  */
  132. drn_fnc_DynamicWeather_ShowDebugTextAllClients = {
  133.     drn_DynamicWeather_DebugTextEventArgs = _this;
  134.     publicVariable "drn_DynamicWeather_DebugTextEventArgs";
  135.     drn_DynamicWeather_DebugTextEventArgs call drn_fnc_DynamicWeather_ShowDebugTextLocal;
  136. };
  137.  
  138. if (_debug) then {
  139.     ["Starting script WeatherEffects.sqf..."] call drn_fnc_DynamicWeather_ShowDebugTextLocal;
  140. };
  141.  
  142. drn_DynamicWeatherEventArgs = []; // [current overcast, current fog, current rain, current weather change ("OVERCAST", "FOG" or ""), target weather value, time until weather completion (in seconds), current wind x, current wind z]
  143. drn_AskServerDynamicWeatherEventArgs = []; // []
  144.  
  145. drn_fnc_DynamicWeather_SetWeatherLocal = {
  146.     private ["_currentOvercast", "_currentFog", "_currentRain", "_currentWeatherChange", "_targetWeatherValue", "_timeUntilCompletion", "_currentWindX", "_currentWindZ"];
  147.  
  148.     _currentOvercast = _this select 0;
  149.     _currentFog = _this select 1;
  150.     _currentRain = _this select 2;
  151.     _currentWeatherChange = _this select 3;
  152.     _targetWeatherValue = _this select 4;
  153.     _timeUntilCompletion = _this select 5;
  154.     _currentWindX = _this select 6;
  155.     _currentWindZ = _this select 7;
  156.    
  157.     // Set current weather values
  158.     0 setOvercast _currentOvercast;
  159.     0 setFog _currentFog;
  160.     drn_var_DynamicWeather_Rain = _currentRain;
  161.     setWind [_currentWindX, _currentWindZ, true];
  162.    
  163.     // Set forecast
  164.     if (_currentWeatherChange == "OVERCAST") then {
  165.         _timeUntilCompletion setOvercast _targetWeatherValue;
  166.     };
  167.     if (_currentWeatherChange == "FOG") then {
  168.         _timeUntilCompletion setFog _targetWeatherValue;
  169.     };
  170. };
  171.  
  172. if (!isServer) then {
  173.     "drn_DynamicWeatherEventArgs" addPublicVariableEventHandler {
  174.         drn_DynamicWeatherEventArgs call drn_fnc_DynamicWeather_SetWeatherLocal;
  175.     };
  176.  
  177.     waitUntil {!isNil "drn_var_DynamicWeather_ServerInitialized"};
  178.    
  179.     drn_AskServerDynamicWeatherEventArgs = [true];
  180.     publicVariable "drn_AskServerDynamicWeatherEventArgs";
  181. };
  182.  
  183. if (isServer) then {
  184.     drn_fnc_DynamicWeather_SetWeatherAllClients = {
  185.         private ["_timeUntilCompletion", "_currentWeatherChange"];
  186.        
  187.         _timeUntilCompletion = drn_DynamicWeather_WeatherChangeCompletedTime - drn_DynamicWeather_WeatherChangeStartedTime;
  188.         if (_timeUntilCompletion > 0) then {
  189.             _currentWeatherChange = drn_DynamicWeather_CurrentWeatherChange;
  190.         }
  191.         else {
  192.             _currentWeatherChange = "";
  193.         };
  194.        
  195.         drn_DynamicWeatherEventArgs = [overcast, fog, drn_var_DynamicWeather_Rain, _currentWeatherChange, drn_DynamicWeather_WeatherTargetValue, _timeUntilCompletion, drn_DynamicWeather_WindX, drn_DynamicWeather_WindZ];
  196.         publicVariable "drn_DynamicWeatherEventArgs";
  197.         drn_DynamicWeatherEventArgs call drn_fnc_DynamicWeather_SetWeatherLocal;
  198.     };
  199.    
  200.     "drn_AskServerDynamicWeatherEventArgs" addPublicVariableEventHandler {
  201.         call drn_fnc_DynamicWeather_SetWeatherAllClients;
  202.     };
  203.    
  204.     drn_DynamicWeather_CurrentWeatherChange = "";
  205.     drn_DynamicWeather_WeatherTargetValue = 0;
  206.     drn_DynamicWeather_WeatherChangeStartedTime = time;
  207.     drn_DynamicWeather_WeatherChangeCompletedTime = time;
  208.     drn_DynamicWeather_WindX = _initialWind select 0;
  209.     drn_DynamicWeather_WindZ = _initialWind select 1;
  210.    
  211.     if (_initialFog == -1) then {
  212.         _initialFog = (_minimumFog + random (_maximumFog - _minimumFog));
  213.     }
  214.     else {
  215.         if (_initialFog < _minimumFog) then {
  216.             _initialFog = _minimumFog;
  217.         };
  218.         if (_initialFog > _maximumFog) then {
  219.             _initialFog = _maximumFog;
  220.         };
  221.     };
  222.    
  223.     0 setFog _initialFog;
  224.    
  225.     if (_initialOvercast == -1) then {
  226.         _initialOvercast = (_minimumOvercast + random (_maximumOvercast - _minimumOvercast));
  227.     }
  228.     else {
  229.         if (_initialOvercast < _minimumOvercast) then {
  230.             _initialOvercast = _minimumOvercast;
  231.         };
  232.         if (_initialOvercast > _maximumOvercast) then {
  233.             _initialOvercast = _maximumOvercast;
  234.         };
  235.     };
  236.    
  237.     0 setOvercast _initialOvercast;
  238.    
  239.     if (_initialOvercast >= 0.75) then {
  240.         if (_initialRain == -1) then {
  241.             _initialRain = (_minimumRain + random (_minimumRain - _minimumRain));
  242.         }
  243.         else {
  244.             if (_initialRain < _minimumRain) then {
  245.                 _initialRain = _minimumRain;
  246.             };
  247.             if (_initialRain > _maximumRain) then {
  248.                 _initialRain = _maximumRain;
  249.             };
  250.         };
  251.     }
  252.     else {
  253.         _initialRain = 0;
  254.     };
  255.    
  256.     drn_var_DynamicWeather_Rain = _initialRain;
  257.     0 setRain drn_var_DynamicWeather_Rain;
  258.    
  259.     _maxWind = _minimumWind + random (_maximumWind - _minimumWind);
  260.    
  261.     if (drn_DynamicWeather_WindX == -1) then {
  262.         if (random 100 < 50) then {
  263.             drn_DynamicWeather_WindX = -_minimumWind - random (_maxWind - _minimumWind);
  264.         }
  265.         else {
  266.             drn_DynamicWeather_WindX = _minimumWind + random (_maxWind - _minimumWind);
  267.         };
  268.     };
  269.    
  270.     if (drn_DynamicWeather_WindZ == -1) then {
  271.         if (random 100 < 50) then {
  272.             drn_DynamicWeather_WindZ = -_minimumWind - random (_maxWind - _minimumWind);
  273.         }
  274.         else {
  275.             drn_DynamicWeather_WindZ = _minimumWind + random (_maxWind - _minimumWind);
  276.         };
  277.     };
  278.    
  279.     setWind [drn_DynamicWeather_WindX, drn_DynamicWeather_WindZ, true];
  280.    
  281.     sleep 0.05;
  282.    
  283.     publicVariable "drn_var_DynamicWeather_Rain";
  284.     drn_var_DynamicWeather_ServerInitialized = true;
  285.     publicVariable "drn_var_DynamicWeather_ServerInitialized";
  286.    
  287.     // Start weather thread
  288.     [_minWeatherChangeTimeMin, _maxWeatherChangeTimeMin, _minTimeBetweenWeatherChangesMin, _maxTimeBetweenWeatherChangesMin, _minimumFog, _maximumFog, _minimumOvercast, _maximumOvercast, _minimumWind, _maximumWind, _windChangeProbability, _debug] spawn {
  289.         private ["_minWeatherChangeTimeMin", "_maxWeatherChangeTimeMin", "_minTimeBetweenWeatherChangesMin", "_maxTimeBetweenWeatherChangesMin", "_minimumFog", "_maximumFog", "_minimumOvercast", "_maximumOvercast", "_minimumWind", "_maximumWind", "_windChangeProbability", "_debug"];
  290.         private ["_weatherType", "_fogLevel", "_overcastLevel", "_oldFogLevel", "_oldOvercastLevel", "_weatherChangeTimeSek"];
  291.        
  292.         _minWeatherChangeTimeMin = _this select 0;
  293.         _maxWeatherChangeTimeMin = _this select 1;
  294.         _minTimeBetweenWeatherChangesMin = _this select 2;
  295.         _maxTimeBetweenWeatherChangesMin = _this select 3;
  296.         _minimumFog = _this select 4;
  297.         _maximumFog = _this select 5;
  298.         _minimumOvercast = _this select 6;
  299.         _maximumOvercast = _this select 7;
  300.         _minimumWind = _this select 8;
  301.         _maximumWind = _this select 9;
  302.         _windChangeProbability = _this select 10;
  303.         _debug = _this select 11;
  304.        
  305.         // Set initial fog level
  306.         _fogLevel = 2;
  307.         _overcastLevel = 2;
  308.        
  309.         while {true} do {
  310.             // Sleep a while until next weather change
  311.             sleep floor (_minTimeBetweenWeatherChangesMin * 60 + random ((_maxTimeBetweenWeatherChangesMin - _minTimeBetweenWeatherChangesMin) * 60));
  312.            
  313.             if (_minimumFog == _maximumFog && _minimumOvercast != _maximumOvercast) then {
  314.                 _weatherType = "OVERCAST";
  315.             };
  316.             if (_minimumFog != _maximumFog && _minimumOvercast == _maximumOvercast) then {
  317.                 _weatherType = "FOG";
  318.             };
  319.             if (_minimumFog != _maximumFog && _minimumOvercast != _maximumOvercast) then {
  320.                
  321.                 // Select type of weather to change
  322.                 if ((random 100) < 50) then {
  323.                     _weatherType = "OVERCAST";
  324.                 }
  325.                 else {
  326.                     _weatherType = "FOG";
  327.                 };
  328.             };
  329.            
  330.             // DEBUG
  331.             //_weatherType = "OVERCAST";
  332.            
  333.             if (_weatherType == "FOG") then {
  334.                
  335.                 drn_DynamicWeather_CurrentWeatherChange = "FOG";
  336.                
  337.                 // Select a new fog level
  338.                 _oldFogLevel = _fogLevel;
  339.                 _fogLevel = floor ((random 100) / 25);
  340.                
  341.                 while {_fogLevel == _oldFogLevel} do {
  342.                     _fogLevel = floor ((random 100) / 25);
  343.                 };
  344.                
  345.                 if (_fogLevel == 0) then {
  346.                     drn_DynamicWeather_WeatherTargetValue = _minimumFog + (_maximumFog - _minimumFog) * random 0.05;
  347.                 };
  348.                 if (_fogLevel == 1) then {
  349.                     drn_DynamicWeather_WeatherTargetValue = _minimumFog + (_maximumFog - _minimumFog) * (0.05 + random 0.2);
  350.                 };
  351.                 if (_fogLevel == 2) then {
  352.                     drn_DynamicWeather_WeatherTargetValue = _minimumFog + (_maximumFog - _minimumFog) * (0.25 + random 0.3);
  353.                 };
  354.                 if (_fogLevel == 3) then {
  355.                     drn_DynamicWeather_WeatherTargetValue = _minimumFog + (_maximumFog - _minimumFog) * (0.55 + random 0.45);
  356.                 };
  357.                
  358.                 drn_DynamicWeather_WeatherChangeStartedTime = time;
  359.                 _weatherChangeTimeSek = _minWeatherChangeTimeMin * 60 + random ((_maxWeatherChangeTimeMin - _minWeatherChangeTimeMin) * 60);
  360.                 drn_DynamicWeather_WeatherChangeCompletedTime = time + _weatherChangeTimeSek;
  361.                
  362.                 if (_debug) then {
  363.                     ["Weather forecast: Fog " + str drn_DynamicWeather_WeatherTargetValue + " in " + str round (_weatherChangeTimeSek / 60) + " minutes."] call drn_fnc_DynamicWeather_ShowDebugTextAllClients;
  364.                 };
  365.             };
  366.            
  367.             if (_weatherType == "OVERCAST") then {
  368.                
  369.                 drn_DynamicWeather_CurrentWeatherChange = "OVERCAST";
  370.                
  371.                 // Select a new overcast level
  372.                 _oldOvercastLevel = _overcastLevel;
  373.                 //_overcastLevel = floor ((random 100) / 25);
  374.                 _overcastLevel = 3;
  375.                
  376.                 while {_overcastLevel == _oldOvercastLevel} do {
  377.                     _overcastLevel = floor ((random 100) / 25);
  378.                 };
  379.                
  380.                 if (_overcastLevel == 0) then {
  381.                     drn_DynamicWeather_WeatherTargetValue = _minimumOvercast + (_maximumOvercast - _minimumOvercast) * random 0.05;
  382.                 };
  383.                 if (_overcastLevel == 1) then {
  384.                     drn_DynamicWeather_WeatherTargetValue = _minimumOvercast + (_maximumOvercast - _minimumOvercast) * (0.05 + random 0.3);
  385.                 };
  386.                 if (_overcastLevel == 2) then {
  387.                     drn_DynamicWeather_WeatherTargetValue = _minimumOvercast + (_maximumOvercast - _minimumOvercast) * (0.35 + random 0.35);
  388.                 };
  389.                 if (_overcastLevel == 3) then {
  390.                     drn_DynamicWeather_WeatherTargetValue = _minimumOvercast + (_maximumOvercast - _minimumOvercast) * (0.7 + random 0.3);
  391.                 };
  392.                
  393.                 // DEBUG
  394.                 /*
  395.                 if (overcast > 0.8) then {
  396.                     drn_DynamicWeather_WeatherTargetValue = 0.5;
  397.                 }
  398.                 else {
  399.                     drn_DynamicWeather_WeatherTargetValue = 0.85;
  400.                 };
  401.                 */
  402.                
  403.                 drn_DynamicWeather_WeatherChangeStartedTime = time;
  404.                 _weatherChangeTimeSek = _minWeatherChangeTimeMin * 60 + random ((_maxWeatherChangeTimeMin - _minWeatherChangeTimeMin) * 60);
  405.                 drn_DynamicWeather_WeatherChangeCompletedTime = time + _weatherChangeTimeSek;
  406.                
  407.                 if (_debug) then {
  408.                     ["Weather forecast: Overcast " + str drn_DynamicWeather_WeatherTargetValue + " in " + str round (_weatherChangeTimeSek / 60) + " minutes."] call drn_fnc_DynamicWeather_ShowDebugTextAllClients;
  409.                 };
  410.             };
  411.            
  412.             // On average every one fourth of weather changes, change wind too
  413.             if (random 100 < _windChangeProbability) then {
  414.                 private ["_maxWind"];
  415.                
  416.                 _maxWind = _minimumWind + random (_maximumWind - _minimumWind);
  417.                
  418.                 if (random 100 < 50) then {
  419.                     drn_DynamicWeather_WindX = -_minimumWind - random (_maxWind - _minimumWind);
  420.                 }
  421.                 else {
  422.                     drn_DynamicWeather_WindX = _minimumWind + random (_maxWind - _minimumWind);
  423.                 };
  424.                 if (random 100 < 50) then {
  425.                     drn_DynamicWeather_WindZ = -_minimumWind - random (_maxWind - _minimumWind);
  426.                 }
  427.                 else {
  428.                     drn_DynamicWeather_WindZ = _minimumWind + random (_maxWind - _minimumWind);
  429.                 };
  430.                
  431.                 if (_debug) then {
  432.                     ["Wind changes: [" + str drn_DynamicWeather_WindX + ", " + str drn_DynamicWeather_WindZ + "]."] call drn_fnc_DynamicWeather_ShowDebugTextAllClients;
  433.                 };
  434.             };
  435.            
  436.             call drn_fnc_DynamicWeather_SetWeatherAllClients;
  437.            
  438.             sleep _weatherChangeTimeSek;
  439.         };
  440.     };
  441.    
  442.     // Start rain thread
  443.     if (_rainIntervalRainProbability > 0) then {
  444.         [_minimumRain, _maximumRain, _forceRainToStopAfterOneRainInterval, _minRainIntervalTimeMin, _maxRainIntervalTimeMin, _rainIntervalRainProbability, _debug] spawn {
  445.             private ["_minimumRain", "_maximumRain", "_forceRainToStopAfterOneRainInterval", "_minRainIntervalTimeMin", "_maxRainIntervalTimeMin", "_rainIntervalRainProbability", "_debug"];
  446.             private ["_nextRainEventTime", "_forceStop"];
  447.            
  448.             _minimumRain = _this select 0;
  449.             _maximumRain = _this select 1;
  450.             _forceRainToStopAfterOneRainInterval = _this select 2;
  451.             _minRainIntervalTimeMin = _this select 3;
  452.             _maxRainIntervalTimeMin = _this select 4;
  453.             _rainIntervalRainProbability = _this select 5;
  454.             _debug = _this select 6;
  455.            
  456.             if (rain > 0) then {
  457.                 drn_var_DynamicWeather_Rain = rain;
  458.                 publicVariable "drn_var_DynamicWeather_Rain";
  459.             };
  460.            
  461.             _nextRainEventTime = time;
  462.             _forceStop = false;
  463.            
  464.             while {true} do {
  465.                
  466.                 if (overcast > 0.75) then {
  467.                    
  468.                     if (time >= _nextRainEventTime) then {
  469.                         private ["_rainTimeSec"];
  470.                        
  471.                         // At every rain event time, start or stop rain with 50% probability
  472.                         if (random 100 < _rainIntervalRainProbability && !_forceStop) then {
  473.                             drn_var_DynamicWeather_rain = _minimumRain + random (_maximumRain - _minimumRain);
  474.                             publicVariable "drn_var_DynamicWeather_rain";
  475.                            
  476.                             _forceStop = _forceRainToStopAfterOneRainInterval;
  477.                         }
  478.                         else {
  479.                             drn_var_DynamicWeather_rain = 0;
  480.                             publicVariable "drn_var_DynamicWeather_rain";
  481.                            
  482.                             _forceStop = false;
  483.                         };
  484.                        
  485.                         // Pick a time for next rain change
  486.                         _rainTimeSec = _minRainIntervalTimeMin * 60 + random ((_maxRainIntervalTimeMin - _minRainIntervalTimeMin) * 60);
  487.                         _nextRainEventTime = time + _rainTimeSec;
  488.                        
  489.                         if (_debug) then {
  490.                             ["Rain set to " + str drn_var_DynamicWeather_rain + " for " + str (_rainTimeSec / 60) + " minutes"] call drn_fnc_DynamicWeather_ShowDebugTextAllClients;
  491.                         };
  492.                     };
  493.                 }
  494.                 else {
  495.                     if (drn_var_DynamicWeather_rain != 0) then {
  496.                         drn_var_DynamicWeather_rain = 0;
  497.                         publicVariable "drn_var_DynamicWeather_rain";
  498.                        
  499.                         if (_debug) then {
  500.                             ["Rain stops due to low overcast."] call drn_fnc_DynamicWeather_ShowDebugTextAllClients;
  501.                         };
  502.                     };
  503.                    
  504.                     _nextRainEventTime = time;
  505.                     _forceStop = false;
  506.                 };
  507.                
  508.                 if (_debug) then {
  509.                     sleep 1;
  510.                 }
  511.                 else {
  512.                     sleep 10;
  513.                 };
  514.             };
  515.         };
  516.     };
  517. };
  518.  
  519. [_rainIntervalRainProbability, _debug] spawn {
  520.     private ["_rainIntervalRainProbability", "_debug"];
  521.     private ["_rain", "_rainPerSecond"];
  522.    
  523.     _rainIntervalRainProbability = _this select 0;
  524.     _debug = _this select 1;
  525.    
  526.     if (_debug) then {
  527.         _rainPerSecond = 0.2;
  528.     }
  529.     else {
  530.         _rainPerSecond = 0.03;
  531.     };
  532.    
  533.     if (_rainIntervalRainProbability > 0) then {
  534.         _rain = drn_var_DynamicWeather_Rain;
  535.     }
  536.     else {
  537.         _rain = 0;
  538.     };
  539.    
  540.     0 setRain _rain;
  541.     sleep 0.1;
  542.    
  543.     while {true} do {
  544.         if (_rainIntervalRainProbability > 0) then {
  545.             if (_rain < drn_var_DynamicWeather_Rain) then {
  546.                 _rain = _rain + _rainPerSecond;
  547.                 if (_rain > 1) then { _rain = 1; };
  548.             };
  549.             if (_rain > drn_var_DynamicWeather_Rain) then {
  550.                 _rain = _rain - _rainPerSecond;
  551.                 if (_rain < 0) then { _rain = 0; };
  552.             };
  553.         }
  554.         else {
  555.             _rain = 0;
  556.         };
  557.        
  558.         3 setRain _rain;
  559.        
  560.         sleep 3;
  561.     };
  562. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top