Advertisement
Daniel1357911

ARMA 3 Lightning Script (A mix between CG and CC lightning)

Oct 2nd, 2021 (edited)
2,705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 5.07 KB | None | 0 0
  1. /*
  2.     Author: Daniel13579
  3.  
  4.     Title:
  5.     Rapid Lightning
  6.  
  7.     Description:
  8.     Spawns random lightning around the player/object
  9.  
  10.     Showcase scenario:
  11.     https://steamcommunity.com/sharedfiles/filedetails/?id=2570627497
  12.  
  13.     How to use the script:
  14.     Put the lightning sqf file in the mission folder.
  15.     Put the execution line underneath in the trigger activation field:
  16.    
  17.     startLightning = 1; null = [A, B, C, D] execVM "Lightning.sqf";
  18.  
  19.     A is the maximum distance each lightning can spawn from the given position.
  20.     The distance ranges from 0 meters to the number you supply.
  21.  
  22.     B is the base number of seconds before a new lightning can be spawned.
  23.  
  24.     C is the maximum amount of more seconds randomly added to this delay.
  25.  
  26.     D is the object the lightning will be centered around. The player for example.
  27.  
  28.     startLightning = 1; will start the lightning
  29.     startLightning = 0; will stop the lightning
  30.    
  31.     Example:
  32.     startLightning = 1; null = [12000, 3, 6, player] execVM "Lightning.sqf";    
  33. */
  34.  
  35. private [
  36.     "_lightningDist","_delay","_delayRandom","_lightningPos","_randomLightningDist","_dir","_randomNumber",
  37.     "_zH1","_zH2","_pos","_light","_class","_lightning","_y","_p","_r","_meters","_duration","_time"
  38. ];
  39.  
  40. // organize our arguments
  41. _lightningDist = _this select 0;
  42. _delay = _this select 1;
  43. _delayRandom = _this select 2;
  44. _lightningPos = _this select 3;
  45.  
  46. // create loop for spawning lightning
  47. while { startLightning == 1 } do
  48. {
  49.  
  50.     _randomLightningDist = (random _lightningDist);
  51.     _dir = (random 360);
  52.     _randomNumber = (random 100);
  53.     _zH1 = 250;
  54.     _zH2 = (random 50);
  55.  
  56.     // make a perimeter around the player/object
  57.     if (_randomLightningDist <= 50) then { _randomLightningDist = 50 };
  58.  
  59.     _pos = [_lightningPos, _randomLightningDist, _dir] call BIS_fnc_relPos;
  60.  
  61.     _light = "#lightpoint" createvehiclelocal _pos;
  62.     if (_randomNumber <= 50) then {
  63.         _light setposATL [_pos select 0,_pos select 1,(_pos select 2) + _zH1 + _zH2 + 10];
  64.     } else {
  65.         _light setposATL [_pos select 0,_pos select 1,(_pos select 2) + 10];
  66.     };
  67.     _light setLightDayLight true;
  68.     _light setLightBrightness 300;
  69.     _light setLightAmbient [0.05, 0.05, 0.1];
  70.     _light setlightcolor [1, 1, 2];
  71.  
  72.     sleep 0.1;
  73.     _light setLightBrightness 0;
  74.     sleep (random 0.1);
  75.    
  76.     _class = ["lightning1_F","lightning2_F"] call bis_Fnc_selectrandom;
  77.     _lightning = _class createvehiclelocal [100,100,100];
  78.     if (_randomNumber <= 50) then {
  79.         _y = (random 360);
  80.         _p = (random 360);
  81.         _r = (90 - random 25 + random 25);
  82.         _lightning setVectorDirAndUp [
  83.             [sin _y * cos _p, cos _y * cos _p, sin _p],
  84.             [[sin _r, -sin _p, cos _r * cos _p], -_y] call BIS_fnc_rotateVector2D
  85.         ];
  86.         _lightning setposATL [_pos select 0,_pos select 1,(_pos select 2) + _zH1 + _zH2];
  87.     } else {
  88.         _lightning setdir _dir;
  89.         _lightning setpos _pos;
  90.     };
  91.  
  92.     // distance between player and lightning
  93.     _meters = player distance _lightning;
  94.  
  95.     // thunder sounds
  96.     [_lightning, _meters] spawn {
  97.  
  98.         params ["_lightning", "_meters"];
  99.  
  100.         // very close thunder sounds
  101.         if (_meters <= 600) then {
  102.        
  103.         // select random thunder sound
  104.         _randomThunderSound = selectRandom ["A3\Sounds_F_Exp\environment\elements\thunders\thunder_heavy_3.wss",
  105.         "A3\Sounds_F_Exp\environment\elements\thunders\thunder_heavy_4.wss","A3\Sounds_F_Exp\environment\elements\thunders\thunder_heavy_5.wss"];
  106.        
  107.         // play sound  
  108.         playSound3D [_randomThunderSound, _lightning, false, getPosASL _lightning, 5, 1, 20000];
  109.  
  110.         };
  111.        
  112.         // close thunder sounds
  113.         if (600 < _meters && _meters <= 1200) then {
  114.  
  115.         // select random thunder sound
  116.         _randomThunderSound = selectRandom ["A3\Sounds_F_Exp\environment\elements\thunders\thunder_heavy_1.wss"];
  117.  
  118.  
  119.         // play sound  
  120.         playSound3D [_randomThunderSound, _lightning, false, getPosASL _lightning, 5, 1, 20000];
  121.  
  122.         };
  123.  
  124.         // distant thunder sounds
  125.         if (1200 < _meters && _meters <= 6000) then {
  126.  
  127.         // select random thunder sound
  128.         _randomThunderSound = selectRandom ["A3\Sounds_F_Exp\environment\elements\thunders\thunder_norm_2.wss","A3\sounds_F\ambient\thunder\thunder_01.wss"];
  129.  
  130.         // play sound  
  131.         playSound3D [_randomThunderSound, _lightning, false, getPosASL _lightning, 5, 1, 20000];
  132.  
  133.         };
  134.  
  135.         // very distant thunder sounds
  136.         if (_meters > 6000) then {
  137.  
  138.         // select random thunder sound
  139.         _randomThunderSound = selectRandom ["A3\Sounds_F_Exp\environment\elements\thunders\thunder_norm_1.wss",
  140.         "A3\Sounds_F_Exp\environment\elements\thunders\thunder_norm_2.wss","A3\Sounds_F_Exp\environment\elements\thunders\thunder_norm_3.wss",
  141.         "A3\Sounds_F_Exp\environment\elements\thunders\thunder_norm_4.wss","A3\Sounds_F_Exp\environment\elements\thunders\thunder_norm_5.wss"];
  142.  
  143.         // play sound  
  144.         playSound3D [_randomThunderSound, _lightning, false, getPosASL _lightning, 5, 1, 20000];
  145.  
  146.         };
  147.    
  148.     };
  149.    
  150.     _duration = (3 + random 1);
  151.     for "_i" from 0 to _duration do {
  152.         _time = time + 0.1;
  153.         _light setLightBrightness (100 + random 100);
  154.         waituntil {time > _time};
  155.     };
  156.  
  157.     deletevehicle _lightning;
  158.     deletevehicle _light;
  159.  
  160.     // disable engine lightnings
  161.     0 setlightnings 0;
  162.  
  163.     // delay plus random delay
  164.     sleep (_delay + random _delayRandom);
  165.    
  166. };
  167.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement