fnc_bandageAllNearbyCCP.sqf 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Author: M3ales
  3. *
  4. * Arguments:
  5. * Healer
  6. * Origin To Search from
  7. * Radius To Search Around for People
  8. * Return Value:
  9. * Nothing
  10. *
  11. * Example:
  12. * [player, cursorTarget] call rd501_fnc_bandageAllNearbyCCP
  13. *
  14. * Public: No
  15. */
  16. params["_healer", "_origin", "_radius"];
  17. private _nearbyPatients = _origin nearEntities ["CAManBase", _radius] select {
  18. [_x] call rd501_fnc_checkInsideCCP &&
  19. {
  20. count (_x getVariable ["ace_medical_openWounds", []]) > 0
  21. }
  22. };
  23. private _args = [_healer, _nearbyPatients, _origin];
  24. if(count _nearbyPatients == 0) exitWith {
  25. ["Nobody to Bandage Inside CCP", true, 2, 0] call ace_common_fnc_displayText;
  26. };
  27. [format["Bandaging %1 Patient(s)", count _nearbyPatients], false, 10, 0] call ace_common_fnc_displayText;
  28. private _onFinish = {
  29. (_this select 0) params ["_player", "_patients", "_building"];
  30. {
  31. if([_x] call rd501_fnc_checkInsideCCP) then {
  32. [_player, _x] call rd501_fnc_bandageAllWounds;
  33. };
  34. } forEach (_patients);
  35. _building setVariable ["rd501_medical_ccp_bandageProgress", -1, true];
  36. _building setVariable["rd501_medical_ccp_bandageMembers", [], true];
  37. [_player, "", 1] call ace_common_fnc_doAnimation;
  38. };
  39. private _onFailure = {
  40. params["_args", "_progress", "_errorCode"];
  41. _args params["_healer","_nearbyPatients", "_building"];
  42. [_healer, "", 1] call ace_common_fnc_doAnimation;
  43. _bandagers = _building getVariable ["rd501_medical_ccp_bandageMembers", []];
  44. if(count _bandagers <= 1) then {
  45. _building setVariable ["rd501_medical_ccp_bandageProgress", -1, true];
  46. _building setVariable ["rd501_medical_ccp_bandageMembers", [], true];
  47. _building setVariable ["rd501_medical_ccp_bandageProgressComplete", 100];
  48. }
  49. else
  50. {
  51. _newArr = _bandagers deleteAt (_bandagers findIf { _x isEqualTo ([] call CBA_fnc_currentUnit)}) select 1;
  52. _building setVariable["rd501_medical_ccp_bandageMembers", _newArr, true];
  53. }
  54. };
  55. private _condition = {
  56. params["_args", "_progress", "_errorCode"];
  57. _args params["_healer","_nearbyPatients", "_building"];
  58. if(_progress == -1) exitWith {false};
  59. if(_healer getVariable ["ACE_Unconscious", false]) exitWith {false};
  60. alive _healer && alive _building
  61. };
  62. if(_origin getVariable ["rd501_medical_ccp_bandageProgress", -1] == -1) then {
  63. private _bandageDuration = ((count _nearbyPatients) * rd501_medical_ccp_bandageDurationSeconds);
  64. _origin setVariable ["rd501_medical_ccp_bandageProgress", 0, true];
  65. _origin setVariable ["rd501_medical_ccp_bandageMembers", [player], true];
  66. _origin setVariable ["rd501_medical_ccp_bandageProgressComplete", _bandageDuration, true];
  67. }
  68. else
  69. {
  70. _bandageMembers = _origin getVariable ["rd501_medical_ccp_bandageMembers", []];
  71. _bandageMembers append [player];
  72. _origin setVariable ["rd501_medical_ccp_bandageMembers", _bandageMembers, true];
  73. };
  74. [
  75. {
  76. params ["_args", "_handle"];
  77. _args params ["_healer", "_nearbyPatients", "_origin"];
  78. _progress = _origin getVariable ["rd501_medical_ccp_bandageProgress", -1];
  79. _progressComplete = _origin getVariable ["rd501_medical_ccp_bandageProgressComplete", 100];
  80. if(_progress < 0 || _progress >= _progressComplete) exitWith {
  81. [_handle] call CBA_fnc_removePerFrameHandler;
  82. };
  83. if!(_healer getVariable ["ACE_Unconscious", false]) exitWith {
  84. ["rd501_medical_ccp_incrementBandage",[_origin, _healer]] call CBA_fnc_serverEvent;
  85. };
  86. },
  87. 1,
  88. _args
  89. ] call CBA_fnc_addPerFrameHandler;
  90. [_healer, "AinvPknlMstpSnonWnonDr_medic5", 0] call ace_common_fnc_doAnimation;
  91. ["rd501_medical_ccp_bandageProgress", "rd501_medical_ccp_bandageProgressComplete", _origin, _args, _onFinish, _onFailure, "Bandaging All Patients Inside CCP", _condition] call rd501_fnc_valueProgressBar;