Advertisement
iLogann

maintain_area.sqf

Jul 30th, 2014
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.73 KB | None | 0 0
  1. //Code developed by Axe Cop - Massiv improvments && performance tunes by Skaronator
  2. private ["_missing","_missingQty","_proceed","_itemIn","_countIn","_qty","_num_removed","_uniqueID","_removed","_removed_total","_tobe_removed_total","_obj","_objectID","_objectUID","_classname","_location","_dir","_objectCharacterID","_object","_temp_removed_array","_textMissing","_target","_objectClasses","_range","_objects","_requirements","_count","_cost","_itemText","_option"];
  3.  
  4. if (DZE_ActionInProgress) exitWith { cutText [(localize "STR_EPOCH_ACTIONS_2") , "PLAIN DOWN"]; };
  5. DZE_ActionInProgress = true;
  6.  
  7. player removeAction s_player_maintain_area;
  8. s_player_maintain_area = 1;
  9. player removeAction s_player_maintain_area_preview;
  10. s_player_maintain_area_preview = 1;
  11.  
  12. _target = cursorTarget; // Plastic_Pole_EP1_DZ
  13.  
  14. _objectClasses = DZE_maintainClasses;
  15. _range = DZE_maintainRange; // set the max range for the maintain area
  16. _objects = nearestObjects [_target, _objectClasses, _range];
  17.  
  18. //filter to only those that have 10% damage
  19. _objects_filtered = [];
  20. {
  21. if (damage _x >= DZE_DamageBeforeMaint) then {
  22. _objects_filtered set [count _objects_filtered, _x];
  23. };
  24. } count _objects;
  25. _objects = _objects_filtered;
  26.  
  27. // TODO dynamic requirements based on used building parts?
  28. _count = count _objects;
  29.  
  30. if (_count == 0) exitWith {
  31. cutText [format[(localize "STR_EPOCH_ACTIONS_22"), _count], "PLAIN DOWN"];
  32. DZE_ActionInProgress = false;
  33. s_player_maintain_area = -1;
  34. s_player_maintain_area_preview = -1;
  35. };
  36.  
  37. _requirements = [];
  38. switch true do {
  39. case (_count <= 15): {_requirements = []};
  40. case (_count <= 20): {_requirements = []};
  41. case (_count <= 25): {_requirements = []};
  42. case (_count <= 30): {_requirements = []};
  43. case (_count <= 40): {_requirements = []};
  44. case (_count <= 50): {_requirements = []};
  45. case (_count <= 75): {_requirements = []};
  46. case (_count <= 100): {_requirements = []};
  47. case (_count <= 125): {_requirements = []};
  48. case (_count <= 150): {_requirements = []};
  49. case (_count <= 200): {_requirements = []};
  50. case (_count <= 250): {_requirements = []};
  51. case (_count <= 300): {_requirements = []};
  52. case (_count > 350): {_requirements = []};
  53. };
  54.  
  55.  
  56.  
  57. _option = _this select 3;
  58. switch _option do {
  59. case "maintain": {
  60.  
  61. _missing = "";
  62. _missingQty = 0;
  63. _proceed = true;
  64. {
  65. _itemIn = _x select 0;
  66. _countIn = _x select 1;
  67. _qty = { (_x == _itemIn) || (configName(inheritsFrom(configFile >> "cfgMagazines" >> _x)) == _itemIn) } count magazines player;
  68. if (_qty < _countIn) exitWith { _missing = _itemIn; _missingQty = (_countIn - _qty); _proceed = false; };
  69. } count _requirements;
  70.  
  71. if (_proceed) then {
  72. player playActionNow "Medic";
  73. [player,_range,true,(getPosATL player)] spawn player_alertZombies;
  74.  
  75. _temp_removed_array = [];
  76. _removed_total = 0;
  77. _tobe_removed_total = 0;
  78.  
  79. {
  80. _removed = 0;
  81. _itemIn = _x select 0;
  82. _countIn = _x select 1;
  83. _tobe_removed_total = _tobe_removed_total + _countIn;
  84.  
  85. {
  86. if ((_removed < _countIn) && ((_x == _itemIn) || configName(inheritsFrom(configFile >> "cfgMagazines" >> _x)) == _itemIn)) then {
  87. _num_removed = ([player,_x] call BIS_fnc_invRemove);
  88. _removed = _removed + _num_removed;
  89. _removed_total = _removed_total + _num_removed;
  90. if (_num_removed >= 1) then {
  91. _temp_removed_array set [count _temp_removed_array,_x];
  92. };
  93. };
  94. } forEach magazines player;
  95. } forEach _requirements;
  96.  
  97. // all required items removed from player gear
  98. if (_tobe_removed_total == _removed_total) then {
  99. cutText [format[(localize "STR_EPOCH_ACTIONS_4"), _count], "PLAIN DOWN", 5];
  100. PVDZE_maintainArea = [player,1,_target];
  101. publicVariableServer "PVDZE_maintainArea";
  102. } else {
  103. {player addMagazine _x;} count _temp_removed_array;
  104. cutText [format[(localize "STR_EPOCH_ACTIONS_5"),_removed_total,_tobe_removed_total], "PLAIN DOWN"];
  105. };
  106. } else {
  107. _textMissing = getText(configFile >> "CfgMagazines" >> _missing >> "displayName");
  108. cutText [format[(localize "STR_EPOCH_ACTIONS_6"), _missingQty, _textMissing], "PLAIN DOWN"];
  109. };
  110. };
  111. case "preview": {
  112. _cost = "";
  113. {
  114. _itemIn = _x select 0;
  115. _countIn = _x select 1;
  116. _itemText = getText(configFile >> "CfgMagazines" >> _itemIn >> "displayName");
  117. if (_cost != "") then {
  118. _cost = _cost + " and ";
  119. };
  120. _cost = _cost + (str(_countIn) + " of " + _itemText);
  121. } count _requirements;
  122. cutText [format[(localize "STR_EPOCH_ACTIONS_7"), _count, _cost], "PLAIN DOWN"];
  123. };
  124. };
  125.  
  126. DZE_ActionInProgress = false;
  127. s_player_maintain_area = -1;
  128. s_player_maintain_area_preview = -1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement