Files
Clarksons_Logi_Framework/functions/fn_materielAdd.sqf
T

47 lines
1.1 KiB
Plaintext
Raw Normal View History

/*
* Author: Clarky
*
*
*
*
*/
params ["_hq", "_amount", "_player"];
// Grab all HQ/Base/Depots
private _baseDetails = _hq getVariable "baseDetails";
private _depots = _baseDetails get "depots";
if (_depots isEqualTo []) exitWith {
[
"CLF_ShowMessage",
[
1,
0,
"No connected supply depots found."
],
_player
] call CBA_fnc_targetEvent;
// Return false;
false;
};
// Loop through and add materiel to the depots
// Might work on a better way to do this eventually (i.e prioritising specific depots depending on reasons)
{
// If the _amount is now at 0, exit the loop early
if (_amount <= 0) exitWith {};
// Get currently looped depot's materiel and draw down from it
private _depotMateriel = _x getVariable "currentMateriel";
private _depotMax = _x getVariable "maxMateriel";
private _freeSpace = _depotMax - _depotMateriel;
private _addAmount = _amount min _freeSpace;
_x setVariable ["currentMateriel", _depotMateriel + _addAmount, true];
// Update remaining amount to reduce
_amount = _amount - _addAmount;
} forEach _depots;
// Return true
true;