fnc_shield_onHit.sqf 1.2 KB

1234567891011121314151617181920212223242526
  1. (_this select 0) params ["_target", "_shooter", "_projectile", "_position", "_velocity", "_selection", "_ammo", "_vector", "_radius", "_surfaceType", "_isDirect"];
  2. if(_target isEqualTo objNull) exitWith { systemChat "Target is null idk why"; };
  3. private _health = _target getVariable ["rd501_shield_currentHealth", false];
  4. if(_health isEqualTo false) exitWith { systemChat "Health not found"; };
  5. _ammo params ["_directHit", "_indirectHit", "_indirectRange", "_explosionHit", "_ammoClass"];
  6. private _hit = _directHit + (_indirectHit/(_indirectRange max 0.1)) + _explosionHit;
  7. private _result = _health - _hit;
  8. if(_result <= 0) then {
  9. _target setVariable ["rd501_shield_currentHealth", _result, true];
  10. private _ehId = _target getVariable ["rd501_shield_ehId", -1];
  11. ["rd501_shield_destroy", [_target], _target] call cba_fnc_targetEvent;
  12. _target removeEventHandler ["HitPart", _ehId];
  13. }
  14. else
  15. {
  16. // Set locally only to reduce network traffic
  17. _target setVariable ["rd501_shield_currentHealth", _result];
  18. [_target] call rd501_fnc_shield_checkState;
  19. private _delay = _target getVariable["rd501_shield_regenDelay", 5];
  20. _target setVariable ["rd501_shield_regenStartsAt", diag_tickTime + _delay];
  21. };