summaryrefslogtreecommitdiffstats
path: root/Client/Functions/Client_ReplaceInventoryAmmo.sqf
diff options
context:
space:
mode:
authorhybrid <hybrid@hybridlabs.pro>2026-06-11 19:38:09 +0300
committerhybrid <hybrid@hybridlabs.pro>2026-06-11 19:38:09 +0300
commita3a91d4f45b22fd487ecbc954ad979be5d03efdd (patch)
treea554ab159a347dcd6c00ca1c7c26c1ec3ac0a6bd /Client/Functions/Client_ReplaceInventoryAmmo.sqf
downloada2wf_chernarus-a3a91d4f45b22fd487ecbc954ad979be5d03efdd.tar.gz
a2wf_chernarus-a3a91d4f45b22fd487ecbc954ad979be5d03efdd.tar.bz2
a2wf_chernarus-a3a91d4f45b22fd487ecbc954ad979be5d03efdd.zip
Diffstat (limited to '')
-rw-r--r--Client/Functions/Client_ReplaceInventoryAmmo.sqf65
1 files changed, 65 insertions, 0 deletions
diff --git a/Client/Functions/Client_ReplaceInventoryAmmo.sqf b/Client/Functions/Client_ReplaceInventoryAmmo.sqf
new file mode 100644
index 0000000..810e4e2
--- /dev/null
+++ b/Client/Functions/Client_ReplaceInventoryAmmo.sqf
@@ -0,0 +1,65 @@
+Private ['_freeSpace','_futureSpace','_get','_limit','_magazines','_newMag','_newMagIsSide','_newMagSpace','_oldMags','_presentMags','_replacement','_rlIndex','_size','_spaceToReduce','_totalToReplace','_z'];
+_newMag = _this select 0;
+_oldMags = _this select 1;
+_magazines = _this select 2;
+
+_presentMags = [];
+_replacement = [];
+_size = 0;
+_spaceToReduce = 0;
+
+{
+ Private['_cmag','_ct'];
+ _cmag = _x;
+ _ct = {_x == _cmag} count _oldMags;
+
+ if (_ct > 0) then {
+ _get = _cmag Call GetNamespace;
+ _presentMags = _presentMags + [_cmag];
+ _spaceToReduce = _spaceToReduce + (_get select QUERYGEARSPACE);
+ };
+} forEach _magazines;
+
+if (_newMag == "") exitWith {_magazines - _presentMags};
+
+_get = _newMag Call GetNamespace;
+_newMagSpace = _get select QUERYGEARSPACE;
+_newMagIsSide = _get select QUERYGEARHANDGUNPOOL;
+_limit = if (_newMagIsSide) then {8} else {12};
+
+if (_newMagIsSide) then {
+ {
+ _get = _x Call GetNamespace;
+
+ if !(isNil '_get') then {
+ if (_get select QUERYGEARHANDGUNPOOL) then {
+ _size = _size + (_get select QUERYGEARSPACE);
+ };
+ };
+ } forEach _magazines;
+} else {
+ {
+ _get = _x Call GetNamespace;
+
+ if !(isNil '_get') then {
+ if !(_get select QUERYGEARHANDGUNPOOL) then {
+ _size = _size + (_get select QUERYGEARSPACE);
+ };
+ };
+ } forEach _magazines;
+};
+
+_totalToReplace = count _presentMags;
+_freeSpace = _size - _spaceToReduce;
+
+_futureSpace = _totalToReplace * _newMagSpace;
+while {(_futureSpace + _freeSpace) > _limit} do {
+ _totalToReplace = _totalToReplace - 1;
+ _futureSpace = _totalToReplace * _newMagSpace;
+};
+
+for [{_z = 0},{_z < _totalToReplace},{_z = _z + 1}] do {_replacement = _replacement + [_newMag]};
+
+_magazines = (_magazines - _presentMags) + _replacement;
+
+_magazines \ No newline at end of file