Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Author: www.3commandobrigade.com
- Join an ammo belt
- Arguments:
- none
- Return Value:
- none
- */
- /////////////////////////////////////////////////////////////////////////////////////////////
- // Main
- //////////////////////////////////////////////////////////////////////////////////////////
- private["_handled", "_splittableBelts", "_ammoInBelts", "_subBelts", "_ammoCount", "_belt", "_beltID", "_replacementBeltID", "_beltsFound", "_deleteBelt", "_contents", "_holder", "_listOfWeaponHolders"];
- _splittableBelts = getArray(configFile >> "UK3CB_BAF_AmmoBelts" >> "SplittableBelts");
- _subBelts = getArray(configFile >> "UK3CB_BAF_AmmoBelts" >> "SubBelts");
- _handled = false;
- if (alive player) then {
- //diag_log format ["****** Joining an ammo belt"];
- // reset counter
- _ammoInBelts = [];
- {_ammoInBelts pushBack 0;} forEach _splittableBelts;
- // Search for magazine on the player
- {
- _belt = _x select 0;
- _beltID = (_subBelts find _belt);
- if (_beltID >= 0) then {
- // Check if this is the 1st belt found of this type
- _ammoCount = _ammoInBelts select _beltID;
- if (_ammoCount == 0) then {
- // Store the ammo count
- _ammoInBelts set [_beltID, (_x select 1)];
- } else {
- // 2nd belt found of this type
- _ammoCount = _ammoCount + (_x select 1);
- // replace both belts
- player removeMagazine _belt;
- player removeMagazine _belt;
- player addMagazine [(_splittableBelts select _beltID), _ammoCount];
- _handled = true;
- };
- };
- if (_handled) exitWith {};
- } forEach (magazinesAmmo player);
- _holder = objNull;
- if (!_handled) then {
- //diag_log format ["****** Joining ammo belt on the ground"];
- // reset counter
- _ammoInBelts = [];
- {_ammoInBelts pushBack 0;} forEach _splittableBelts;
- // Locate magazines on the ground (within 2 metres)
- _listOfWeaponHolders = nearestObjects [getPosATL player, ["WeaponHolder", "GroundWeaponHolder"], 3];
- _replacementBeltID = -1;
- {
- _contents = magazinesAmmoCargo _x;
- {
- _belt = _x select 0;
- _beltID = (_subBelts find _belt);
- if (_beltID >= 0) then {
- // Check if this is the 1st belt found of this type
- _ammoCount = _ammoInBelts select _beltID;
- if (_ammoCount == 0) then {
- // Store the ammo count
- _ammoInBelts set [_beltID, (_x select 1)];
- } else {
- // 2nd belt found of this type
- _ammoCount = _ammoCount + (_x select 1);
- _replacementBeltID = _beltID;
- };
- };
- if (_replacementBeltID >= 0) exitWith {};
- } forEach _contents;
- if (_replacementBeltID >= 0) exitWith {};
- } forEach _listOfWeaponHolders;
- // Replace magazines - Note has to be a two stage process, as the magazines may be in different weapon holders
- _beltsFound = 0;
- if (_replacementBeltID >= 0) then {
- {
- _deleteBelt = false;
- _contents = magazinesAmmoCargo _x;
- {
- if (_belt == (_x select 0)) then {
- if (_beltsFound == 0) then {
- _beltsFound = _beltsFound + 1;
- } else {
- _handled = true;
- };
- _contents deleteAt (_contents find _x);
- _deleteBelt = true;
- };
- if (_handled) exitWith {};
- } forEach magazinesAmmoCargo _x;
- // Delete the magazine
- if (_deleteBelt) then {
- // Remove magazine from ground holder - Note only way to do this at present
- deleteVehicle _x;
- // Create new holder and add both existing content and replacement belts
- _holder = createVehicle ["GroundWeaponHolder", getPosATL player, [], 0, "CAN_COLLIDE"];
- _holder setDir (random 360);
- {_holder addMagazineAmmoCargo [(_x select 0), 1, (_x select 1)];} forEach _contents;
- if (_handled) then {
- _holder addMagazineAmmoCargo [(_splittableBelts select _replacementBeltID), 1, _ammoCount];
- };
- };
- if (_handled) exitWith {};
- } forEach _listOfWeaponHolders;
- };
- };
- if (_handled) then {
- if (!(isNull _holder)) then {
- player playAction "PutDown";
- };
- playSound "UK3CB_Adjust_Ammo_Belt";
- } else {
- hintSilent format ["Failed to join belts"];
- };
- };
- _handled
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement