fnc_stitchAllWoundsNearbyCCP.sqf 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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_stitchAllNearbyCCP
  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_bandagedWounds", []]) > 0
  21. }
  22. };
  23. private _args = [_healer, _nearbyPatients, _origin];
  24. if(count _nearbyPatients == 0) exitWith {
  25. ["Nobody to Stitch Inside CCP", true, 2, 0] call ace_common_fnc_displayText;
  26. };
  27. [format["Stitching %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_stitchAllWounds;
  33. };
  34. } forEach (_patients);
  35. _building setVariable ["rd501_medical_ccp_stitchProgress", -1, true];
  36. _building setVariable["rd501_medical_ccp_stitchMembers", [], 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, "AmovPknlMstpSrasWrflDnon", 1] call ace_common_fnc_doAnimation;
  43. _stitchers = _building getVariable ["rd501_medical_ccp_stitchMembers", []];
  44. diag_log format["_stitchers %1", _stitchers];
  45. if(count _stitchers <= 1) then {
  46. _building setVariable ["rd501_medical_ccp_stitchProgress", -1, true];
  47. _building setVariable["rd501_medical_ccp_stitchMembers", [], true];
  48. _progressComplete = _building setVariable ["rd501_medical_ccp_stitchProgressComplete", 100];
  49. }
  50. else
  51. {
  52. _newArr = _stitchers deleteAt (_stitchers findIf { _x isEqualTo ([] call CBA_fnc_currentUnit)}) select 1;
  53. _building setVariable["rd501_medical_ccp_stitchMembers", _newArr, true];
  54. }
  55. };
  56. private _condition = {
  57. params["_args", "_progress", "_errorCode"];
  58. _args params["_healer","_nearbyPatients", "_building"];
  59. if(_progress == -1) exitWith {false};
  60. if(_healer getVariable ["ACE_Unconscious", false]) exitWith {false};
  61. alive _healer && alive _building
  62. };
  63. if(_origin getVariable ["rd501_medical_ccp_stitchProgress", -1] == -1) then {
  64. private _stitchDuration = ((count _nearbyPatients) * rd501_medical_ccp_stitchDurationSeconds);
  65. _origin setVariable ["rd501_medical_ccp_stitchProgress", 0, true];
  66. _origin setVariable ["rd501_medical_ccp_stitchMembers", [player], true];
  67. _origin setVariable ["rd501_medical_ccp_stitchProgressComplete", _stitchDuration, true];
  68. }
  69. else
  70. {
  71. _stitchMembers = _origin getVariable ["rd501_medical_ccp_stitchMembers", []];
  72. _stitchMembers append [player];
  73. _origin setVariable ["rd501_medical_ccp_stitchMembers", _stitchMembers, true];
  74. };
  75. [
  76. {
  77. params ["_args", "_handle"];
  78. _args params ["_healer", "_nearbyPatients", "_origin"];
  79. _progress = _origin getVariable ["rd501_medical_ccp_stitchProgress", -1];
  80. _progressComplete = _origin getVariable ["rd501_medical_ccp_stitchProgressComplete", 100];
  81. if(_progress >= _progressComplete || _progress < 0) exitWith {
  82. [_handle] call CBA_fnc_removePerFrameHandler;
  83. };
  84. if!(_healer getVariable ["ACE_Unconscious", false]) exitWith {
  85. ["rd501_medical_ccp_incrementStitch",[_origin, _healer]] call CBA_fnc_serverEvent;
  86. };
  87. },
  88. 0.5,
  89. _args
  90. ] call CBA_fnc_addPerFrameHandler;
  91. [_healer, "AinvPknlMstpSnonWnonDr_medic5", 0] call ace_common_fnc_doAnimation;
  92. ["rd501_medical_ccp_stitchProgress", "rd501_medical_ccp_stitchProgressComplete",_origin, _args, _onFinish, _onFailure, "Stitching All Patients Inside CCP", _condition] call rd501_fnc_valueProgressBar;