Last active
August 29, 2015 13:56
-
-
Save cyrq/8891662 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
handleBackpack.sqf | |
Author: cyrq ([email protected]). | |
Made for DayZed: http://dayzed.eu | |
Thanks to Hympnomatic for the _getClass funtion: http://forums.bistudio.com/showthread.php?148285-From-display-name-to-classname&p=2583286&viewfull=1#post2583286 | |
You can use, modify and distribute this without any permissions. | |
Give credit where credit is due. | |
Description: Disables the left/right arrows in the INV UI on weapons (if highlighted) when the player | |
doesn't have the needed amount of free slots in his backpack. | |
*/ | |
disableSerialization; | |
_control = 105; | |
_leftArrow = 146; | |
_player = player; | |
if (vehicle player != player) then { | |
_player = vehicle player; | |
}; | |
_backpack = unitBackpack _player; | |
_backpackWeaponsMax = getNumber (configFile >> "CfgVehicles" >> (typeOf _backpack) >> "transportMaxWeapons"); | |
_backpackMagazinesMax = getNumber (configFile >> "CfgVehicles" >> (typeOf _backpack) >> "transportMaxMagazines"); | |
_countWeapons = { | |
_weapons = []; | |
_return = 0; | |
_weapons = (getWeaponCargo (unitBackpack player)) select 1; | |
{ _return = _return + _x } foreach _weapons; | |
_return; | |
}; | |
_countMagazines = { | |
_magazines = []; | |
_return = 0; | |
_magazines = (getMagazineCargo (unitBackpack player)) select 1; | |
{ _return = _return + _x } foreach _magazines; | |
_return; | |
}; | |
_countFreeSlots = { | |
_return = [(_backpackWeaponsMax - _weapons), (_backpackMagazinesMax - _magazines)]; | |
_return; | |
}; | |
_getClass = { | |
private["_this","_displayName","_default","_out","_cfgWeapons","_cfgMagazines"]; | |
_displayName = _this select 0; | |
_default = [_this, 1, "ERROR: Item not found"] call BIS_fnc_param; | |
_out = _default; | |
_cfgWeapons = configFile >> "CfgWeapons"; | |
_cfgMagazines = configFile >> "CfgMagazines"; | |
for "_i" from 0 to count (_cfgWeapons) - 1 do { | |
if ((isClass (_cfgWeapons select _i)) && {_displayName == getText(_cfgWeapons select _i >> "displayName")}) exitWith { | |
_out = configName (_cfgWeapons select _i); | |
}; | |
}; | |
if (_out != _default) exitWith {_out}; | |
for "_i" from 0 to count (_cfgMagazines) - 1 do { | |
if ((isClass (_cfgMagazines select _i)) && {_displayName == getText(_cfgMagazines select _i >> "displayName")}) exitWith { | |
_out = configName(_cfgMagazines select _i); | |
}; | |
}; | |
_out | |
}; | |
while {!(isNull (findDisplay 106))} do { | |
_weapons = [] call _countWeapons; | |
_magazines = [] call _countMagazines; | |
_freeSlots = [] call _countFreeSlots; | |
//diag_log format ["Freeslots : %1",_freeSlots]; | |
_freeMagazineSlots = _freeSlots select 1; | |
//diag_log format ["Freeslots Magazine : %1",_freeMagazineSlots]; | |
_freeWeaponSlots = _freeSlots select 0; | |
//diag_log format ["Freeslots Weapon Slots : %1",_freeWeaponSlots]; | |
sleep 0.1; | |
if ((_freeWeaponSlots < 1) OR (_freeMagazineSlots < 5)) then { | |
_selected = lbCurSel _control; | |
//diag_log format ["Selected : %1",_selected]; | |
_selectedText = lnbText [_control,[_selected,1]]; | |
//diag_log format ["Selected Text : %1",_selectedText]; | |
_itemClass = [_selectedText] call _getClass; | |
//diag_log format ["Item Class : %1",_itemClass]; | |
_isPistol = inheritsFrom (configFile >> "CfgWeapons" >> _itemClass); | |
if (_isPistol == "Pistol") then { | |
//diag_log format ["Item Class : %1 is a Pistol",_itemClass]; | |
}; | |
if ((isClass (configFile >> "CfgWeapons" >> _itemClass)) && | |
((getNumber (configFile >> "CfgWeapons" >> _itemClass >> "type") != 131072))) then { | |
ctrlEnable [_leftArrow, false]; | |
} else { | |
if (!(ctrlEnabled _leftArrow)) then { | |
ctrlEnable [_leftArrow, true]; | |
}; | |
}; | |
} else { | |
if (!(ctrlEnabled _leftArrow)) then { | |
ctrlEnable [_leftArrow, true]; | |
}; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment