diff --git a/SQF/dayz_code/compile/fn_addDuplicateTool.sqf b/SQF/dayz_code/compile/fn_addDuplicateTool.sqf index 0d7a73dd1..402228982 100644 --- a/SQF/dayz_code/compile/fn_addDuplicateTool.sqf +++ b/SQF/dayz_code/compile/fn_addDuplicateTool.sqf @@ -12,25 +12,32 @@ _this: string - toolbelt item classname to check and add How to use: "ItemSledge" call player_addDuplicateTool; */ -private "_bag"; +local _tool = _this; +local _displayName = getText(configFile >> "CfgWeapons" >> _tool >> "displayName"); -if (_this in items player) then { - _bag = unitBackpack player; - if (!isNull _bag) then { - systemChat format[localize "str_epoch_player_313",_this]; - _bag addWeaponCargoGlobal [_this,1]; +if (_tool in items player) then { + local _bag = unitBackpack player; + if (!isNull _bag) then { + local _freeSlots = call fnc_freeBackpackSlots; + if (_freeSlots > 0) then { + systemChat format[localize "str_epoch_player_313",_displayName]; + _bag addWeaponCargoGlobal [_tool,1]; + } else { + [_tool,2,1] call fn_dropItem; + systemChat format[localize "str_actions_noroom",_displayName]; + }; } else { - [_this,2,1] call fn_dropItem; - systemChat format[localize "str_actions_noroom",_this]; + [_tool,2,1] call fn_dropItem; + systemChat format[localize "str_actions_noroom",_displayName]; }; } else { //Remove melee magazines (BIS_fnc_invAdd fix) false call dz_fn_meleeMagazines; - if !([player,_this] call BIS_fnc_invAdd) then { + if !([player,_tool] call BIS_fnc_invAdd) then { systemChat localize "str_epoch_player_107"; - [_this,2,1] call fn_dropItem; - systemChat format[localize "str_actions_noroom",_this]; + [_tool,2,1] call fn_dropItem; + systemChat format[localize "str_actions_noroom",_displayName]; }; true call dz_fn_meleeMagazines; }; \ No newline at end of file diff --git a/SQF/dayz_code/compile/fn_freeBackpackSlots.sqf b/SQF/dayz_code/compile/fn_freeBackpackSlots.sqf new file mode 100644 index 000000000..bde21ea09 --- /dev/null +++ b/SQF/dayz_code/compile/fn_freeBackpackSlots.sqf @@ -0,0 +1,41 @@ +local _bag = unitBackpack player; +local _freeSlots = 0; + +if (!isNull _bag) then { + local _type = typeOf _bag; + local _maxMagazinesBag = getNumber(configFile >> "CfgVehicles" >> _type >> "transportMaxMagazines"); + + if (_maxMagazinesBag < 1) exitwith {}; // Fail safe + + local _cargoMagazinesBag = getMagazineCargo _bag; + local _cargoWeaponsBag = getWeaponCargo _bag; + local _weaponsBag = getWeaponCargo _bag select 0; + local _magazinesBag = getMagazineCargo _bag select 0; + local _qtyMaxBag = 0; + + { + local _magazine = _x; + local _qtyMagazine = (_cargoMagazinesBag select 1) select _foreachIndex; + local _magazineInvType = getNumber(configFile >> "CfgMagazines" >> _magazine >> "type"); + if (_magazineInvType > 16) then {_magazineInvType = _magazineInvType/256}; + _qtyMaxBag = _qtyMaxBag + (_magazineInvType*_qtyMagazine); + } foreach _magazinesBag; + + { + local _weapon = _x; + local _qtyWeapon = (_cargoWeaponsBag select 1) select _foreachIndex; + local _weaponInvType = getNumber(configFile >> "CfgWeapons" >> _weapon >> "type"); + + call { + if (_weaponInvType == 1) exitwith {_qtyMaxBag = _qtyMaxBag + (10*_qtyWeapon);}; + if (_weaponInvType == 2) exitwith {_qtyMaxBag = _qtyMaxBag + (5*_qtyWeapon);}; + if (_weaponInvType in [256,4096]) exitwith {_qtyMaxBag = _qtyMaxBag + _qtyWeapon;}; + }; + } foreach _weaponsBag; + + if (_qtyMaxBag < _maxMagazinesBag) then { + _freeSlots = _maxMagazinesBag - _qtyMaxBag; + }; +}; + +_freeSlots \ No newline at end of file diff --git a/SQF/dayz_code/init/compiles.sqf b/SQF/dayz_code/init/compiles.sqf index 20a713a21..c3d748f29 100644 --- a/SQF/dayz_code/init/compiles.sqf +++ b/SQF/dayz_code/init/compiles.sqf @@ -195,6 +195,7 @@ if (!isDedicated) then { fnc_radioState = compile preprocessFileLineNumbers "\z\addons\dayz_code\actions\radioState.sqf"; // Toggle radio on and off fnc_localizeMessage = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_localizeMessage.sqf"; fnc_remoteMessage = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_remoteMessage.sqf"; + fnc_freeBackpackSlots = compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\fn_freeBackpackSlots.sqf"; fnc_apsiState = compile preprocessFileLineNumbers "\z\addons\dayz_code\actions\apsiState.sqf"; // Toggle APSI on and off if (DZE_EVR) then {call compile preprocessFileLineNumbers "\z\addons\dayz_code\compile\client_evr.sqf";};