Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. /*
  2. Author: www.3commandobrigade.com
  3. Join an ammo belt
  4. Arguments:
  5. none
  6. Return Value:
  7. none
  8. */
  9.  
  10. /////////////////////////////////////////////////////////////////////////////////////////////
  11. // Main
  12. //////////////////////////////////////////////////////////////////////////////////////////
  13.  
  14. private["_handled", "_splittableBelts", "_ammoInBelts", "_subBelts", "_ammoCount", "_belt", "_beltID", "_replacementBeltID", "_beltsFound", "_deleteBelt", "_contents", "_holder", "_listOfWeaponHolders"];
  15.  
  16. _splittableBelts = getArray(configFile >> "UK3CB_BAF_AmmoBelts" >> "SplittableBelts");
  17. _subBelts = getArray(configFile >> "UK3CB_BAF_AmmoBelts" >> "SubBelts");
  18.  
  19. _handled = false;
  20. if (alive player) then {
  21. //diag_log format ["****** Joining an ammo belt"];
  22.  
  23. // reset counter
  24. _ammoInBelts = [];
  25. {_ammoInBelts pushBack 0;} forEach _splittableBelts;
  26.  
  27. // Search for magazine on the player
  28. {
  29. _belt = _x select 0;
  30. _beltID = (_subBelts find _belt);
  31. if (_beltID >= 0) then {
  32. // Check if this is the 1st belt found of this type
  33. _ammoCount = _ammoInBelts select _beltID;
  34. if (_ammoCount == 0) then {
  35. // Store the ammo count
  36. _ammoInBelts set [_beltID, (_x select 1)];
  37. } else {
  38. // 2nd belt found of this type
  39. _ammoCount = _ammoCount + (_x select 1);
  40.  
  41. // replace both belts
  42. player removeMagazine _belt;
  43. player removeMagazine _belt;
  44.  
  45. player addMagazine [(_splittableBelts select _beltID), _ammoCount];
  46. _handled = true;
  47. };
  48. };
  49. if (_handled) exitWith {};
  50. } forEach (magazinesAmmo player);
  51.  
  52. _holder = objNull;
  53. if (!_handled) then {
  54. //diag_log format ["****** Joining ammo belt on the ground"];
  55.  
  56. // reset counter
  57. _ammoInBelts = [];
  58. {_ammoInBelts pushBack 0;} forEach _splittableBelts;
  59.  
  60. // Locate magazines on the ground (within 2 metres)
  61. _listOfWeaponHolders = nearestObjects [getPosATL player, ["WeaponHolder", "GroundWeaponHolder"], 3];
  62. _replacementBeltID = -1;
  63. {
  64. _contents = magazinesAmmoCargo _x;
  65. {
  66. _belt = _x select 0;
  67. _beltID = (_subBelts find _belt);
  68. if (_beltID >= 0) then {
  69. // Check if this is the 1st belt found of this type
  70. _ammoCount = _ammoInBelts select _beltID;
  71. if (_ammoCount == 0) then {
  72. // Store the ammo count
  73. _ammoInBelts set [_beltID, (_x select 1)];
  74. } else {
  75. // 2nd belt found of this type
  76. _ammoCount = _ammoCount + (_x select 1);
  77. _replacementBeltID = _beltID;
  78. };
  79. };
  80. if (_replacementBeltID >= 0) exitWith {};
  81. } forEach _contents;
  82. if (_replacementBeltID >= 0) exitWith {};
  83. } forEach _listOfWeaponHolders;
  84.  
  85. // Replace magazines - Note has to be a two stage process, as the magazines may be in different weapon holders
  86. _beltsFound = 0;
  87. if (_replacementBeltID >= 0) then {
  88. {
  89. _deleteBelt = false;
  90. _contents = magazinesAmmoCargo _x;
  91. {
  92. if (_belt == (_x select 0)) then {
  93. if (_beltsFound == 0) then {
  94. _beltsFound = _beltsFound + 1;
  95. } else {
  96. _handled = true;
  97. };
  98. _contents deleteAt (_contents find _x);
  99. _deleteBelt = true;
  100. };
  101. if (_handled) exitWith {};
  102. } forEach magazinesAmmoCargo _x;
  103.  
  104. // Delete the magazine
  105. if (_deleteBelt) then {
  106. // Remove magazine from ground holder - Note only way to do this at present
  107. deleteVehicle _x;
  108.  
  109. // Create new holder and add both existing content and replacement belts
  110. _holder = createVehicle ["GroundWeaponHolder", getPosATL player, [], 0, "CAN_COLLIDE"];
  111. _holder setDir (random 360);
  112.  
  113. {_holder addMagazineAmmoCargo [(_x select 0), 1, (_x select 1)];} forEach _contents;
  114.  
  115. if (_handled) then {
  116. _holder addMagazineAmmoCargo [(_splittableBelts select _replacementBeltID), 1, _ammoCount];
  117. };
  118. };
  119. if (_handled) exitWith {};
  120. } forEach _listOfWeaponHolders;
  121. };
  122. };
  123.  
  124. if (_handled) then {
  125. if (!(isNull _holder)) then {
  126. player playAction "PutDown";
  127. };
  128. playSound "UK3CB_Adjust_Ammo_Belt";
  129. } else {
  130. hintSilent format ["Failed to join belts"];
  131. };
  132. };
  133. _handled
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement