Daniel1357911

ARMA 3 Lightning Script (new)

Aug 20th, 2021 (edited)
1,347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQF 4.45 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. // organize our arguments
  36. _lightningDist = _this select 0;
  37. _delay = _this select 1;
  38. _delayRandom = _this select 2;
  39. _lightningPos = _this select 3;
  40.  
  41. // create loop for spawning lightning
  42. while { startLightning == 1 } do
  43. {
  44.  
  45.     _randomLightningDist = (random _lightningDist);
  46.     _dir = (random 360);
  47.  
  48.     // make a perimeter around the player/object
  49.     if (_randomLightningDist <= 50) then { _randomLightningDist = 50 };
  50.  
  51.     private _pos = [_lightningPos, _randomLightningDist, _dir] call BIS_fnc_relPos;
  52.  
  53.     _light = "#lightpoint" createvehiclelocal _pos;
  54.     _light setposatl [_pos select 0,_pos select 1,(_pos select 2) + 10];
  55.     _light setLightDayLight true;
  56.     _light setLightBrightness 300;
  57.     _light setLightAmbient [0.05, 0.05, 0.1];
  58.     _light setlightcolor [1, 1, 2];
  59.  
  60.     sleep 0.1;
  61.     _light setLightBrightness 0;
  62.     sleep (random 0.1);
  63.    
  64.     private _class = ["lightning1_F","lightning2_F"] call bis_Fnc_selectrandom;
  65.     private _lightning = _class createvehiclelocal [100,100,100];
  66.     _lightning setdir _dir;
  67.     _lightning setpos _pos;
  68.  
  69.     // distance between player and lightning
  70.     private _meters = player distance _lightning;
  71.  
  72.     // thunder sounds
  73.     [_lightning, _meters] spawn {
  74.  
  75.         params ["_lightning", "_meters"];
  76.  
  77.         // very close thunder sounds
  78.         if (_meters <= 600) then {
  79.        
  80.         // select random thunder sound
  81.         _randomThunderSound = selectRandom ["A3\Sounds_F_Exp\environment\elements\thunders\thunder_heavy_3.wss",
  82.         "A3\Sounds_F_Exp\environment\elements\thunders\thunder_heavy_4.wss","A3\Sounds_F_Exp\environment\elements\thunders\thunder_heavy_5.wss"];
  83.        
  84.         // play sound  
  85.         playSound3D [_randomThunderSound, _lightning, false, getPosASL _lightning, 5, 1, 20000];
  86.  
  87.         };
  88.        
  89.         // close thunder sounds
  90.         if (600 < _meters && _meters <= 1200) then {
  91.  
  92.         // select random thunder sound
  93.         _randomThunderSound = selectRandom ["A3\Sounds_F_Exp\environment\elements\thunders\thunder_heavy_1.wss",
  94.         "A3\Sounds_F_Exp\environment\elements\thunders\thunder_heavy_4.wss","A3\Sounds_F_Exp\environment\elements\thunders\thunder_heavy_5.wss"];
  95.  
  96.  
  97.         // play sound  
  98.         playSound3D [_randomThunderSound, _lightning, false, getPosASL _lightning, 5, 1, 20000];
  99.  
  100.         };
  101.  
  102.         // distant thunder sounds
  103.         if (1200 < _meters && _meters <= 6000) then {
  104.  
  105.         // select random thunder sound
  106.         _randomThunderSound = selectRandom ["A3\Sounds_F_Exp\environment\elements\thunders\thunder_norm_2.wss","A3\sounds_F\ambient\thunder\thunder_01.wss"];
  107.  
  108.         // play sound  
  109.         playSound3D [_randomThunderSound, _lightning, false, getPosASL _lightning, 5, 1, 20000];
  110.  
  111.         };
  112.  
  113.         // very distant thunder sounds
  114.         if (_meters > 6000) then {
  115.  
  116.         // select random thunder sound
  117.         _randomThunderSound = selectRandom ["A3\Sounds_F_Exp\environment\elements\thunders\thunder_norm_1.wss",
  118.         "A3\Sounds_F_Exp\environment\elements\thunders\thunder_norm_2.wss","A3\Sounds_F_Exp\environment\elements\thunders\thunder_norm_3.wss",
  119.         "A3\Sounds_F_Exp\environment\elements\thunders\thunder_norm_4.wss","A3\Sounds_F_Exp\environment\elements\thunders\thunder_norm_5.wss"];
  120.  
  121.         // play sound  
  122.         playSound3D [_randomThunderSound, _lightning, false, getPosASL _lightning, 5, 1, 20000];
  123.  
  124.         };
  125.    
  126.     };
  127.    
  128.     _duration = (3 + random 1);
  129.     for "_i" from 0 to _duration do {
  130.         _time = time + 0.1;
  131.         _light setLightBrightness (100 + random 100);
  132.         waituntil {time > _time};
  133.     };
  134.  
  135.     deletevehicle _lightning;
  136.     deletevehicle _light;
  137.  
  138.     // disable engine lightnings
  139.     0 setlightnings 0;
  140.  
  141.     // delay plus random delay
  142.     sleep (_delay + random _delayRandom);
  143.    
  144. };
  145.  
Add Comment
Please, Sign In to add comment