fnc_shield_checkState.sqf 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. params["_shield"];
  2. if(_shield isEqualTo objNull) exitWith {
  3. diag_log format["[RD501][Shield] Specified shield is null while checking state '%1", _shield];
  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. diag_log "[RD501][Shield] Shield is now normal health, updating texture on clients";
  14. _shield setVariable["rd501_shield_isLowHealth", false];
  15. private _jipId = _shield getVariable ["rd501_shield_stateJipId", false];
  16. if(_jipId isEqualTo false) then {
  17. _jipId = ["rd501_shield_normalHealth",[_shield, _type]] call CBA_fnc_globalEventJIP;
  18. _shield setVariable ["rd501_shield_stateJipId", _jipId, true];
  19. [_jipId, _shield] call CBA_fnc_removeGlobalEventJIP;
  20. }
  21. else
  22. {
  23. ["rd501_shield_normalHealth",[_shield, _type], _jipId] call CBA_fnc_globalEventJIP;
  24. [_jipId, _shield] call CBA_fnc_removeGlobalEventJIP;
  25. };
  26. };
  27. };
  28. if!(_isLowHealth) exitWith {
  29. if(_currentHealth < _threshold) then {
  30. diag_log "[RD501][Shield] Shield is now normal health, updating texture on clients";
  31. _shield setVariable["rd501_shield_isLowHealth", true];
  32. private _jipId = _shield getVariable ["rd501_shield_stateJipId", false];
  33. if(_jipId isEqualTo false) then {
  34. _jipId = ["rd501_shield_lowHealth",[_shield, _type]] call CBA_fnc_globalEventJIP;
  35. _shield setVariable ["rd501_shield_stateJipId", _jipId, true];
  36. [_jipId, _shield] call CBA_fnc_removeGlobalEventJIP;
  37. }
  38. else
  39. {
  40. ["rd501_shield_lowHealth",[_shield, _type], _jipId] call CBA_fnc_globalEventJIP;
  41. [_jipId, _shield] call CBA_fnc_removeGlobalEventJIP;
  42. };
  43. };
  44. };