Browse Source

Merge pull request #76 from 501st-Aux-Mod-Team/emp

Emp
Erliens 4 years ago
parent
commit
2103bdba50

BIN
@501st Community Auxiliary Mod/addons/VenMK2.pbo.RD501_Aux_Mod.bisign


+ 69 - 0
addons - Copy/RD501_EMP/config.cpp

@@ -0,0 +1,69 @@
+#include "../RD501_main/config_macros.hpp"
+
+class CfgPatches
+{
+	class macro_patch_name(emp)
+	{
+		author=DANKAUTHORS;
+		requiredAddons[]=
+		{
+			macro_root_req
+		};
+		requiredVersion=0.1;
+		units[]={};
+		weapons[]={};
+	};
+};
+
+class CfgFunctions
+{
+	class RD501
+	{
+		class Weapons
+		{
+			file="\RD501_EMP";
+			class onHit
+			{
+			};
+			class onHitEMP
+			{
+			};
+			class showHintEMP
+			{
+			};
+		};
+	};
+};
+class Extended_HitPart_EventHandlers
+{
+	class CAManBase
+	{
+		JLTS_weapons_core="if (JLTS_settings_EMP_mainSwitch == 1 || JLTS_settings_Stun_mainSwitch == 1) then {(_this select 0) call RD501_fnc_onHit}";
+	};
+};
+class CfgHints
+{
+	class RD501_ordnance
+	{
+		displayName="$STR_JLTS_names_HintCatOrdnance";
+		category="JLTS";
+		logicalOrder=2;
+		class EMP
+		{
+			displayName="$STR_JLTS_names_HintEMPEffect";
+			description="$STR_JLTS_descs_HintEMPEffect";
+			tip="$STR_JLTS_tips_HintEMPEffect";
+			arguments[]={};
+			image="\MRC\JLTS\weapons\Core\data\ui\hint_emp_ca.paa";
+			logicalOrder=1;
+			class EMP_sub_fry
+			{
+				displayName="Weapon Jammed";
+				description="You have been struck by EMP which may have damaged the circuits of some of your weapons and inventory items. Use the 'Clear Jam' keybind to fix your weapon.";
+				tip="$STR_JLTS_tips_HintEMPEffect";
+				arguments[]={};
+				image="\MRC\JLTS\weapons\Core\data\ui\hint_emp_fry_ca.paa";
+			};
+		};
+	};
+};

+ 28 - 0
addons - Copy/RD501_EMP/fn_onhit.sqf

@@ -0,0 +1,28 @@
+/*
+ * Author: MrClock
+ * HitPart XEH function
+ *
+ *
+ * Arguments:
+ * Inherited from HitPart XEH
+ *
+ * Example:
+ * (_this select 0) call JLTS_fnc_onHit;
+ *
+ * Return Value:
+ * None
+ *
+ */
+
+params["_target", "_shooter", "_projectile", "_position", "_velocity", "_selection", "_ammo", "_vector", "_radius", "_surfaceType", "_isDirect"];
+
+//if (!hasInterface) exitWith {};
+
+if (isNil{_ammo select 4}) exitWith {/*systemChat "Fall damage"*/};
+
+if (!alive _target) exitWith {};
+
+private _ammoUsed = _ammo select 4;
+
+if (getNumber(configFile >> "CfgAmmo" >> _ammoUsed >> "JLTS_isEMPAmmo") == 1) then {[_target,_shooter,_ammoUsed,_projectile] call RD501_fnc_onHitEMP};
+if (getNumber(configFile >> "CfgAmmo" >> _ammoUsed >> "JLTS_isStunAmmo") == 1) then {[_target,_shooter,_ammoUsed] call JLTS_fnc_onHitStun};

+ 178 - 0
addons - Copy/RD501_EMP/fn_onhitemp.sqf

