2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2015-04-01 16:48:46 +00:00
|
|
|
/*
|
|
|
|
* Author: Garth 'L-H' de Wet
|
2024-04-02 21:07:45 +00:00
|
|
|
* Adds an item, weapon, or magazine to the unit's inventory or places it in a weapon holder if no space.
|
2015-04-01 16:48:46 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2015-04-12 23:27:21 +00:00
|
|
|
* 0: Unit <OBJECT>
|
|
|
|
* 1: Classname <STRING>
|
2015-09-18 07:38:19 +00:00
|
|
|
* 2: Container (uniform, vest, backpack) (default: "") <STRING>
|
|
|
|
* 3: Magazine Ammo Count (default: -1) <NUMBER>
|
2015-04-01 16:48:46 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
2015-09-18 07:38:19 +00:00
|
|
|
* 0: Added to player <BOOL>
|
2024-04-02 21:07:45 +00:00
|
|
|
* 1: Weapon holder item was placed in <OBJECT>
|
2015-04-01 16:48:46 +00:00
|
|
|
*
|
2017-06-08 13:31:51 +00:00
|
|
|
* Example:
|
2024-04-02 21:07:45 +00:00
|
|
|
* [player, "30Rnd_65x39_caseless_mag", "", 5] call ace_common_fnc_addToInventory
|
2017-06-08 13:31:51 +00:00
|
|
|
*
|
2015-04-01 16:48:46 +00:00
|
|
|
* Public: Yes
|
|
|
|
*/
|
|
|
|
|
2015-09-18 07:38:19 +00:00
|
|
|
params ["_unit", "_classname", ["_container", ""], ["_ammoCount", -1]];
|
2015-04-12 23:27:21 +00:00
|
|
|
|
2015-12-14 12:08:19 +00:00
|
|
|
private _type = _classname call FUNC(getItemType);
|
2015-04-01 17:20:24 +00:00
|
|
|
|
2017-10-10 14:39:59 +00:00
|
|
|
private _canAdd = false;
|
2021-07-23 20:35:52 +00:00
|
|
|
private _canFitWeaponSlot = false;
|
2017-10-10 14:39:59 +00:00
|
|
|
private _addedToUnit = false;
|
2024-04-02 21:07:45 +00:00
|
|
|
private _weaponHolder = _unit;
|
2015-04-01 23:51:34 +00:00
|
|
|
|
2015-04-12 23:27:21 +00:00
|
|
|
switch (_container) do {
|
2015-09-18 07:38:19 +00:00
|
|
|
case "vest": {
|
2021-02-27 16:26:12 +00:00
|
|
|
_canAdd = [_unit, _classname, 1, false, true, false] call CBA_fnc_canAddItem;
|
2015-09-18 07:38:19 +00:00
|
|
|
};
|
|
|
|
case "backpack": {
|
2021-02-27 16:26:12 +00:00
|
|
|
_canAdd = [_unit, _classname, 1, false, false, true] call CBA_fnc_canAddItem;
|
2015-09-18 07:38:19 +00:00
|
|
|
};
|
|
|
|
case "uniform": {
|
2021-02-27 16:26:12 +00:00
|
|
|
_canAdd = [_unit, _classname, 1, true, false, false] call CBA_fnc_canAddItem;
|
2015-09-18 07:38:19 +00:00
|
|
|
};
|
|
|
|
default {
|
2021-02-27 16:26:12 +00:00
|
|
|
_canAdd = [_unit, _classname] call CBA_fnc_canAddItem;
|
2021-07-23 20:35:52 +00:00
|
|
|
if (_canAdd) then {
|
|
|
|
switch (_type select 1) do {
|
|
|
|
case "primary": {
|
|
|
|
_canFitWeaponSlot = primaryWeapon _unit == "";
|
|
|
|
};
|
|
|
|
case "secondary": {
|
|
|
|
_canFitWeaponSlot = secondaryWeapon _unit == "";
|
|
|
|
};
|
|
|
|
case "handgun": {
|
|
|
|
_canFitWeaponSlot = handgunWeapon _unit == "";
|
|
|
|
};
|
|
|
|
case "binocular": {
|
|
|
|
_canFitWeaponSlot = binocular _unit == "";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2015-09-18 07:38:19 +00:00
|
|
|
};
|
2015-04-01 17:20:24 +00:00
|
|
|
};
|
|
|
|
|
2015-09-18 07:38:19 +00:00
|
|
|
switch (_type select 0) do {
|
2015-04-01 16:48:46 +00:00
|
|
|
case "weapon": {
|
2021-07-23 20:35:52 +00:00
|
|
|
if (_canAdd || {_canFitWeaponSlot}) then {
|
2015-09-18 07:38:19 +00:00
|
|
|
_addedToUnit = true;
|
|
|
|
|
2015-04-12 23:27:21 +00:00
|
|
|
switch (_container) do {
|
2015-09-18 07:38:19 +00:00
|
|
|
case "vest": {
|
|
|
|
(vestContainer _unit) addWeaponCargoGlobal [_classname, 1];
|
|
|
|
};
|
|
|
|
case "backpack": {
|
|
|
|
(backpackContainer _unit) addWeaponCargoGlobal [_classname, 1];
|
|
|
|
};
|
|
|
|
case "uniform": {
|
|
|
|
(uniformContainer _unit) addWeaponCargoGlobal [_classname, 1];
|
|
|
|
};
|
|
|
|
default {
|
2021-07-23 20:35:52 +00:00
|
|
|
if (_canFitWeaponSlot) then {
|
|
|
|
_unit addWeaponGlobal _classname;
|
|
|
|
} else {
|
|
|
|
{
|
|
|
|
_x params ["_parameters", "_container"];
|
|
|
|
|
|
|
|
if (_parameters call CBA_fnc_canAddItem) exitWith {
|
|
|
|
_container addWeaponCargoGlobal [_classname, 1]; // addWeaponGlobal will replace the weapon currently in a slot
|
|
|
|
};
|
|
|
|
} forEach [
|
|
|
|
[[_unit, _classname, 1, false, false, true], backpackContainer _unit],
|
|
|
|
[[_unit, _classname, 1, false, true, false], vestContainer _unit],
|
|
|
|
[[_unit, _classname, 1, true, false, false], uniformContainer _unit]
|
|
|
|
];
|
|
|
|
};
|
2015-09-18 07:38:19 +00:00
|
|
|
};
|
2015-04-01 17:34:38 +00:00
|
|
|
};
|
2015-04-01 16:48:46 +00:00
|
|
|
} else {
|
2015-09-18 07:38:19 +00:00
|
|
|
_addedToUnit = false;
|
|
|
|
|
2024-04-02 21:07:45 +00:00
|
|
|
_weaponHolder = nearestObject [_unit, "WeaponHolder"];
|
2015-09-18 07:38:19 +00:00
|
|
|
|
2024-04-02 21:07:45 +00:00
|
|
|
if (isNull _weaponHolder || {_unit distance _weaponHolder > 2}) then {
|
|
|
|
_weaponHolder = createVehicle ["GroundWeaponHolder", _unit, [], 0, "CAN_COLLIDE"];
|
|
|
|
};
|
|
|
|
|
|
|
|
_weaponHolder addWeaponCargoGlobal [_classname, 1];
|
2015-04-01 16:48:46 +00:00
|
|
|
};
|
|
|
|
};
|
2015-09-18 07:38:19 +00:00
|
|
|
|
2015-04-01 16:48:46 +00:00
|
|
|
case "magazine": {
|
2015-09-18 07:38:19 +00:00
|
|
|
if (_ammoCount == -1) then {
|
|
|
|
_ammoCount = getNumber (configFile >> "CfgMagazines" >> _classname >> "count");
|
|
|
|
};
|
|
|
|
|
2015-04-01 17:20:24 +00:00
|
|
|
if (_canAdd) then {
|
2015-09-18 07:38:19 +00:00
|
|
|
_addedToUnit = true;
|
|
|
|
|
2015-04-01 17:34:16 +00:00
|
|
|
switch (_container) do {
|
2015-09-18 07:38:19 +00:00
|
|
|
case "vest": {
|
2024-03-04 22:00:31 +00:00
|
|
|
(vestContainer _unit) addMagazineAmmoCargo [_classname, 1, _ammoCount];
|
2015-09-18 07:38:19 +00:00
|
|
|
};
|
|
|
|
case "backpack": {
|
2024-03-04 22:00:31 +00:00
|
|
|
(backpackContainer _unit) addMagazineAmmoCargo [_classname, 1, _ammoCount];
|
2015-09-18 07:38:19 +00:00
|
|
|
};
|
|
|
|
case "uniform": {
|
2024-03-04 22:00:31 +00:00
|
|
|
(uniformContainer _unit) addMagazineAmmoCargo [_classname, 1, _ammoCount];
|
2015-09-18 07:38:19 +00:00
|
|
|
};
|
|
|
|
default {
|
|
|
|
_unit addMagazine [_classname, _ammoCount];
|
|
|
|
};
|
2015-04-01 17:34:38 +00:00
|
|
|
};
|
2015-04-01 16:48:46 +00:00
|
|
|
} else {
|
2015-09-18 07:38:19 +00:00
|
|
|
_addedToUnit = false;
|
|
|
|
|
2024-04-02 21:07:45 +00:00
|
|
|
_weaponHolder = nearestObject [_unit, "WeaponHolder"];
|
|
|
|
|
|
|
|
if (isNull _weaponHolder || {_unit distance _weaponHolder > 2}) then {
|
|
|
|
_weaponHolder = createVehicle ["GroundWeaponHolder", _unit, [], 0, "CAN_COLLIDE"];
|
|
|
|
};
|
2015-09-18 07:38:19 +00:00
|
|
|
|
2024-04-02 21:07:45 +00:00
|
|
|
_weaponHolder addMagazineAmmoCargo [_classname, 1, _ammoCount];
|
2015-04-01 16:48:46 +00:00
|
|
|
};
|
|
|
|
};
|
2015-09-18 07:38:19 +00:00
|
|
|
|
2015-04-01 16:48:46 +00:00
|
|
|
case "item": {
|
2015-04-01 17:20:24 +00:00
|
|
|
if (_canAdd) then {
|
2015-09-18 07:38:19 +00:00
|
|
|
_addedToUnit = true;
|
|
|
|
|
2015-04-12 23:27:21 +00:00
|
|
|
switch (_container) do {
|
2015-09-18 07:38:19 +00:00
|
|
|
case "vest": {
|
|
|
|
_unit addItemToVest _classname;
|
|
|
|
};
|
|
|
|
case "backpack": {
|
|
|
|
_unit addItemToBackpack _classname;
|
|
|
|
};
|
|
|
|
case "uniform": {
|
|
|
|
_unit addItemToUniform _classname;
|
|
|
|
};
|
|
|
|
default {
|
|
|
|
_unit addItem _classname;
|
|
|
|
};
|
2015-04-01 17:34:38 +00:00
|
|
|
};
|
2015-04-01 16:48:46 +00:00
|
|
|
} else {
|
2015-09-18 07:38:19 +00:00
|
|
|
_addedToUnit = false;
|
|
|
|
|
2024-04-02 21:07:45 +00:00
|
|
|
_weaponHolder = nearestObject [_unit, "WeaponHolder"];
|
|
|
|
|
|
|
|
if (isNull _weaponHolder || {_unit distance _weaponHolder > 2}) then {
|
|
|
|
_weaponHolder = createVehicle ["GroundWeaponHolder", _unit, [], 0, "CAN_COLLIDE"];
|
|
|
|
};
|
2015-09-18 07:38:19 +00:00
|
|
|
|
2024-04-02 21:07:45 +00:00
|
|
|
_weaponHolder addItemCargoGlobal [_classname, 1];
|
2015-04-01 16:48:46 +00:00
|
|
|
};
|
|
|
|
};
|
2015-09-18 07:38:19 +00:00
|
|
|
|
2015-08-26 13:20:11 +00:00
|
|
|
default {
|
2015-09-18 07:38:19 +00:00
|
|
|
_addedToUnit = false;
|
2016-10-02 10:55:31 +00:00
|
|
|
WARNING_2("Incorrect item type passed to %1, passed: %2",QFUNC(AddToInventory),_type);
|
2015-08-26 13:20:11 +00:00
|
|
|
};
|
2015-04-01 16:48:46 +00:00
|
|
|
};
|
|
|
|
|
2024-04-02 21:07:45 +00:00
|
|
|
[_addedToUnit, _weaponHolder]
|