fnc_bandageAllNearbyCCP.sqf 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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, "AmovPknlMstpSrasWrflDnon", 1] call ace_common_fnc_doAnimation;
  43. _bandagers = _building getVariable ["rd501_medical_ccp_bandageMembers", []];
  44. systemChat format["_bandagers %1", _bandagers];
  45. if(count _bandagers <= 1) then {
  46. _building setVariable ["rd501_medical_ccp_bandageProgress", -1, true];
  47. _building setVariable["rd501_medical_ccp_bandageMembers", [], true];
  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. _origin setVariable ["rd501_medical_ccp_bandageProgress", 0, true];
  64. _origin setVariable ["rd501_medical_ccp_bandageMembers", [player], true];
  65. }
  66. else
  67. {
  68. _bandageMembers = _origin getVariable ["rd501_medical_ccp_bandageMembers", []];
  69. _bandageMembers append [player];
  70. _origin setVariable ["rd501_medical_ccp_bandageMembers", _bandageMembers, true];
  71. };
  72. [
  73. {
  74. params ["_args", "_handle"];
  75. _args params ["_healer", "_nearbyPatients", "_origin"];
  76. _progress = _origin getVariable ["rd501_medical_ccp_bandageProgress", -1];
  77. if(_progress > 100 || _progress < 0) exitWith {
  78. systemChat "EH Exit";
  79. [_handle] call CBA_fnc_removePerFrameHandler;
  80. };
  81. if!(_healer getVariable ["ACE_Unconscious", false]) exitWith {
  82. systemChat "EH Increment";
  83. [_origin, _healer] call rd501_fnc_incrementBandageProgress;
  84. };
  85. },
  86. 0.5,
  87. _args
  88. ] call CBA_fnc_addPerFrameHandler;
  89. [_healer, "AinvPknlMstpSnonWnonDr_medic5", 0] call ace_common_fnc_doAnimation;
  90. [_origin, _args, _onFinish, _onFailure, "Bandaging All Patients Inside CCP", _condition] call rd501_fnc_valueProgressBar;