fn_onhitemp.sqf 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Author: MrClock
  3. * EMP ammo hit handler
  4. *
  5. *
  6. * Arguments:
  7. * 0: Unit <OBJECT>
  8. * 1: Unit <OBJECT>
  9. * 2: Ammo <STRING>
  10. * 3: Projectile <OBJECT>
  11. *
  12. * Example:
  13. * [Bob,Jack,"GrenadeHand",objNull] call JLTS_fnc_onHitEMP;
  14. *
  15. * Return Value:
  16. * None
  17. *
  18. */
  19. #define COOLDOWN 2
  20. params["_target", "_shooter", "_ammo","_projectile"];
  21. if ((getText(configFile >> "CfgAmmo" >> _ammo >> "simulation") != "shotBullet") && ((_projectile distance _target) > getNumber(configFile >> "CfgAmmo" >> _ammo >> "indirectHitRange"))) exitWith {/*systemChat "Out of range"*/};
  22. private _weaponsTarget = weapons _target;
  23. if (_target getVariable["JLTS_EMPCooldown",CBA_missionTime - 1] < CBA_missionTime) then {
  24. if (JLTS_settings_EMP_EMPEffectScope > 0) then {
  25. {
  26. if (getNumber(configFile >> "CfgWeapons" >> _x >> "JLTS_isFried") == 1) then {} else
  27. {
  28. if (getNumber(configFile >> "CfgWeapons" >> _x >> "JLTS_hasElectronics") == 1 && getNumber(configFile >> "CfgWeapons" >> _x >> "JLTS_hasEMPProtection") != 1) then
  29. {
  30. private _friedWeapon = getText(configFile >> "CfgWeapons" >> _x >> "JLTS_friedItem");
  31. switch (true) do {
  32. case (_x in uniformItems _target): {
  33. _target removeItemFromUniform _x;
  34. _target addItemToUniform _friedWeapon;
  35. };
  36. case (_x in vestItems _target): {
  37. _target removeItemFromVest _x;
  38. _target addItemToVest _friedWeapon;
  39. };
  40. case (_x in backpackItems _target): {
  41. _target removeItemFromBackpack _x;
  42. _target addItemToBackpack _friedWeapon;
  43. };
  44. default {
  45. switch (true) do {
  46. case (_x in weapons _target): {
  47. [_x,_target,"FRY"] call JLTS_fnc_weaponEMPEffect;
  48. };
  49. default {};
  50. };
  51. };
  52. };
  53. };
  54. };
  55. } forEach _weaponsTarget;
  56. if (JLTS_settings_EMP_EMPEffectScope > 1) then {
  57. {
  58. if (getNumber(configFile >> "CfgMagazines" >> _x >> "JLTS_hasElectronics") == 1 && getNumber(configFile >> "CfgMagazines" >> _x >> "JLTS_hasEMPProtection") != 1) then {
  59. _target removeMagazines _x;
  60. };
  61. } forEach magazines _target;
  62. };
  63. if (JLTS_settings_EMP_EMPEffectScope > 2) then {
  64. {
  65. if (getNumber(configFile >> "CfgWeapons" >> _x >> "JLTS_hasElectronics") == 1 && getNumber(configFile >> "CfgWeapons" >> _x >> "JLTS_hasEMPProtection") != 1) then {
  66. _target unassignItem _x;
  67. };
  68. } forEach assignedItems _target;
  69. {
  70. if (getNumber(configFile >> "CfgWeapons" >> _x >> "JLTS_hasElectronics") == 1 && getNumber(configFile >> "CfgWeapons" >> _x >> "JLTS_hasEMPProtection") != 1) then {
  71. _target removeItem _x;
  72. };
  73. } forEach items _target;
  74. };
  75. };
  76. playSound3D[
  77. selectRandom [
  78. "MRC\JLTS\weapons\Core\sounds\fried_weapon\1.wss",
  79. "MRC\JLTS\weapons\Core\sounds\fried_weapon\2.wss",
  80. "MRC\JLTS\weapons\Core\sounds\fried_weapon\3.wss",
  81. "MRC\JLTS\weapons\Core\sounds\fried_weapon\4.wss",
  82. "MRC\JLTS\weapons\Core\sounds\fried_weapon\5.wss"
  83. ],
  84. _target,
  85. false,
  86. getPosASL _target,
  87. 5,
  88. 1,
  89. 0
  90. ];
  91. _target setVariable["JLTS_EMPCooldown",CBA_missionTime + COOLDOWN,true];
  92. private _uniform = uniform _target;
  93. private _isDroid = getNumber(configFile >> "CfgWeapons" >> _uniform >> "JLTS_isDroid");
  94. private _affectedUniforms = missionNamespace getVariable["JLTS_emp_affectedUniforms",[]];
  95. private _protectedUniforms = missionNamespace getVariable["JLTS_emp_protectedUniforms",[]];
  96. private _useConfig = missionNamespace getVariable["JLTS_emp_useConfig",true];
  97. //if ((_isDroid != 1 || (_uniform in _protectedUniforms)) && !(_uniform in _affectedUniforms)) exitWith {[_target,"HUMAN"] remoteExec ["JLTS_fnc_showHintEMP",0,true];};
  98. _toFry = false;
  99. if (_useConfig) then {
  100. if ((_isDroid == 1 || _uniform in _affectedUniforms) && {!(_uniform in _protectedUniforms)} && {alive _target}) then {
  101. _toFry = true;
  102. };
  103. } else {
  104. if (_uniform in _affectedUniforms && {alive _target}) then {
  105. _toFry = true;
  106. };
  107. };
  108. if (_toFry) then {
  109. [_target] spawn {
  110. private _timeOfHit = CBA_missionTime;
  111. private _useDefaultSounds = missionNamespace getVariable["JLTS_emp_useDefaultSounds",true];
  112. params ["_target"];
  113. private _uniform = uniform _target;
  114. _target stop true;
  115. waitUntil {_timeOfHit + 1 < CBA_missionTime};
  116. _target disableAI "all";
  117. [_target,"DROID"] remoteExec ["JLTS_fnc_showHintEMP",0,true];
  118. private _delay = _timeOfHit + random[1,5,10];
  119. waitUntil {_delay < CBA_missionTime};
  120. if (getText(configFile >> "CfgWeapons" >> _uniform >> "JLTS_deathSounds") != "") then {
  121. private _deathSoundClass = getText(configFile >> "CfgWeapons" >> _uniform >> "JLTS_deathSounds");
  122. private _friedSound = selectRandom getArray(configFile >> "CfgJLTSDeathSounds" >> _deathSoundClass >> "emp");
  123. playSound3D[_friedSound,_target,false,getPosASL _target,2,1,0];
  124. } else {
  125. if (_useDefaultSounds) then {
  126. private _friedSound = selectRandom getArray(configFile >> "CfgJLTSDeathSounds" >> "DeathDroid" >> "emp");
  127. playSound3D[_friedSound,_target,false,getPosASL _target,2,1,0];
  128. };
  129. };
  130. if (alive _target) then {
  131. _target setDamage 1;
  132. };
  133. _target setVariable ["JLTS_EMPCooldown",nil, true];
  134. };
  135. } else {
  136. [_target,"HUMAN"] remoteExec ["JLTS_fnc_showHintEMP",0,true];
  137. };
  138. } else {
  139. //systemChat "EMP cooldown"
  140. };