Browse Source

Merge branch 'add-squad-shield-server-sounds' into patch1121

m3ales 4 years ago
parent
commit
1610ca2735

+ 17 - 67
addons - Copy/RD501_Main/XEH_postinit.sqf

@@ -85,71 +85,21 @@ call macro_fnc_name(stun);
 	}, 1] call CBA_fnc_addPerFrameHandler;
 }] call CBA_fnc_addEventHandler;
 
-// Grenade Deployables
-["ace_firedPlayer", {
-    params["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile"];
-
-    if (isNull _projectile) then {
-        _projectile = nearestObject [_unit, _ammo];
-    };
-    private _config = configFile >> "CfgAmmo" >> _ammo;
-    if (getNumber (_config >> "rd501_grenade_deployable") == 1) then {
-        private _deployable = getText (_config >> "rd501_grenade_deployable_object");
-        private _ttl = getNumber (_config >> "rd501_grenade_deployable_timeToLive");
-        if(isNil "_ttl") then {
-            _ttl = -1;
-        };
-        [
-            {
-                params["_projectile", "_deployable"];
-                private _speed = vectorMagnitude (velocity _projectile);
-                !(isNil "_projectile") && (alive _projectile) && _speed <= 0.1
-            }, 
-            {
-                params["_projectile", "_deployable", "_timeToLive"];
-                private _position = getPosATL _projectile;
-                private _deployed = createVehicle [_deployable, _position, [], 0, "CAN_COLLIDE"];
-				_deployed setPosATL _position;
-                deleteVehicle _projectile;
-                if(_timeToLive > 0) then {
-                    [
-                        {
-                            params["_deployed"];
-                            deleteVehicle _deployed;
-                        },
-                        [_deployed],
-                        _timeToLive
-                    ] call CBA_fnc_waitAndExecute;
-                };
-            },
-            [_projectile, _deployable, _ttl, _magazine, _unit],
-            10, 
-            { 
-                params["", "", "", "_magazine", "_unit"];
-				systemChat "Something went wrong with your order, we apologise for the inconvenience.";
-				systemChat "Please file all complaints with Mirror at the Aux Office.";
-				[
-					{
-						params["_unit", "_mag"];
-						_unit addItem _mag;
-						systemChat "We've attached a complementary replacement if you had any inventory space.";
-					},
-					[_unit, _magazine],
-					2
-				] call CBA_fnc_waitAndExecute;
-			}
-        ] call CBA_fnc_waitUntilAndExecute;
-    };
-}] call CBA_fnc_addEventHandler;
+// Fired Deployables
+if(isServer) then {
+	["rd501_fired_deployable_deployServer", {
+		_this call rd501_fnc_fired_deployable_deployServer
+	}] call CBA_fnc_addEventHandler;
+};
 
-// Prevent Dismount on all Zeus Placed Items
-{
-	private _idx = _x addEventHandler ["CuratorObjectPlaced", {
-		params ["_curator","_entity"];
-		if(!(_entity isKindOf "Man") && (side _entity) == east) then {
-			_entity allowCrewInImmobile true;
-			_entity setVehicleLock "LOCKED";
-		};
-	}];
-	_x setVariable ["rd501_curator_dismount_disable_index", _idx, false];
-} forEach allCurators;
+if(hasInterface) then {
+	["ace_firedPlayer", {
+		_this call rd501_fnc_fired_deployable_firedHandler
+	}] call CBA_fnc_addEventHandler;
+	["rd501_fired_deployable_soundLoop", {
+		_this call rd501_fnc_fired_deployable_loopSoundLocal
+	}] call CBA_fnc_addEventHandler;
+	["rd501_fired_deployable_soundEnd", {
+		_this call rd501_fnc_fired_deployable_endSoundLocal
+	}] call CBA_fnc_addEventHandler;
+};

+ 6 - 0
addons - Copy/RD501_Main/XEH_preInit.sqf

