Jump to content
Sign in to follow this  
MarkCode82

Varied Lightning and Thunder Volume Pitch script for more realistic weather simulation

Recommended Posts

Problem description: The below script is unable to spawn Lightning1_F.p3d  and Lightning2_F.p3d files on an if (isServer) then {} condition yet called from debug console via Local execution or Global Execution it works. Is there anyway I could do this?

The kind of error I see is the following.

 

a3\data_f_curator\misc\lightning1.p3d: No geometry and no visual shape

a3\data_f_curator\misc\lightning2.p3d: No geometry and no visual shape

 

function names:

RS_fnc_ThunderGenerator;

RS_fnc_CreateLightningBolt;

RS_fnc_createLightPoint;

 

Call stack:

[true] spawn RS_fnc_ThunderGenerator ->

[randomised direction, X axis displacement, Y Axis Displacement,Z Axis Displacement] call RS_fnc_createLightningBolt;
LightningBolt is used for reference from which the
[X axis displacement, Y Axis Displacement,Z Axis Displacement] call RS_fnc_createLightpoint

 

At which point the code then executes the playSound3D from the references to the vehicle Objects.

 

 

Thunder generator loop:

private ["_randomDisplacement","_randomX","_randomY","_ChanceOfSpawnRepeat"
,"_totalPlayerList","_randomlySelectedPlayer"];
_ActiveThunder = _this select 0;
while {_ActiveThunder} do {
    if (isServer) then {
        if ((overcast > 0.7) && (rain > 0.6)) then {
           0 setLightnings 0;
           _totalPlayerList = allPlayers;
           _randomPlayer = _totalPlayerList call BIS_fnc_selectRandom;
           diag_log format ["Random player was selected successfully %1",_randomPlayer];
           _center = getPos _randomPlayer;
           diag_log format ["Random player Pos %1",_center];
           _dir = floor(random 360);
           diag_log format ["Random player Obj Dir %1",_center];
           _strikeCenter = _center;
           diag_log format ["Random player Obj StrikeCenter Is %1",_strikeCenter];
           _RandomDisplacementValueX = floor(random 800);
           _RandomDisplacementValueY = floor(random 800);
           diag_log format ["Random Random Displacement X: %1",_RandomDisplacementValueX];
           diag_log format ["Random Random Displacement Y: %1",_RandomDisplacementValueY];
           _LimitValue = round(random 4);
           _RandomTimeFactor = [5,15] call BIS_fnc_randomInt;
           _AudibleDistance = [1500,2000] call BIS_fnc_randomInt;
        /* Thunder_01.wss (Medium Frequency) PitchLimit 3 - 2; VolumeLimit 3 - 12;
           Thunder_02.wss (Medium Frequency) PitchLimit 3; VolumeLimit 3 - 12;
           Thunder_03.wss (Highest Frequency) PitchLimit 0.80 - 1; VolumeLimit 3 - 12;
           Thunder_04.wss (Lowest Frequency) PitchLimit 0.90 - 1; VolumeLimit 3 - 12;
           thunder_05.wss (Lower Frequency) PitchLimit 0.85 - 1; VolumeLimit 3 - 11;
           thunder_06.wss (Higher Frequency) PitchLimit 0.90 - 1; VolumeLimit 3 - 12
            
        */
            _Thunder_01LimitsVolume = [8,12] call BIS_fnc_randomNum;
            _Thunder_02LimitsVolume = [8,12] call BIS_fnc_randomNum;
            _Thunder_03LimitsVolume = [8,12] call BIS_fnc_randomNum;
            _Thunder_04LimitsVolume = [8,15] call BIS_fnc_randomNum;
            _Thunder_05LimitsVolume = [8,13] call BIS_fnc_randomNum;
            _Thunder_06LimitsVolume = [8,12] call BIS_fnc_randomNum;
            _Thunder_01LimitsPitch = [2,3] call BIS_fnc_RandomNum;
            _Thunder_02LimitsPitch = [1,3] call BIS_fnc_randomNum;
            _Thunder_03LimitsPitch = [0.55,0.95] call BIS_fnc_randomNum;
            _Thunder_04LimitsPitch = [0.55,0.95] call BIS_fnc_randomNum;
            _Thunder_05LimitsPitch = [0.55,0.95] call BIS_fnc_randomNum;
            _Thunder_06LimitsPitch = [0.55,0.95] call BIS_fnc_randomNum;
            _SoundDataPool = ["A3\Sounds_f\ambient\thunder\thunder_01.wss",
                      "A3\Sounds_f\ambient\thunder\thunder_02.wss",
                      "A3\Sounds_f\ambient\thunder\thunder_03.wss",
                      "A3\Sounds_f\ambient\thunder\thunder_04.wss",
                      "A3\Sounds_f\ambient\thunder\thunder_05.wss",
                      "A3\Sounds_f\ambient\thunder\thunder_06.wss"];
        _testPos = [(_center select 0),(_center select 1),(_center select 2)];
        diag_log  format ["%1",_testPos];
        _ChanceOfSpawnRepeat = random 1;
        _RepeatCount = round(random 3);
                _randomX = (_center select 0) + (_RandomDisplacementValueX - (2*_RandomDisplacementValueX));
                _randomY = (_center select 1) + (_RandomDisplacementValueY - (2*_RandomDisplacementValueY));
                diag_log format ["randomised X position : %1 randomised Y position : %2",_randomX,_randomY];
                GRandomXY = [_randomX,_randomY];
                publicVariable "GRandomXY";
                    if (_ChanceOfSpawnRepeat > 0.8) then {
                        for [{_i=0},{_i <= _RepeatCount},{_i = _i + 1}] do {
                        [_dir,_randomX,_randomY,_testPos select 2] call RS_fnc_createLightningBolt;
                        [_dir,_randomX,_randomY,_testPos select 2] call RS_fnc_createLightPoint;
                        diag_log format ["RandomX: %1, \n RandomY %2, \n BaseZ %3",_randomX,_randomY,_ChanceOfSpawnRepeat];
                            DistA = getPosATL _randomlySelectedPlayer distance [_randomX,_randomY,0];
                                if (round(DistA) <= 100) then {
                                    _HighestFreqCreateThun03 = _SoundDataPool select 2;
                                    playSound3D [_HighestFreqCreateThun03,PV_LightningObject,false,getpos PV_LightningObject,_Thunder_03LimitsVolume,_Thunder_03LimitsPitch,_AudibleDistance];
                                    };
                                    
                                if (round(DistA) <= 200) then {
                                    _HigherFreqCreateThun06 = _SoundDataPool select 5;
                                    playSound3D [_HigherFreqCreateThun06,PV_LightningObject,false,getpos PV_LightningObject,_Thunder_06LimitsVolume,_Thunder_06LimitsPitch,_AudibleDistance];
                                    };
                                    
                                if (round(DistA) <= 400) then {
                                    _MediumFreqCreateThun02 = _SoundDataPool select 1;
                                    playSound3D [_MediumFreqCreateThun02,PV_LightningObject,false,getpos PV_LightningObject,_Thunder_02LimitsVolume,_Thunder_02LimitsPitch,_AudibleDistance];
                                    };
                                
                                if (round(DistA) <= 500) then {
                                    _MediumFreqCreateThun01 = _SoundDataPool select 0;
                                    playSound3D [_MediumFreqCreateThun01,PV_LightningObject,false,getpos PV_LightningObject,_Thunder_01LimitsVolume,_Thunder_01LimitsPitch,_AudibleDistance];
                                    };
                                    
                                if (round(DistA) <= 530) then {
                                    _LowerFreqCreateThun05 = _SoundDataPool select 4;
                                    playSound3D [_LowerFreqCreateThun05,PV_LightningObject,false,getpos PV_LightningObject,_Thunder_05LimitsVolume,_Thunder_05LimitsPitch,_AudibleDistance];
                                    };
                                    
                                if (round(DistA) <=700) then {
                                    _LowerFreqCreateThun04 = _SoundDataPool select 3;
                                    playSound3D [_LowerFreqCreateThun04,PV_LightningObject,false,getpos PV_LightningObject,_Thunder_05LimitsVolume,_Thunder_05LimitsPitch,_AudibleDistance];
                                    };
                        };
                    } else {
                        [_dir,_randomX,_randomY,(_testPos select 2)] call RS_fnc_createLightningBolt;
                        [_dir,_randomX,_randomY,(_testPos select 2)] call RS_fnc_createLightPoint;
                        PV_LightningPos = [_randomX,_randomY,_testPos];
                        publicVariable "PV_LightningPos";
                        hint format ["%1",PV_LightningPos];                                                    
                        sleep _RandomTimeFactor;
                        DistB = getPosATL player distance [_randomX,_randomY,0];
                                if (round(DistB) <= 100) then {
                                    _HighestFreqCreateThun03 = _SoundDataPool select 2;
                                    playSound3D [_HighestFreqCreateThun03,PV_LightningObject,false,getpos PV_LightningObject,_Thunder_03LimitsVolume,_Thunder_03LimitsPitch,_AudibleDistance];
                                    };
                                    
                                if (round(DistB) <= 200) then {
                                    _HigherFreqCreateThun06 = _SoundDataPool select 5;
                                    playSound3D [_HigherFreqCreateThun06,PV_LightningObject,false,getpos PV_LightningObject,_Thunder_06LimitsVolume,_Thunder_06LimitsPitch,_AudibleDistance];
                                    };
                                    
                                if (round(DistB) <= 400) then {
                                    _MediumFreqCreateThun02 = _SoundDataPool select 1;
                                    playSound3D [_MediumFreqCreateThun02,PV_LightningObject,false,getpos PV_LightningObject,_Thunder_02LimitsVolume,_Thunder_02LimitsPitch,_AudibleDistance];
                                    };
                                
                                if (round(DistB) <= 500) then {
                                    _MediumFreqCreateThun01 = _SoundDataPool select 0;
                                    playSound3D [_MediumFreqCreateThun01,PV_LightningObject,false,getpos PV_LightningObject,_Thunder_01LimitsVolume,_Thunder_01LimitsPitch,_AudibleDistance];
                                    };
                                    
                                if (round(DistB) <= 530) then {
                                    _LowerFreqCreateThun05 = _SoundDataPool select 4;
                                    playSound3D [_LowerFreqCreateThun05,PV_LightningObject,false,getpos PV_LightningObject,_Thunder_05LimitsVolume,_Thunder_05LimitsPitch,_AudibleDistance];
                                    };
                                    
                                if (round(DistB) <= 700) then {
                                    _LoweestFreqCreateThun04 = _SoundDataPool select 3;
                                    playSound3D [_LoweestFreqCreateThun04,PV_LightningObject,false,getpos PV_LightningObject,_Thunder_04LimitsVolume,_Thunder_04LimitsPitch,_AudibleDistance];
                                    };
                        PV_LightningPos = [_randomX,_randomY,_testPos];
                        publicVariable "PV_LightningPos";
                        hint format ["%1",PV_LightningPos];                                                    
                        sleep _RandomTimeFactor;
                    };
                };
            };
        };

