fnc_shield_checkState.sqf 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. params["_shield"];
  2. if(_shield isEqualTo objNull) exitWith {
  3. diag_log format["[RD501][Shield] Specified shield is null while checking state"];
  4. };
  5. private _maxHealth = _shield getVariable ["rd501_shield_maxHealth", false];
  6. private _currentHealth = _shield getVariable ["rd501_shield_currentHealth", false];
  7. private _isLowHealth = _shield getVariable ["rd501_shield_isLowHealth", false];
  8. private _lowHealthPercentage = _shield getVariable ["rd501_shield_lowHealthPercentage", 20];
  9. private _threshold = _maxHealth * (_lowHealthPercentage/100);
  10. private _type = _shield getVariable ["rd501_shield_type", "REPUBLIC"];
  11. if(_isLowHealth) exitWith {
  12. if(_currentHealth >= _threshold) then {
  13. _shield setVariable["rd501_shield_isLowHealth", false];
  14. private _jipId = _shield getVariable ["rd501_shield_stateJipId", false];
  15. if(_jipId isEqualTo false) then {
  16. _jipId = ["rd501_shield_normalHealth",[_shield, _type]] call CBA_fnc_globalEventJIP;
  17. _shield setVariable ["rd501_shield_stateJipId", _jipId, true];
  18. [_jipId, _shield] call CBA_fnc_removeGlobalEventJIP;
  19. }
  20. else
  21. {
  22. ["rd501_shield_normalHealth",[_shield, _type], _jipId] call CBA_fnc_globalEventJIP;
  23. [_jipId, _shield] call CBA_fnc_removeGlobalEventJIP;
  24. };
  25. };
  26. };
  27. if!(_isLowHealth) exitWith {
  28. if(_currentHealth < _threshold) then {
  29. _shield setVariable["rd501_shield_isLowHealth", true];
  30. private _jipId = _shield getVariable ["rd501_shield_stateJipId", false];
  31. if(_jipId isEqualTo false) then {
  32. _jipId = ["rd501_shield_normalHealth",[_shield, _type]] call CBA_fnc_globalEventJIP;
  33. _shield setVariable ["rd501_shield_stateJipId", _jipId, true];
  34. [_jipId, _shield] call CBA_fnc_removeGlobalEventJIP;
  35. }
  36. else
  37. {
  38. ["rd501_shield_lowHealth",[_shield, _type], _jipId] call CBA_fnc_globalEventJIP;
  39. [_jipId, _shield] call CBA_fnc_removeGlobalEventJIP;
  40. };
  41. };
  42. };