Skip to content

Commit

Permalink
use switch statement in fnc_useItem
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkIsGrim committed Mar 6, 2024
1 parent ee070a6 commit 8a0d64f
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions addons/medical_treatment/functions/fnc_useItem.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,27 @@ private _useOrder = [[_patient, _medic], [_medic, _patient], [_medic]] select GV
private _unitVehicle = objectParent _unit;
private _unitItems = [_x, 0] call EFUNC(common,uniqueItems);
private _unitMagazines = [_x, 2] call EFUNC(common,uniqueItems);
private _vehicleItems = itemCargo _unitVehicle; // [] for objNull
private _vehicleMagazines = magazineCargo _unitVehicle; // same

{
if (!isNull _unitVehicle) then {
if (_x in (itemCargo _unitVehicle)) then {
switch (true) do {
case (_x in _vehicleItems): {
_unitVehicle addItemCargoGlobal [_x, -1];
[_unit, _x] breakOut "Main";
};
if (_x in ((magazinesAmmoCargo _unitVehicle) apply { _x select 0 })) then {
case (_x in _vehicleMagazines): {
[_unitVehicle, _x] call EFUNC(common,adjustMagazineAmmo);
[_unit, _x] breakOut "Main";
};
};
if (_x in _unitItems) then {
_unit removeItem _x;
[_unit, _x] breakOut "Main";
};
if (_x in _unitMagazines) then {
[_unit, _x] call EFUNC(common,adjustMagazineAmmo);
[_unit, _x] breakOut "Main";
case (_x in _unitItems): {
_unit removeItem _x;
[_unit, _x] breakOut "Main";
};
case (_x in _unitMagazines): {
[_unit, _x] call EFUNC(common,adjustMagazineAmmo);
[_unit, _x] breakOut "Main";
};
};
} forEach _items;
} forEach _useOrder;
Expand Down

0 comments on commit 8a0d64f

Please sign in to comment.