2015-04-01 16:48:46 +00:00
|
|
|
/*
|
|
|
|
* Author: Garth 'L-H' de Wet
|
|
|
|
* Adds an item,weapon,magazine to the unit's inventory
|
|
|
|
* or places it in a weaponHolder if no space.
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Unit (OBJECT)
|
|
|
|
* 1: Classname (String)
|
|
|
|
* 2: Type (String)
|
2015-04-01 17:20:24 +00:00
|
|
|
* 3: Container (String, Optional)
|
2015-04-01 16:48:46 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* Array:
|
|
|
|
* 0: Added to player (Bool)
|
|
|
|
* 1: weaponholder (OBJECT)
|
|
|
|
*
|
|
|
|
* Public: Yes
|
|
|
|
*/
|
|
|
|
#include "script_component.hpp"
|
|
|
|
|
|
|
|
EXPLODE_3_PVT(_this,_unit,_classname,_type);
|
|
|
|
private "_addedToPlayer";
|
2015-04-01 17:20:24 +00:00
|
|
|
private "_container";
|
|
|
|
private "_canAdd";
|
|
|
|
|
|
|
|
_canAdd = false;
|
2015-04-01 16:48:46 +00:00
|
|
|
_addedToPlayer = true;
|
|
|
|
|
2015-04-01 17:20:24 +00:00
|
|
|
if((count _this) > 3) then {
|
2015-04-01 17:22:27 +00:00
|
|
|
_container = _this select 3;
|
2015-04-01 17:20:24 +00:00
|
|
|
} else {
|
2015-04-01 17:22:27 +00:00
|
|
|
_container = nil;
|
2015-04-01 17:20:24 +00:00
|
|
|
};
|
|
|
|
|
2015-04-01 17:35:22 +00:00
|
|
|
if(!isNil "_container") then {
|
2015-04-01 17:22:27 +00:00
|
|
|
switch (_container) do {
|
|
|
|
case "vest": { _canAdd = _unit canAddItemToVest _classname; };
|
|
|
|
case "backpack": { _canAdd = _unit canAddItemToBackpack _classname; };
|
|
|
|
case "uniform": { _canAdd = _unit canAddItemToUniform _classname; };
|
|
|
|
};
|
2015-04-01 17:20:24 +00:00
|
|
|
} else {
|
2015-04-01 17:22:27 +00:00
|
|
|
_canAdd = _unit canAdd _classname;
|
2015-04-01 17:20:24 +00:00
|
|
|
};
|
|
|
|
|
2015-04-01 16:48:46 +00:00
|
|
|
switch (_type) do {
|
|
|
|
case "weapon": {
|
|
|
|
if (!isClass(ConfigFile >> "CfgWeapons" >> _classname)) exitWith {};
|
2015-04-01 17:20:24 +00:00
|
|
|
if (_canAdd) then {
|
2015-04-01 17:34:16 +00:00
|
|
|
switch (_container) do {
|
2015-04-01 17:34:38 +00:00
|
|
|
case "vest": { (vestContainer _unit) addWeaponCargoGlobal [_classname, 1]; };
|
|
|
|
case "backpack": { (backpackContainer _unit) addWeaponCargoGlobal [_classname, 1]; };
|
|
|
|
case "uniform": { (uniformContainer _unit) addWeaponCargoGlobal [_classname, 1]; };
|
|
|
|
default { _unit addWeaponGlobal _classname; };
|
|
|
|
};
|
2015-04-01 16:48:46 +00:00
|
|
|
} else {
|
|
|
|
_addedToPlayer = false;
|
|
|
|
_pos = _unit modelToWorld [0,1,0.05];
|
|
|
|
_unit = createVehicle ["WeaponHolder_Single_F",_pos,[],0,"NONE"];
|
|
|
|
_unit addWeaponCargoGlobal [_classname,1];
|
|
|
|
_unit setPosATL _pos;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
case "magazine": {
|
|
|
|
if (!isClass(ConfigFile >> "CfgMagazines" >> _classname)) exitWith {};
|
2015-04-01 17:20:24 +00:00
|
|
|
if (_canAdd) then {
|
2015-04-01 17:34:16 +00:00
|
|
|
switch (_container) do {
|
2015-04-01 17:34:38 +00:00
|
|
|
case "vest": { (vestContainer _unit) addMagazineCargoGlobal [_classname, 1]; };
|
|
|
|
case "backpack": { (backpackContainer _unit) addMagazineCargoGlobal [_classname, 1]; };
|
|
|
|
case "uniform": { (uniformContainer _unit) addMagazineCargoGlobal [_classname, 1]; };
|
|
|
|
default { _unit addMagazineGlobal _classname; };
|
|
|
|
};
|
2015-04-01 16:48:46 +00:00
|
|
|
} else {
|
|
|
|
_addedToPlayer = false;
|
|
|
|
_pos = _unit modelToWorld [0,1,0.05];
|
|
|
|
_unit = createVehicle ["WeaponHolder_Single_F",_pos,[],0,"NONE"];
|
|
|
|
_unit addMagazineCargoGlobal [_classname, 1];
|
|
|
|
_unit setPosATL _pos;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
case "item": {
|
|
|
|
if (!isClass(ConfigFile >> "CfgWeapons" >> _classname)) exitWith {};
|
2015-04-01 17:20:24 +00:00
|
|
|
if (_canAdd) then {
|
2015-04-01 17:34:16 +00:00
|
|
|
switch (_container) do {
|
2015-04-01 17:34:38 +00:00
|
|
|
case "vest": { _unit addItemToVest _classname; };
|
|
|
|
case "backpack": { _unit addItemToBackpack _classname; };
|
|
|
|
case "uniform": { _unit addItemToUniform _classname; };
|
|
|
|
default { _unit addItem _classname; };
|
|
|
|
};
|
2015-04-01 16:48:46 +00:00
|
|
|
} else {
|
|
|
|
_addedToPlayer = false;
|
|
|
|
_pos = _unit modelToWorld [0,1,0.05];
|
|
|
|
_unit = createVehicle ["WeaponHolder_Single_F",_pos,[],0,"NONE"];
|
|
|
|
_unit addItemCargoGlobal [_classname,1];
|
|
|
|
_unit setPosATL _pos;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
default {diag_log format ["ACE: Incorrect item type passed to %1, passed: %2",QFUNC(AddToInventory),_type];};
|
|
|
|
};
|
|
|
|
|
|
|
|
[_addedToPlayer,_unit]
|