@@ -0,0 +1,178 @@
+/*
+ * Author: MrClock
+ * EMP ammo hit handler
+ *
+ *
+ * Arguments:
+ * 0: Unit <OBJECT>
+ * 1: Unit <OBJECT>
+ * 2: Ammo <STRING>
+ * 3: Projectile <OBJECT>
+ *
+ * Example:
+ * [Bob,Jack,"GrenadeHand",objNull] call JLTS_fnc_onHitEMP;
+ *
+ * Return Value:
+ * None
+ *
+ */
+ 
+#define COOLDOWN 2
+
+params["_target", "_shooter", "_ammo","_projectile"];
+
+if ((getText(configFile >> "CfgAmmo" >> _ammo >> "simulation") != "shotBullet") && ((_projectile distance _target) > getNumber(configFile >> "CfgAmmo" >> _ammo >> "indirectHitRange"))) exitWith {/*systemChat "Out of range"*/}; 
+
+private _weaponsTarget = weapons _target;
+private _fryOnEMP = false;
+
+if (_target getVariable["JLTS_EMPCooldown",CBA_missionTime - 1] < CBA_missionTime) then {
+
+	if (JLTS_settings_EMP_EMPEffectScope > 0) then {
+		{
+			if (getNumber(configFile >> "CfgWeapons" >> _x >> "JLTS_isFried") == 1) then {} else 
+			{
+				if (getNumber(configFile >> "CfgWeapons" >> _x >> "JLTS_hasElectronics") == 1 &&
+				    getNumber(configFile >> "CfgWeapons" >> _x >> "JLTS_hasEMPProtection") != 1 &&
+				    getNumber(configFile >> "CfgWeapons" >> _x >> "RD501_fryOnEMP") != 1) then {
+					private _friedWeapon = getText(configFile >> "CfgWeapons" >> _x >> "JLTS_friedItem");
+					switch (true) do {
+						case (_x in uniformItems _target): {
+							_target removeItemFromUniform _x;
+							_target addItemToUniform _friedWeapon;
+						};
+						case (_x in vestItems _target): {
+							_target removeItemFromVest _x;
+							_target addItemToVest _friedWeapon;
+						};
+						case (_x in backpackItems _target): {
+							_target removeItemFromBackpack _x;
+							_target addItemToBackpack _friedWeapon;
+						};
+						default {
+							switch (true) do {
+								case (_x in weapons _target): {
+									[_x,_target,"FRY"] call JLTS_fnc_weaponEMPEffect;
+								};
+								default {};
+							};
+						};
+					};
+					_fryOnEMP = true;
+				} else {
+				    if (getNumber(configFile >> "CfgWeapons" >> _x >> "JLTS_hasEMPProtection") != 1 &&
+                    	getNumber(configFile >> "CfgWeapons" >> _x >> "RD501_fryOnEMP") != 1) then
+                    {
+                        [_target, currentWeapon _target] call ace_overheating_fnc_jamWeapon;
+                    };
+				};
+			};
+		} forEach _weaponsTarget;
+
+		if (JLTS_settings_EMP_EMPEffectScope > 1) then {
+			{
+				if (getNumber(configFile >> "CfgMagazines" >> _x >> "JLTS_hasElectronics") == 1 && getNumber(configFile >> "CfgMagazines" >> _x >> "JLTS_hasEMPProtection") != 1) then {
+					_target removeMagazines _x;
+				};
+			} forEach magazines _target;
+		};
+		
+		if (JLTS_settings_EMP_EMPEffectScope > 2) then {
+			{
+				if (getNumber(configFile >> "CfgWeapons" >> _x >> "JLTS_hasElectronics") == 1 && getNumber(configFile >> "CfgWeapons" >> _x >> "JLTS_hasEMPProtection") != 1) then {
+					_target unassignItem _x;
+				};
+			} forEach assignedItems _target;
+			{
+				if (getNumber(configFile >> "CfgWeapons" >> _x >> "JLTS_hasElectronics") == 1 && getNumber(configFile >> "CfgWeapons" >> _x >> "JLTS_hasEMPProtection") != 1) then {
+					_target removeItem _x;
+				};
+			} forEach items _target;
+		};
+	};
+	
+	playSound3D[
+		selectRandom [
+			"MRC\JLTS\weapons\Core\sounds\fried_weapon\1.wss",
+			"MRC\JLTS\weapons\Core\sounds\fried_weapon\2.wss",
+			"MRC\JLTS\weapons\Core\sounds\fried_weapon\3.wss",
+			"MRC\JLTS\weapons\Core\sounds\fried_weapon\4.wss",
+			"MRC\JLTS\weapons\Core\sounds\fried_weapon\5.wss"
+		],
+		_target,
+		false,
+		getPosASL _target,
+		5,
+		1,
+		0
+	];
+	
+	_target setVariable["JLTS_EMPCooldown",CBA_missionTime + COOLDOWN,true];
+	
+	private _uniform = uniform _target;
+	private _isDroid = getNumber(configFile >> "CfgWeapons" >> _uniform >> "JLTS_isDroid");
+	private _affectedUniforms = missionNamespace getVariable["JLTS_emp_affectedUniforms",[]];
+	private _protectedUniforms = missionNamespace getVariable["JLTS_emp_protectedUniforms",[]];
+	private _useConfig = missionNamespace getVariable["JLTS_emp_useConfig",true];
+
+	_toFry = false;
+	
+	if (_useConfig) then {
+		if ((_isDroid == 1 || _uniform in _affectedUniforms) && {!(_uniform in _protectedUniforms)} && {alive _target}) then {
+			_toFry = true;
+		};
+	} else {
+		if (_uniform in _affectedUniforms && {alive _target}) then {
+			_toFry = true;
+		};
+	};
+
+	if (_toFry) then {
+		
+		[_target] spawn {
+			private _timeOfHit = CBA_missionTime;
+			private _useDefaultSounds = missionNamespace getVariable["JLTS_emp_useDefaultSounds",true];
+
+			
+			params ["_target"];
+			private _uniform = uniform _target;
+			_target stop true;
+
+			waitUntil {_timeOfHit + 1 < CBA_missionTime};
+			_target disableAI "all";
+            if (_fryOnEMP) then {
+                [_target,"DROID"] remoteExec ["JLTS_fnc_showHintEMP",0,true];
+            } else {
+                [_target,"DROID"] remoteExec ["RD501_fnc_showHintEMP",0,true];
+            };
+			private _delay = _timeOfHit + random[1,5,10];
+			waitUntil {_delay < CBA_missionTime};
+			
+			if (getText(configFile >> "CfgWeapons" >> _uniform >> "JLTS_deathSounds") != "") then {
+				private _deathSoundClass = getText(configFile >> "CfgWeapons" >> _uniform >> "JLTS_deathSounds");
+				private _friedSound = selectRandom getArray(configFile >> "CfgJLTSDeathSounds" >> _deathSoundClass >> "emp");
+				playSound3D[_friedSound,_target,false,getPosASL _target,2,1,0];
+			} else {
+				if (_useDefaultSounds) then {
+					private _friedSound = selectRandom getArray(configFile >> "CfgJLTSDeathSounds" >> "DeathDroid" >> "emp");
+					playSound3D[_friedSound,_target,false,getPosASL _target,2,1,0];
+				};
+			};
+			
+
+			if (alive _target) then {
+				_target setDamage 1;
+			};
+			
+			_target setVariable ["JLTS_EMPCooldown",nil, true];
+		};
+	} else {
+    	if (_fryOnEMP) then {
+		    [_target,"HUMAN"] remoteExec ["JLTS_fnc_showHintEMP",0,true];
+		} else {
+		    [_target,"HUMAN"] remoteExec ["RD501_fnc_showHintEMP",0,true];
+		};
+	};
+} else {
+	//systemChat "EMP cooldown"
+};

