Page MenuHomeFeedback Tracker

Inventory management via scripts needs more flexibility
Reviewed, WishlistPublic

Description

<b>EDIT: Look at SaMatra's comment below, his suggestion is much better.</b>

<u>Short</u>: Add new functions to access and remove inventory items by ID.

<u>Long</u>: As of right now, inventory items can only be managed by their class name, regardless of which container they are in (uniform, vest, backpack). This makes it very difficult to try managing individual items from a player's inventory.

For example, I am trying to make a selling system, so that players can sell things directly from their inventory in exchange for money usable in my custom mission. Let's say a player has a bunch 6.5mm STANAG mags spread out in his inventory, many of which are partially used.

Now, the player wants to give one of these mags that, for example, is located in his vest, and has 14 rounds out of 30 left. At the moment, the only functions to remove magazines from an unit's inventory are <i>removeMagazine</i> and its variants, which only accept class names. This also applies to item and weapon functions. As a result, we cannot remove an item based on its inventory location or ammo state; the current remove functions will simply remove the first one from the inventory, regardless of its location.

The solution to this, is to add a set of functions to manage inventory items with IDs. As evidenced by the output of the <i>magazinesDetail</i> function, inventory items already have IDs, so adding such functions shouldn't be hard.

Here are my suggestions:

<b>inventoryItems _unit</b>
Outputs an array of arrays in the format [<item name>, <item ID>, <item location>], similar to <i>magazinesAmmoFull</i>
Example output:
[
["FirstAidKit", 3, "Uniform"],
["16Rnd_9x21_Mag", 4, "Uniform"],
["30Rnd_556x45_Stanag", 14, "Vest"],
["30Rnd_556x45_Stanag", 17, "Vest"],
["acc_flashlight", 21, "Vest"],
["Medikit", 25, "Backpack"],
["SMG_01_F", 30, "Backpack"],
["30Rnd_45ACP_Mag_SMG_01", 34, "Backpack"],
]

<b>_unit removeInventoryItem _itemID</b>
Removes a specific item by its ID returned from the former function

<b>_unit inventoryWeaponItems _itemID</b>
Outputs an array corresponding to accessories attached to a weapon in the inventory and its loaded magazine(s), similar to <i>weaponsItems</i>
Example output:
[
"arifle_MX_GL_F",
"muzzle_snds_H",
"acc_pointer_IR",
"optic_Aco",
[

		"30Rnd_65x39_caseless_mag",
		30

],
[

		"1Rnd_HE_Grenade_shell",
		1

]
]

Also, the <b><i>magazinesAmmoFull</i></b> function should be modified to include the inventory ID of each magazine. Example output:
[
["30Rnd_65x39_caseless_mag",30,false,-1,"Uniform", 11],
["30Rnd_65x39_caseless_mag",30,false,-1,"Vest", 14],
["16Rnd_9x21_Mag",16,false,-1,"Vest", 15],
["SmokeShellGreen",1,true,0,"SmokeShellGreenMuzzle", 17],
["Chemlight_green",1,true,0,"ChemlightGreenMuzzle", 21],
["HandGrenade",1,true,0,"HandGrenadeMuzzle", 25],
["30Rnd_65x39_caseless_mag",30,true,1,"arifle_MX_ACO_pointer_F", -1], // -1 since it's loaded inside a weapon
["16Rnd_9x21_Mag",16,true,2,"hgun_P07_F", -1]
]

Sorry if this looks very technical, but it is mostly oriented at coders. In the end, it's all about having more flexibility.

Event Timeline

AgentRev edited Steps To Reproduce. (Show Details)Aug 15 2013, 5:38 AM
AgentRev edited Additional Information. (Show Details)
AgentRev set Category to Scripting.
AgentRev set Reproducibility to N/A.
AgentRev set Severity to None.
AgentRev set Resolution to Open.
AgentRev set Legacy ID to 172773982.May 7 2016, 4:02 PM

These are really useful suggestions, but I would recommend to organize it differently. First of all commands should operate with containers instead of units since now we have unitVest and unitUniform. Here is how I see it:

Items

<array> = getItemCargoDetails <vehicle>
with output in form of array of ids and item classes
[
[item_id, item_class],
[...more items...]
]

<vehicle> deleteItemCargoGlobal <item_id>

Weapons

<array> = getWeaponCargoDetails <vehicle>
with output in form of array which should contain weapon inventory id, weapon class name, array with attachments and their item_id (should be ordered in muzzle, flashlight and then optics order with empty array if no item is linked as weapon attachment), array with magazines loaded in muzzles where magazines also should have id in case we will need to delete magazine right from the weapon with deleteItemCargoGlobal command by calling it on same container where weapon is and specifying magazine id
[
[

		weapon_id,
		weapon_class,
		[
			[item_id, muzzle_class],
			[item_id, flashlight_class],
			[item_id, optics_class]
		],
		[
			[
				magazine_id,
				muzzle_loaded_magazine,
				muzzle_loaded_magazine_ammo_count,
			],
			[...more loaded mags for each muzzle, empty array if nothing is loaded...]
		]

],
[...more weapons...]
]