@@ -149,4 +149,10 @@ macro_prep_xeh(impulse\fnc_impulseApply.sqf,impulseApply)
 macro_prep_xeh(impulse\fnc_impulseIncrease.sqf,impulseIncrease)
 macro_prep_xeh(impulse\fnc_impulseDecrease.sqf,impulseDecrease)
 
+// Fired Deployables
+macro_prep_xeh(fired_deployable\fnc_fired_deployable_firedHandler.sqf,fired_deployable_firedHandler)
+macro_prep_xeh(fired_deployable\fnc_fired_deployable_deployServer.sqf,fired_deployable_deployServer)
+macro_prep_xeh(fired_deployable\fnc_fired_deployable_loopSoundLocal.sqf,fired_deployable_loopSoundLocal)
+macro_prep_xeh(fired_deployable\fnc_fired_deployable_endSoundLocal.sqf,fired_deployable_endSoundLocal)
+
 diag_log "RD501 PREP Complete";

+ 51 - 0
addons - Copy/RD501_Main/functions/fired_deployable/fnc_fired_deployable_deployServer.sqf

@@ -0,0 +1,51 @@
+params[["_ammo", ""], ["_position", [0,0,0]]];
+
+diag_log format["Deploying Squad Shield for %1 at %2", _ammo, _position];
+
+private _config = configFile >> "CfgAmmo" >> _ammo; 
+if!(isClass _config) exitWith { 
+	diag_log format["Unable to find class '%1' in CfgAmmo", _ammo]; 
+}; 
+
+private _isValid = getNumber (_config >> "rd501_fired_deployable") == 1;
+private _deployable = getText (_config >> "rd501_fired_deployable_object");
+private _timeToLive = getNumber (_config >> "rd501_fired_deployable_timeToLive");
+
+if(!_isValid) exitWith {
+	diag_log format["Requested throw type '%1' is does not contain rd501_fired_deployable=1", _ammo];
+};
+
+if(isNil "_deployable" || _deployable isEqualTo "") exitWith { 
+	diag_log format["Failed to find rd501_fired_deployable_object defined in ammo type %1", _ammo];
+};
+
+_config = configFile >> "CfgVehicles" >> _deployable;
+private _loopSound = getText (_config >> "rd501_fired_deployable_loopSound");
+private _loopDuration = getNumber (_config >> "rd501_fired_deployable_loopDuration");
+private _endSound = getText (_config >> "rd501_fired_deployable_endSound");
+private _endDuration = getNumber (_config >> "rd501_fired_deployable_endDuration");
+private _soundDistance = getNumber (_config >> "rd501_fired_deployable_soundDistance");
+
+private _deployed = createVehicle [_deployable, _position, [], 0, "CAN_COLLIDE"];
+_deployed setPosATL _position;
+
+if(_timeToLive > 0) then {
+	[
+		{
+			params["_deployable"];
+			deleteVehicle _deployable;
+		},
+		[_deployed],
+		_timeToLive
+	] call CBA_fnc_waitAndExecute;
+
+	[
+		{
+			params["_deployed", "_endSound", "_endDuration", "_distance"];
+			["rd501_fired_deployable_soundEnd", [_deployed, _endSound, _endDuration, _distance]] call CBA_fnc_globalEvent;
+		},
+		[_deployed, _endSound, _endDuration, _soundDistance],
+		(_timeToLive - _endDuration)
+	] call CBA_fnc_waitAndExecute;
+	["rd501_fired_deployable_soundLoop", [_deployed, _loopSound, _loopDuration, _timeToLive, _soundDistance]] call CBA_fnc_globalEvent;
+};

+ 31 - 0
addons - Copy/RD501_Main/functions/fired_deployable/fnc_fired_deployable_endSoundLocal.sqf