Create Lightning Bolt:

private ["_class","_LightningObj","_duration","_time"];
_class = ["Lightning1_F","Lightning2_F"] call bis_Fnc_selectrandom;
_LightningObj = _class createVehicle [100,100,100];
_LightningObj setDir (_this select 0);                                
_LightningObj setPosAtl [_this select 1,_this select 2,_this select 3];
_duration = random 3;                                                                                    
    for "_i" from 0 to _duration do {
    _time = time + 0.1;
    _LightningObj setLightBrightness (900 + random 100);
    waitUntil {time > _time};
    };
        PV_LightningObject = _LightningObj;

Create Lightpoint:

private ["_LightObj"];
    diag_log format ["Passed location data: X: %1\n Y:%2 \n Z: %3",_this select 0,_this select 1,_this select 2,_this select 3];
    _LightObj = "#lightpoint" createvehicleLocal [_this select 0,_this select 1,_this select 2];
        _LightObj setposatl [_this select 0,_this select 1,_this select 2];
        _LightObj setLightDayLight true;
        _LightObj setLightBrightness 300;
        _LightObj setLightAmbient [0.2, 0.2, 0.1];
        _LightObj setlightcolor [1, 1, 3];
        sleep 0.15;
        _LightObj setLightBrightness 0;
        sleep (random 0.15);
        PV_LightPointObject = _LightObj;
        publicVariable "PV_LightPointObject";
        deleteVehicle _LightObj;

Code Above Adapated from Shpook's Ambient Lightning Script.

All code above is also subject to: https://www.bistudio.com/community/licenses/arma-public-license

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  

×