Add better duplicated tool check

- Fix disappearing keys when the backpack was full
- Localize added tool
- Add message where the tool got dropped
- fnc_freeBackpackSlots handles also bigger inventory objects with more as one slot
This commit is contained in:
A Man
2022-05-02 09:45:48 +02:00
parent 16bf4375c7
commit 143db3e1ef
3 changed files with 60 additions and 11 deletions

View File

@@ -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;
};

View File

@@ -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

View File

@@ -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";};