@@ -0,0 +1,31 @@
+
+params["_object", "_endSound", "_endDuration", "_distance"];
+
+if(!hasInterface) exitWith {
+	diag_log "No Interface to play sounds from";
+};
+
+if(isNil "_object" || !alive _object) exitWith {
+	systemChat "No target object to play remote sound";
+};
+
+private _currentLoopSource = _object getVariable ["rd501_fired_deployable_loopSoundSource", objNull];
+if(!(isNil "_currentLoopSource") && !(_currentLoopSource isEqualTo objNull)) then {
+	systemChat "Current Loop Source Exists, Deleting";
+	deleteVehicle _currentLoopSource;
+	_object setVariable ["rd501_fired_deployable_loopSoundSource", objNull, false];
+};
+
+private _currentSource = "#dynamicsound" createVehicleLocal ASLToAGL getPosWorld _object;
+_currentSource attachTo [_object, [0, 0, 0]];
+
+[_currentSource, player] say3D [_endSound, _distance, 1, false];
+[
+	{
+		params["_currentSource"];
+		detach _currentSource;
+		deleteVehicle _currentSource;
+	},
+	[_currentSource],
+	(_endDuration + 1)
+] call CBA_fnc_waitAndExecute;

+ 41 - 0
addons - Copy/RD501_Main/functions/fired_deployable/fnc_fired_deployable_firedHandler.sqf

@@ -0,0 +1,41 @@
+params["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile"];
+
+if(!local _unit) exitWith { diag_log "Fired Deployable not local" };
+
+if (isNull _projectile) then {
+	_projectile = nearestObject [_unit, _ammo];
+};
+private _config = configFile >> "CfgAmmo" >> _ammo;
+private _deployable = getNumber (_config >> "rd501_fired_deployable");
+
+if (_deployable == 1) then {
+	[
+		{
+			params["_projectile"];
+			private _speed = vectorMagnitude (velocity _projectile);
+			!(isNil "_projectile") && (alive _projectile) && _speed <= 0.1
+		},
+		{
+			params["_projectile", "_ammo"];
+			private _position = getPosATL _projectile;
+			["rd501_fired_deployable_deployServer", [_ammo, _position]] call CBA_fnc_serverEvent;
+			deleteVehicle _projectile;
+		},
+		[_projectile, _ammo, _magazine, _unit],
+		10,
+		{ 
+			params["", "", "_magazine", "_unit"];
+			systemChat "Something went wrong with your order, we apologise for the inconvenience.";
+			systemChat "Please file all complaints with Mirror at the Aux Office.";
+			[
+				{
+					params["_unit", "_mag"];
+					_unit addItem _mag;
+					systemChat "We've attached a complementary replacement if you had any inventory space.";
+				},
+				[_unit, _magazine],
+				2
+			] call CBA_fnc_waitAndExecute;
+		}
+	] call CBA_fnc_waitUntilAndExecute;
+};

+ 46 - 0
addons - Copy/RD501_Main/functions/fired_deployable/fnc_fired_deployable_loopSoundLocal.sqf

@@ -0,0 +1,46 @@
+
+params["_object", "_loopSound", "_loopDuration", "_totalDuration", "_distance"];
+
+if(!hasInterface) exitWith {
+	diag_log "No Interface to play sounds from";
+};
+
+if(isNil "_object" || !alive _object) exitWith {
+	diag_log "No target object to play remote sound";
+};
+
+private _currentSource = _object getVariable ["rd501_fired_deployable_loopSoundSource", objNull];
+systemChat str _currentSource;
+if(!(isNil "_currentSource") && !(_currentSource isEqualTo objNull)) exitWith {
+	diag_log "Source already exists, removing";
+	detach _currentSource;
+	deleteVehicle _currentSource;
+	_object setVariable ["rd501_fired_deployable_loopSoundSource", objNull, false];
+	[_object, _loopSound, _loopDuration, _totalDuration, _distance] call rd501_fnc_fired_deployable_loopSoundLocal;
+};
+
+_currentSource = "#dynamicsound" createVehicleLocal ASLToAGL getPosWorld _object;
+_currentSource attachTo [_object, [0, 0, 0]];
+_object setVariable ["rd501_fired_deployable_loopSoundSource", _currentSource, false];
+
+private _repeats = ceil (_totalDuration / _loopDuration);
+for "_i" from 0 to _repeats step 1 do {
+	private _delay = ((_loopDuration * _i) - 0.1) max 0.1; //offset by a bit to ensure loop doesn't have a hitch
+	private _last = _repeats == _i;
+	diag_log format["Queuing Up Repeat %1 for delay %2", _i, _delay];
+	[
+		{
+			params["_currentSource", "_loopSound", "_distance", "_last"];
+			if(isNil "_currentSource" || !alive _currentSource) exitWith { systemChat "No Source, Exiting." };
+			[_currentSource, player] say3D [_loopSound, _distance, 1, false];
+			if(_last) then {
+				diag_log "Last Loop, Deleting";
+				detach _currentSource;
+				deleteVehicle _currentSource;
+			};
+		},
+		[_currentSource, _loopSound, _distance, _last],
+		_delay
+	] call CBA_fnc_waitAndExecute;
+};
+_currentSource

