mirror of
https://github.com/EpochModTeam/DayZ-Epoch.git
synced 2025-12-13 19:52:38 +03:00
- Added proper handling of pistol mags and regular mags in gear to prevent magazine overflow - Added pre-check if return change will overflow gear + backpack free space. If change will not fit in gear + backpack free space then buy is prevented with a message notifying the player. In the case of a sale it proceeds anyway, but notifies player if overflow occurs (see comments in returnChange) - Consolidated duplicate code for calculating free space and returning cargo of an object into new calcFreeSpace - Old calculateFreeSpace renamed to displayFreeSpace - Added Weps/Mags/Bags icons to free slot numbers display
85 lines
3.0 KiB
Plaintext
85 lines
3.0 KiB
Plaintext
private ["_object","_mags","_weaps","_normalMags","_normalWeaps","_kinds","_kinds2","_kinds3","_amounts","_amounts2","_amounts3",
|
|
"_counter","_allowedMags","_allowedWeapons","_allowedBackpacks","_currentPrim","_currentSec","_currentTool",
|
|
"_parentClasses","_alreadyInBackpack","_totalNewSpace","_primaryToBuy","_sidearmToBuy","_toolsToBuy",
|
|
"_toBuyTotalMags","_totalSpace","_bags","_totalBagSlots"];
|
|
|
|
_object = _this select 0;
|
|
_primaryToBuy = _this select 1; // Only needed if backpack
|
|
_sidearmToBuy = _this select 2; // Only needed if backpack
|
|
_toolsToBuy = _this select 3; // Only needed if backpack
|
|
_toBuyTotalMags = _this select 4; // Only needed if backpack
|
|
|
|
_allowedMags = 0;
|
|
_allowedWeapons = 0;
|
|
_allowedBackpacks = 0;
|
|
_totalSpace = 0;
|
|
_totalNewSpace = 0;
|
|
_totalBagSlots = 0;
|
|
_mags = getMagazineCargo _object;
|
|
_weaps = getWeaponCargo _object;
|
|
_bags = getBackpackCargo _object;
|
|
_normalMags = [];
|
|
_normalWeaps = [];
|
|
_normalBags = [];
|
|
|
|
_kinds = _mags select 0;
|
|
_amounts = _mags select 1;
|
|
{
|
|
_counter = 0;
|
|
while {_counter < (_amounts select _forEachIndex)} do {
|
|
_normalMags set [count _normalMags, _x];
|
|
_counter = _counter + 1;
|
|
};
|
|
} forEach _kinds;
|
|
|
|
_kinds2 = _weaps select 0;
|
|
_amounts2 = _weaps select 1;
|
|
{
|
|
_counter = 0;
|
|
while {_counter < (_amounts2 select _forEachIndex)} do {
|
|
_normalWeaps set [count _normalWeaps, _x];
|
|
_counter = _counter + 1;
|
|
};
|
|
} forEach _kinds2;
|
|
|
|
_kinds3 = _bags select 0;
|
|
_amounts3 = _bags select 1;
|
|
{
|
|
_counter = 0;
|
|
while {_counter < (_amounts3 select _forEachIndex)} do {
|
|
_normalBags set [count _normalBags, _x];
|
|
_counter = _counter + 1;
|
|
};
|
|
} forEach _kinds3;
|
|
|
|
_allowedMags = getNumber (configFile >> "CfgVehicles" >> (typeOf _object) >> "transportMaxMagazines") - count(_normalMags);
|
|
_allowedWeapons = getNumber (configFile >> "CfgVehicles" >> (typeOf _object) >> "transportMaxWeapons") - count(_normalWeaps);
|
|
_allowedBackpacks = getNumber (configFile >> "CfgVehicles" >> (typeOf _object) >> "transportMaxBackpacks") - count(_normalBags);
|
|
|
|
if (_object isKindOf "Bag_Base_EP1") then {
|
|
// Different weapon types take up different amounts of space in backpacks, but not vehicles
|
|
_currentPrim = 0;
|
|
_currentSec = 0;
|
|
_currentTool = 0;
|
|
{
|
|
_parentClasses = [(configFile >> "CfgWeapons" >> _x),true] call BIS_fnc_returnParents;
|
|
if ("ItemCore" in _parentClasses || "Binocular" in _parentClasses) then {
|
|
_currentTool = _currentTool + 1;
|
|
} else {
|
|
if ("PistolCore" in _parentClasses) then {
|
|
_currentSec = _currentSec + 1;
|
|
} else {
|
|
_currentPrim = _currentPrim + 1;
|
|
};
|
|
};
|
|
} count _normalWeaps;
|
|
|
|
//transportMaxMagazines is the same as total number of 1x slots in backpack
|
|
_totalBagSlots = getNumber (configFile >> "CfgVehicles" >> (typeOf _backpack) >> "transportMaxMagazines");
|
|
|
|
_alreadyInBackpack = (10 * _currentPrim) + (5 * _currentSec) + _currentTool + count(_normalMags);
|
|
_totalNewSpace = 10 * _primaryToBuy + 5 * _sidearmToBuy + _toolsToBuy + _toBuyTotalMags;
|
|
_totalSpace = _alreadyInBackpack + _totalNewSpace;
|
|
};
|
|
|
|
[_totalSpace,_allowedMags,_allowedWeapons,_allowedBackpacks,_totalBagSlots,_normalMags,_normalWeaps,_normalBags] |