Optional container variable for adding item to a specific container (vest/backpack/uniform)

This commit is contained in:
jaynus 2015-04-01 10:20:24 -07:00
parent e06e7a2a51
commit 46284622b3

View File

@ -7,6 +7,7 @@
* 0: Unit (OBJECT) * 0: Unit (OBJECT)
* 1: Classname (String) * 1: Classname (String)
* 2: Type (String) * 2: Type (String)
* 3: Container (String, Optional)
* *
* Return Value: * Return Value:
* Array: * Array:
@ -19,12 +20,32 @@
EXPLODE_3_PVT(_this,_unit,_classname,_type); EXPLODE_3_PVT(_this,_unit,_classname,_type);
private "_addedToPlayer"; private "_addedToPlayer";
private "_container";
private "_canAdd";
_canAdd = false;
_addedToPlayer = true; _addedToPlayer = true;
if((count _this) > 3) then {
_container = _this select 4;
} else {
_container = nil;
};
if(!isNil "_container" && _type != "weapon") then {
switch (_container) do {
case "vest": { _canAdd = _unit canAddItemToVest _classname; };
case "backpack": { _canAdd = _unit canAddItemToBackpack _classname; };
case "uniform": { _canAdd = _unit canAddItemToUniform _classname; };
};
} else {
_canAdd = _unit canAdd _classname;
};
switch (_type) do { switch (_type) do {
case "weapon": { case "weapon": {
if (!isClass(ConfigFile >> "CfgWeapons" >> _classname)) exitWith {}; if (!isClass(ConfigFile >> "CfgWeapons" >> _classname)) exitWith {};
if (_unit canAdd _classname) then { if (_canAdd) then {
_unit addWeaponGlobal _classname; _unit addWeaponGlobal _classname;
} else { } else {
_addedToPlayer = false; _addedToPlayer = false;
@ -36,7 +57,7 @@ switch (_type) do {
}; };
case "magazine": { case "magazine": {
if (!isClass(ConfigFile >> "CfgMagazines" >> _classname)) exitWith {}; if (!isClass(ConfigFile >> "CfgMagazines" >> _classname)) exitWith {};
if (_unit canAdd _classname) then { if (_canAdd) then {
_unit addMagazineGlobal _classname; _unit addMagazineGlobal _classname;
} else { } else {
_addedToPlayer = false; _addedToPlayer = false;
@ -48,7 +69,7 @@ switch (_type) do {
}; };
case "item": { case "item": {
if (!isClass(ConfigFile >> "CfgWeapons" >> _classname)) exitWith {}; if (!isClass(ConfigFile >> "CfgWeapons" >> _classname)) exitWith {};
if (_unit canAdd _classname) then { if (_canAdd) then {
_unit addItem _classname; _unit addItem _classname;
} else { } else {
_addedToPlayer = false; _addedToPlayer = false;