diff --git a/addons/wolf_modules/ambient_battle/IRN_calcSoundPos.sqf b/addons/wolf_modules/ambient_battle/IRN_calcSoundPos.sqf new file mode 100644 index 0000000..ca36878 --- /dev/null +++ b/addons/wolf_modules/ambient_battle/IRN_calcSoundPos.sqf @@ -0,0 +1,13 @@ + params ["_center","_dist","_headPos"]; + _posP = getPosASL player; //getpos player + _posC = getPosASL _center; //getpos of center + _direction = _posC vectorDiff _posP; //get desired positon of selfiestick headgear + //TODO add safeguard for players that manage to get very far away + if (vectorMagnitude _direction < _dist) then { //if center is closer than _dist, set pos directly at center + _headPos = _posC; + } else { //else set in direction of center at _dist meters away + _dirNorm = vectorNormalized _direction; + _direction = _dirNorm vectorMultiply _dist; + _headPos = _posP vectorAdd _direction; + }; + _headPos \ No newline at end of file diff --git a/addons/wolf_modules/ambient_battle/IRN_remoteSound.sqf b/addons/wolf_modules/ambient_battle/IRN_remoteSound.sqf new file mode 100644 index 0000000..e61d8a7 --- /dev/null +++ b/addons/wolf_modules/ambient_battle/IRN_remoteSound.sqf @@ -0,0 +1,9 @@ +params["_sound","_pos","_shots","_delay","_volume","_center","_dist", "_maxDistance"]; +//get distance to center +_d =_center distance player; +if (_d > _maxDistance) exitWith { +}; +//get pos +_pos = [_center,_dist] call IRN_fnc_calcSoundPos; +//play salvo +[_sound,_pos,_shots,_delay,_volume] spawn IRN_fnc_spawnSalvo; \ No newline at end of file diff --git a/addons/wolf_modules/ambient_battle/IRN_spawnSalvo.sqf b/addons/wolf_modules/ambient_battle/IRN_spawnSalvo.sqf new file mode 100644 index 0000000..117358e --- /dev/null +++ b/addons/wolf_modules/ambient_battle/IRN_spawnSalvo.sqf @@ -0,0 +1,6 @@ + params["_sound","_pos","_shots","_delay","_volume"]; + sleep _delay; + for "_i" from 0 to _shots do { + playSound3D [_sound, nil, false, _pos, _volume, 0, 0]; // play sound + sleep random [0.02,0.2,0.5]; + }; \ No newline at end of file diff --git a/addons/wolf_modules/ambient_battles.sqf b/addons/wolf_modules/ambient_battle/ambient_battles.sqf similarity index 64% rename from addons/wolf_modules/ambient_battles.sqf rename to addons/wolf_modules/ambient_battle/ambient_battles.sqf index eb932a1..3cf7c96 100644 --- a/addons/wolf_modules/ambient_battles.sqf +++ b/addons/wolf_modules/ambient_battle/ambient_battles.sqf @@ -17,44 +17,14 @@ _dist = parseNumber _dist; _duration = _module getVariable "duration"; _duration = parseNumber _duration; _center = _module; - +_maxDistance = _module getVariable "maxdistance"; +_maxDistance = parseNumber _maxDistance; if (!isServer) exitWith {}; if (_action !="init") exitWith {}; //only executes ingame, not in Eden -_handle = [false, _duration, _dist, _center] spawn { //[debug mode, duration in seconds] - params["_debug","_duration","_dist","_center"]; - IRN_calcSoundPos = { - params ["_center","_dist","_headPos"]; - _posP = getPosASL player; //getpos player - _posC = getPosASL _center; //getpos of center - _direction = _posC vectorDiff _posP; //get desired positon of selfiestick headgear - //TODO add safeguard for players that manage to get very far away - if (vectorMagnitude _direction < _dist) then { //if center is closer than _dist, set pos directly at center - _headPos = _posC; - } else { //else set in direction of center at _dist meters away - _dirNorm = vectorNormalized _direction; - _direction = _dirNorm vectorMultiply _dist; - _headPos = _posP vectorAdd _direction; - }; - _headPos - }; - - IRN_spawnSalvo = { - params["_sound","_pos","_shots","_delay","_volume"]; - sleep _delay; - for "_i" from 0 to _shots do { - playSound3D [_sound, nil, false, _pos, _volume, 0, 0]; // play sound - sleep random [0.02,0.2,0.5]; - }; - }; - - IRN_remoteSound = { //plays the specified sound on client - params["_sound","_pos","_shots","_delay","_volume","_center","_dist"]; - //get pos - _pos = [_center,_dist] call IRN_calcSoundPos; - //play salvo - [_sound,_pos,_shots,_delay,_volume] call IRN_spawnSalvo; - }; +[false, _duration, _dist, _center, _maxDistance] spawn { //[debug mode, duration in seconds] + params["_debug","_duration","_dist","_center", "_maxDistance"]; + private _i = 0; //iteration counter private ["_posC","_posP","_direction","_dirNorm","_dist","_center","_source"]; @@ -90,7 +60,7 @@ _handle = [false, _duration, _dist, _center] spawn { //[debug mode, duration in for "_i" from 0 to 5 do { //spawn up to 5 salvos of fast fire (MG) _sound = selectRandom (if (random 1 < 0.05) then {_listRare} else {_listShots}); //params["_sound","_pos","_shots","_delay","_volume"]; - [_sound, [0,0,0], random 15, random 10,0.5 + random 0.5,_center,_dist] remoteExec ["IRN_remoteSound",0, true]; + [_sound, [0,0,0], random 15, random 10,0.5 + random 0.5,_center,_dist,_maxDistance] remoteExec ["IRN_fnc_remoteSound",0, true]; }; //-------------- @@ -100,4 +70,4 @@ _handle = [false, _duration, _dist, _center] spawn { //[debug mode, duration in hint ("player to soundsource: " + str (getPosASL player distance _headPos)); hint "finished audio"; }; -} +}; diff --git a/addons/wolf_modules/config.cpp b/addons/wolf_modules/config.cpp index c310467..e361060 100644 --- a/addons/wolf_modules/config.cpp +++ b/addons/wolf_modules/config.cpp @@ -11,12 +11,18 @@ class CfgPatches class CfgFunctions { - class WOLF + class IRN { class a { - class ambientbattles {file = "WOLF_Modules\ambient_battles.sqf";}; - }; + class ambientbattles {file = "WOLF_Modules\ambient_battle\ambient_battles.sqf";}; + + class calcSoundPos {file = "WOLF_Modules\ambient_battle\IRN_calcSoundPos.sqf"}; + + class spawnSalvo {file = "WOLF_Modules\ambient_battle\IRN_spawnSalvo.sqf"}; + + class remoteSound {file = "WOLF_Modules\ambient_battle\IRN_remoteSound.sqf"}; + }; }; }; @@ -34,7 +40,7 @@ class CfgVehicles portrait = "\a3\Modules_F_Curator\Data\portraitSmoke_ca.paa"; displayName = "Ambient Battles"; category = "Effects"; - function = "WOLF_fnc_ambientbattles"; + function = "IRN_fnc_ambientbattles"; is3DEN = 1; isGlobal = 0; isTriggerActivated = 1; @@ -48,63 +54,63 @@ class CfgVehicles { class 50 { - name = "50 Meter"; + name = "50 meters"; value = "50"; default = 1; }; class 100 { - name = "100 Meter"; + name = "100 meters"; value = "100"; }; class 150 { - name = "150 Meter"; + name = "150 meters"; value = "150"; }; class 200 { - name = "200 Meter"; + name = "200 meters"; value = "200"; }; class 250 { - name = "250 Meter"; + name = "250 meters"; value = "250"; }; class 300 { - name = "300 Meter"; + name = "300 meters"; value = "300"; }; class 350 { - name = "350 Meter"; + name = "350 meters"; value = "350"; }; class 400 { - name = "400 Meter"; + name = "400 meters"; value = "400"; }; class 450 { - name = "450 Meter"; + name = "450 meters"; value = "450"; }; class 500 { - name = "500 Meter"; + name = "500 meters"; value = "500"; }; class 550 { - name = "550 Meter"; + name = "550 meters"; value = "550"; }; class 600 { - name = "600 Meter"; + name = "600 meters"; value = "600"; }; }; @@ -117,38 +123,38 @@ class CfgVehicles { class 1 { - name = "1 Minute"; + name = "1 minute"; value = "60"; default = 1; }; class 2 { - name = "2 Minutes"; + name = "2 minutes"; value = "120"; }; class 5 { - name = "5 Minutes"; + name = "5 minutes"; value = "300"; }; class 10 { - name = "10 Minutes"; + name = "10 minutes"; value = "600"; }; class 30 { - name = "30 Minutes"; + name = "30 minutes"; value = "1800"; }; class 60 { - name = "60 Minutes"; + name = "60 minutes"; value = "3600"; }; class 120 { - name = "120 Minutes"; + name = "120 minutes"; value = "7200"; }; class Infinite @@ -156,6 +162,56 @@ class CfgVehicles name = "Infinite"; value = "25555555"; }; + + }; + }; + class maxdistance + { + displayName = "Maximum distance"; + description = "Maximum distance to the module to play sound for the player. If player exceeds the range the sound will be stopped."; + class values + { + class 1000 + { + name = "1000 meters"; + value = "1000"; + }; + class 2000 + { + name = "1500 meters"; + value = "1500"; + }; + class 2000 + { + name = "2000 meters"; + value = "2000"; + }; + class 2500 + { + name = "2500 meters"; + value = "2500"; + }; + class 3000 + { + name = "3000 meters"; + value = "3000"; + default = 1; + }; + class 3500 + { + name = "3500 meters"; + value = "3500"; + }; + class 4000 + { + name = "4000 meters"; + value = "4000"; + }; + class 5000 + { + name = "5000 meters"; + value = "5000"; + }; }; }; };