+ 52 - 0
addons - Copy/RD501_EMP/fn_showhintemp.sqf

@@ -0,0 +1,52 @@
+/*
+ * Author: MrClock
+ *
+ * Arguments:
+ * 0: Unit <OBJECT>
+ * 1: Type <STRING>
+ *
+ * Example:
+ * [Bob,"HUMAN"] call JLTS_fnc_showHintEMP;
+ *
+ * Return Value:
+ * true - if completed without errors
+ */
+
+if (!hasInterface) exitWith {};
+
+params["_unit","_type"];
+
+private _player = JLTS_playerControlled;
+
+
+if (_unit == _player) then {
+	if (JLTS_settings_EMP_notifyPlayer) then {
+		if (toUpper _type == "DROID") then {
+			[
+				["JLTS_ordnance","EMP","EMP_sub_droid"], 
+				20, 
+				nil, 
+				30, 
+				nil, 
+				true, 
+				true, 
+				false, 
+				true
+			] call BIS_fnc_advHint;
+		} else {
+			if (toUpper _type == "HUMAN" && JLTS_settings_EMP_EMPEffectScope > 0) then {
+				[
+					["RD501_ordnance","EMP","EMP_sub_fry"],
+					20, 
+					nil, 
+					30, 
+					nil, 
+					true, 
+					true, 
+					false, 
+					true
+				] call BIS_fnc_advHint;
+			} else {};
+		};
+	};
+};

