ACE3/addons/common/functions/fnc_addToInventory.sqf

143 lines
4.5 KiB
Plaintext
Raw Normal View History

#include "script_component.hpp"
/*
* Author: Garth 'L-H' de Wet
2015-09-18 07:38:19 +00:00
* Adds an item, weapon, or magazine to the unit's inventory or places it in a weaponHolder if no space.
*
* Arguments:
* 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>
*
* Return Value:
2015-09-18 07:38:19 +00:00
* 0: Added to player <BOOL>
* 1: weaponholder <OBJECT>
*
* Example:
* [bob, "classname", "", 5] call ace_common_fnc_addToInventory
*
* Public: Yes
*/
2015-09-18 07:38:19 +00:00
params ["_unit", "_classname", ["_container", ""], ["_ammoCount", -1]];
private _type = _classname call FUNC(getItemType);
private _canAdd = false;
private _addedToUnit = false;
switch (_container) do {
2015-09-18 07:38:19 +00:00
case "vest": {
_canAdd = [_unit, _classname, 1, false, true, false] call CBA_fnc_canAddItem;
2015-09-18 07:38:19 +00:00
};
case "backpack": {
_canAdd = [_unit, _classname, 1, false, false, true] call CBA_fnc_canAddItem;
2015-09-18 07:38:19 +00:00
};
case "uniform": {
_canAdd = [_unit, _classname, 1, true, false, false] call CBA_fnc_canAddItem;
2015-09-18 07:38:19 +00:00
};
default {
_canAdd = [_unit, _classname] call CBA_fnc_canAddItem;
2015-09-18 07:38:19 +00:00
};
};
2015-09-18 07:38:19 +00:00
switch (_type select 0) do {
case "weapon": {
if (_canAdd) then {
2015-09-18 07:38:19 +00:00
_addedToUnit = true;
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 {
_unit addWeaponGlobal _classname;
};
2015-04-01 17:34:38 +00:00
};
} else {
2015-09-18 07:38:19 +00:00
_addedToUnit = false;
private _pos = _unit modelToWorldVisual [0,1,0.05];
2015-09-18 07:38:19 +00:00
_unit = createVehicle ["WeaponHolder_Single_F", _pos, [], 0, "NONE"];
_unit addWeaponCargoGlobal [_classname, 1];
_unit setPosATL _pos;
};
};
2015-09-18 07:38:19 +00:00
case "magazine": {
2015-09-18 07:38:19 +00:00
if (_ammoCount == -1) then {
_ammoCount = getNumber (configFile >> "CfgMagazines" >> _classname >> "count");
};
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": {
(vestContainer _unit) addMagazineCargoGlobal [_classname, 1/*_ammoCount*/]; //@todo Bug! This isn't really the ammo, but magazine count. No such command.
};
case "backpack": {
(backpackContainer _unit) addMagazineCargoGlobal [_classname, 1/*_ammoCount*/]; //@todo Bug! This isn't really the ammo, but magazine count. No such command.
};
case "uniform": {
(uniformContainer _unit) addMagazineCargoGlobal [_classname, 1/*_ammoCount*/]; //@todo Bug! This isn't really the ammo, but magazine count. No such command.
};
default {
_unit addMagazine [_classname, _ammoCount];
};
2015-04-01 17:34:38 +00:00
};
} else {
2015-09-18 07:38:19 +00:00
_addedToUnit = false;
private _pos = _unit modelToWorldVisual [0,1,0.05];
2015-09-18 07:38:19 +00:00
_unit = createVehicle ["WeaponHolder_Single_F", _pos, [], 0, "NONE"];
_unit addMagazineCargoGlobal [_classname, 1/*_ammoCount*/]; //@todo Bug! This isn't really the ammo, but magazine count. No such command.
_unit setPosATL _pos;
};
};
2015-09-18 07:38:19 +00:00
case "item": {
if (_canAdd) then {
2015-09-18 07:38:19 +00:00
_addedToUnit = true;
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
};
} else {
2015-09-18 07:38:19 +00:00
_addedToUnit = false;
private _pos = _unit modelToWorldVisual [0,1,0.05];
2015-09-18 07:38:19 +00:00
_unit = createVehicle ["WeaponHolder_Single_F", _pos, [], 0, "NONE"];
_unit addItemCargoGlobal [_classname, 1];
_unit setPosATL _pos;
};
};
2015-09-18 07:38:19 +00:00
default {
2015-09-18 07:38:19 +00:00
_addedToUnit = false;
WARNING_2("Incorrect item type passed to %1, passed: %2",QFUNC(AddToInventory),_type);
};
};
2015-09-18 07:38:19 +00:00
[_addedToUnit, _unit]