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:
|
2015-04-12 23:27:21 +00:00
|
|
|
* 0: Unit <OBJECT>
|
|
|
|
* 1: Classname <STRING>
|
|
|
|
* 2: Container (uniform, vest, backpack) <STRING><OPTIONAL>
|
|
|
|
* 3: Magazine Ammo Count <NUMBER><OPTIONAL>
|
2015-04-01 16:48:46 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* Array:
|
|
|
|
* 0: Added to player (Bool)
|
|
|
|
* 1: weaponholder (OBJECT)
|
|
|
|
*
|
|
|
|
* Public: Yes
|
|
|
|
*/
|
2015-04-01 23:51:34 +00:00
|
|
|
//#define DEBUG_MODE_FULL
|
2015-04-01 16:48:46 +00:00
|
|
|
#include "script_component.hpp"
|
|
|
|
|
2015-05-14 18:02:42 +00:00
|
|
|
PARAMS_2(_unit,_classname);
|
2015-04-12 23:27:21 +00:00
|
|
|
DEFAULT_PARAM(2,_container,"");
|
|
|
|
DEFAULT_PARAM(3,_ammoCount,-1);
|
|
|
|
|
2015-05-14 22:12:40 +00:00
|
|
|
private ["_addedToPlayer", "_canAdd", "_type", "_pos"];
|
2015-04-01 17:20:24 +00:00
|
|
|
|
|
|
|
_canAdd = false;
|
2015-04-01 16:48:46 +00:00
|
|
|
_addedToPlayer = true;
|
|
|
|
|
2015-04-01 23:51:34 +00:00
|
|
|
_type = [_classname] call EFUNC(common,getItemType);
|
|
|
|
|
2015-04-12 23:27:21 +00:00
|
|
|
switch (_container) do {
|
|
|
|
case "vest": { _canAdd = _unit canAddItemToVest _classname; };
|
|
|
|
case "backpack": { _canAdd = _unit canAddItemToBackpack _classname; };
|
|
|
|
case "uniform": { _canAdd = _unit canAddItemToUniform _classname; };
|
|
|
|
default {_canAdd = _unit canAdd _classname;};
|
2015-04-01 17:20:24 +00:00
|
|
|
};
|
|
|
|
|
2015-04-01 23:51:34 +00:00
|
|
|
switch ((_type select 0)) do {
|
2015-04-01 16:48:46 +00:00
|
|
|
case "weapon": {
|
2015-04-01 17:20:24 +00:00
|
|
|
if (_canAdd) then {
|
2015-04-12 23:27:21 +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;
|
2015-04-03 22:26:27 +00:00
|
|
|
_pos = _unit modelToWorldVisual [0,1,0.05];
|
2015-04-01 16:48:46 +00:00
|
|
|
_unit = createVehicle ["WeaponHolder_Single_F",_pos,[],0,"NONE"];
|
|
|
|
_unit addWeaponCargoGlobal [_classname,1];
|
|
|
|
_unit setPosATL _pos;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
case "magazine": {
|
2015-04-12 23:27:21 +00:00
|
|
|
if (_ammoCount == -1) then {_ammoCount = getNumber (configFile >> "CfgMagazines" >> _classname >> "count");};
|
2015-04-01 17:20:24 +00:00
|
|
|
if (_canAdd) then {
|
2015-04-01 17:34:16 +00:00
|
|
|
switch (_container) do {
|
2015-04-12 23:27:21 +00:00
|
|
|
case "vest": { (vestContainer _unit) addMagazineCargoGlobal [_classname, _ammoCount]; };
|
|
|
|
case "backpack": { (backpackContainer _unit) addMagazineCargoGlobal [_classname, _ammoCount]; };
|
|
|
|
case "uniform": { (uniformContainer _unit) addMagazineCargoGlobal [_classname, _ammoCount]; };
|
|
|
|
default {_unit addMagazine [_classname, _ammoCount]; };
|
2015-04-01 17:34:38 +00:00
|
|
|
};
|
2015-04-01 16:48:46 +00:00
|
|
|
} else {
|
|
|
|
_addedToPlayer = false;
|
2015-04-03 22:26:27 +00:00
|
|
|
_pos = _unit modelToWorldVisual [0,1,0.05];
|
2015-04-01 16:48:46 +00:00
|
|
|
_unit = createVehicle ["WeaponHolder_Single_F",_pos,[],0,"NONE"];
|
2015-04-12 23:27:21 +00:00
|
|
|
_unit addMagazineCargoGlobal [_classname, _ammoCount];
|
2015-04-01 16:48:46 +00:00
|
|
|
_unit setPosATL _pos;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
case "item": {
|
2015-04-01 17:20:24 +00:00
|
|
|
if (_canAdd) then {
|
2015-04-12 23:27:21 +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;
|
2015-04-03 22:26:27 +00:00
|
|
|
_pos = _unit modelToWorldVisual [0,1,0.05];
|
2015-04-01 16:48:46 +00:00
|
|
|
_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]
|