+ 18 - 0
addons - Copy/RD501_EMP/readme.md

@@ -0,0 +1,18 @@
+RD501 EMP adjustments
+======
+Goal
+------
+While JLTS' EMP system works great, its weapon swap feature was deemed to taxing on the servers, especially considering the possibility of cluster-EMP that might hit hundreds of units.
+
+To still have EMP effect guns, but avoid the switching, all guns not configured otherwise will jam when hit by EMP.
+
+Config
+------
+Default (no config params): Gun jams on EMP
+
+To go back to JLTS behaviour:
+* JLTS_hasElectronics = 1
+* JLTS_hasEMPProtection = 0
+* **RD501_fryOnEMP = 1**
+
+If RD501_fryOnEMP is not set to 1, the gun will still jam, thus having the desired behaviour on default JLTS guns without having to edit their config.

+ 1 - 1
addons - Copy/RD501_Main/config_macros.hpp

@@ -77,9 +77,9 @@
 	#define macro_patch_name(component) MODNAME##_patch_##component
 	#define macro_A3_patch "A3_Data_F_Tank_Loadorder"
 	#define macro_root_req macro_patch_name(main)
-	#define macro_lvl1_req macro_patch_name(particle_effects),RD501_patch_Airborne_Helmet_Model,RD501_patch_VenatorMK2
 	#define macro_lvl2_req macro_patch_name(weapons),macro_patch_name(jumppack),macro_patch_name(helmets),macro_patch_name(vehicle_weapons)
 	#define macro_lvl3_req macro_patch_name(units),macro_patch_name(vehicles),macro_patch_name(zeus)
+	#define macro_lvl1_req macro_patch_name(particle_effects),RD501_patch_Airborne_Helmet_Model,RD501_patch_VenatorMK2,macro_patch_name(emp)
 	#define macro_lvl4_req macro_patch_name(droids_config),macro_patch_name(laat_variants)
 	#define macro_lvl5_req macro_patch_name(legacy_classnames)
 	#define macro_end_patches macro_lvl5_req

+ 3 - 3
addons - Copy/RD501_Units/materials/razorblade_holster.rvmat

@@ -8,7 +8,7 @@ PixelShaderID="Super";
 VertexShaderID="Super";
 class Stage1
 {
-	texture="\RD501_Units\textures\republic\clones\avi\acc\razorblade_holster_nohq.paa";
+	texture="RD501_Units\textures\republic\clones\avi\acc\razorblade_holster_nohq.paa";
 	uvSource="tex";
 	class uvTransform
 	{
@@ -44,7 +44,7 @@ class Stage3
 };
 class Stage4
 {
-	texture="\RD501_Units\textures\republic\clones\avi\acc\razorblade_holster_as.paa";
+	texture="RD501_Units\textures\republic\clones\avi\acc\razorblade_holster_as.paa";
 	uvSource="tex";
 	class uvTransform
 	{
@@ -56,7 +56,7 @@ class Stage4
 };
 class Stage5
 {
-	texture="\RD501_Units\textures\republic\clones\avi\acc\razorblade_holster_smdi.paa";
+	texture="RD501_Units\textures\republic\clones\avi\acc\razorblade_holster_smdi.paa";
 	uvSource="tex";
 	class uvTransform
 	{