<vehicle> deleteWeaponCargoGlobal <weapon_id>

Magazines

<array> = getMagazineCargoDetails <vehicle>
with array output of magazine id, classname, ammo count and id of weapon where magazine is loaded into with -1 in case of magazine not being loaded anywhere
[
[

		magazine_id,
		magazine_class,
		magazine_ammo_count,
		magazine_loaded_into_weapon_id,

],
[...more magazines...]
]

<vehicle> deleteMagazineCargoGlobal <magazine_id>

Vehicles

If I understand how vehicles and their containers work, then in order to interact with vehicle weapons and magazines we will need a new scripting command to return turret container which we can later use with above commands.

<turret_container> = <vehicle> vehicleTurret <turretpath>

If vehicle weapons\magazines are setup in a different way and say are actually stored in vehicle container itself and not a special turret container then paths where weapons are installed should be returned with getWeaponCargoDetails output

@SaMatra : Those are great ideas, I didn't think about managing items for all vehicles instead of units only. I pointed your suggestion to japapatramtara in the related issue.

Thanks.

Few more notes: To stay with current naming scheme, deleteMagazineCargoGlobal should be called removeMagazineCargoGlobal (by analogy with removeMagazine, removeWeapon, etc. commands), same with suggested Weapon and Item commands.

Also if there are really item ids that we can operate with (eagerly waiting for review from japapatramtara), maybe we can introduce a command to move weapon\magazine\item from one container to another.

<new_id> = <source_vehicle> moveWeaponCargoGlobal [<destination_vehicle>, <weapon_id>];
<new_id> = <source_vehicle> moveMagazineCargoGlobal [<destination_vehicle>, <magazine_id>];
<new_id> = <source_vehicle> moveItemCargoGlobal [<destination_vehicle>, <item_id>];

Not sure if <new_id> is even needed since I don't know how inventories are setup and work internally in the game but it would be nice if these commands actually relocated weapons\items\magazines instead of deleting them from source vehicle and creating a copy in destination vehicle. Also i'm not sure about multiplayer locality aspects, but I would love to have these commands even if they would require both vehicles to be local.

Having all this will finally in history of Operation Flashpoint \ Armed Assault let us to fully manipulate inventories.

One other action that I don't think we can perform yet, but would be really nice to have, is directly manipulating the attachments and loaded magazines of weapons in containers. Through a bit of manipulation of the weaponsItems results we can get all important information about these weapons, but we can't set them as far as I'm aware. Following SaMatra's last few examples, something to the effect of:

<source_vehicle> addWeaponCargoItem [<weapon_id>, <attachment_name>];
<source_vehicle> removeWeaponCargoItem [<weapon_id>, <attachment_name>];
<source_vehicle> addWeaponCargoMagazine [<weapon_id>, [<magazine_name>, <ammo>]];
<source_vehicle> removeWeaponCargoMagazine [<weapon_id>, <magazine_name>];

Would be very handy. Fairly related to: http://feedback.arma3.com/view.php?id=4903

removeWeaponCargoItem and removeWeaponCargoMagazine are already included in deleteItemCargoGlobal and deleteMagazineCargoGlobal functionality. Also your addWeaponCargoMagazine has no muzzle specified where magazine should be added.

I see, bit of reading/interpreting error on my part. Regardless, I'm not 100% comfortable with the deleteItemCargoGlobal means of removing items as, while it may work, it doesn't really seem to lend itself to a nice opposite/means of adding attached items. That's why I was proposing the pair of functions handle it.

In the same vein, the deleteMagazineCargoGlobal method may work for removing the magazine loaded into a gun, but it doesn't seem to have a viable opposite to load a magazine. The closest I could think of is something to the effect of:

<source_vehicle> assignMagazineCargoGlobal [<magazine_id>, <weapon_id>, <muzzle_id>];

Which would try to load a magazine from the container into a weapon. So a fixed version of my suggestion would probably, look something like (Not sure if removing a magazine requires the muzzle or not):

<source_vehicle> addWeaponCargoMagazine [<weapon_id>, <muzzle_id>, [<magazine_name>, <ammo>]];
<source_vehicle> removeWeaponCargoMagazine [<weapon_id>, <magazine_name>];

The other minor deviation on my suggestion is how getMagazineCargoDetails works. In your suggestion, you're having it return all magazines stored in the inventory of the container, then magazines inside the weapons stored in the container. But the ids of loaded magazines are also returned in getWeaponCargoDetails, so I would recommend removing them from one of the commands. Intuitively, I like having getMagazineCargoDetails return only magazines in the cargo space itself, and loaded magazines included in getWeaponCargoDetails.

And on a new note, as japapatramtara is saying here, http://feedback.arma3.com/view.php?id=14576#c57339, he intends to make all commands usable on items also usable on magazines and weapons, so deleteMagazineCargoGlobal may not even be necessary. Same applies to the moveItemCargoGlobal commands as well.

Other than that, all of the commands you've suggested are great ideas that would be a godsend for many of my little projects.