+ 30 - 0
addons - Copy/RD501_Vehicles/static/shields/config.cpp

@@ -50,6 +50,11 @@ class CfgVehicles
 		displayName="Squad Shield";
 		model="\RD501_Vehicles\static\shields\bubble\bubble.p3d";
 		icon="iconObject_1x1";
+		rd501_fired_deployable_loopSound = "rd501_squad_shield_loop";
+		rd501_fired_deployable_loopDuration = 14;
+		rd501_fired_deployable_endSound = "rd501_squad_shield_end";
+		rd501_fired_deployable_endDuration = 1;
+		rd501_fired_deployable_soundDistance = 300;
 		vehicleClass = macro_editor_vehicle_type(statics)
 		editorCategory =  macro_editor_cat(statics)
 		editorSubcategory = macro_editor_cat(static_msc)
@@ -77,4 +82,29 @@ class CfgVehicles
 		editorCategory =  macro_editor_cat(statics)
 		editorSubcategory = macro_editor_cat(static_msc)
 	};
+};
+class CfgSounds
+{
+	class rd501_squad_shield_loop
+	{
+		// how the sound is referred to in the editor (e.g. trigger effects)
+		name = "shield_loop";
+
+		// filename, volume, pitch, distance (optional)
+		sound[] = { "\RD501_Vehicles\static\shields\shield_loop.wss", 4, 1, 300 };
+
+		// subtitle delay in seconds, subtitle text
+		titles[] = { 1, "*Electric Shield Hum*" };
+	};
+	class rd501_squad_shield_end
+	{
+		// how the sound is referred to in the editor (e.g. trigger effects)
+		name = "shield_loop";
+
+		// filename, volume, pitch, distance (optional)
+		sound[] = { "\RD501_Vehicles\static\shields\shield_end.wss", 4, 1, 300 };
+
+		// subtitle delay in seconds, subtitle text
+		titles[] = { 1, "*Shield Retracting Hiss*" };
+	};
 };

BIN
addons - Copy/RD501_Vehicles/static/shields/shield_end.wss


BIN
addons - Copy/RD501_Vehicles/static/shields/shield_loop.wss


+ 3 - 3
addons - Copy/RD501_Weapons/_ammo/config.cpp

@@ -300,9 +300,9 @@ class CfgAmmo
 		indirectHit=0;
 		indirectHitRange=0;
 		model="\RD501_Weapons\Grenades\data\icecream.p3d";
-		rd501_grenade_deployable = 1;
-        rd501_grenade_deployable_object = "RD501_Squad_Shield";
-        rd501_grenade_deployable_timeToLive = 60;
+		rd501_fired_deployable = 1;
+        rd501_fired_deployable_object = "RD501_Squad_Shield";
+        rd501_fired_deployable_timeToLive = 60;
 		simulation="shotShell";
 	}
 ///////////////////////////////////////////////////////////////////////