You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently found out that there are no such functions/commands in Arma yet, so I wrote these generic functions for getting and setting vehicle cargo inventory, such as the content of an ammo box. I think these would fit CBA well. I didn't make a PR because I don't know the conventions of the CBA project.
Details
They can perfectly represent the state of a vehicle inventory, including
non-full magazines with ammo count
weapons with attachments
backpacks/vests/uniforms with contents
backpacks/vests/uniforms containing weapons with attachments and non-full magazines
Their function closely resembles Arma commands getUnitLoadout and setUnitLoadout which are meant for unit inventory management.
The format of the inventory array closely resembles the one used in getUnitLoadout and setUnitLoadout.
fnc_getCargo and fnc_setCargo are both recursive, they are recursively called for any subcontainers (so backpacks, vests...) in the inventory.
Inventory format
Inventory is represented as an array containing the the following types of items:
fnc_getCargo = {
private_container=_this;
// Add magazines in form ["abc", 30]private_content=magazinesAmmoCargo_container;
// Add weapons in form ["abc", "", "", "", ["mag", 30], [], ""]_contentappend (weaponsItemsCargo_container);
// Add containers (backpacks, vests, uniforms) in form ["abc", [container content...]]// This function is called recursively to get subcontainer content.private_subContainers=everyContainer_container;
_contentappend (_subContainersapply {[_x # 0, (_x # 1call fnc_getCargo)]});
// Add other items in form "abc", excluding containers because they are already added._contentappend (itemCargo_container- (_subContainersapply {_x # 0}));
_content
};
fnc_setCargo = {
private_container=_this # 0;
private_content=_this # 1;
// Clear container of all previous content.clearMagazineCargoGlobal_container;
clearWeaponCargoGlobal_container;
clearBackpackCargoGlobal_container;
clearItemCargoGlobal_container;
// Add new content.
{
private_item=_x;
// Is item a simple item? Form: "abc"if (_itemisEqualType"") then {
_containeraddItemCargoGlobal [_item, 1];
// Is item a magazine? Form: ["abc", 30]
} else {if (_item # 1isEqualType0) then {
_containeraddMagazineAmmoCargo [_item # 0, 1, _item # 1];
// Is item a weapon? Form: ["abc", "", "", "", ["mag", 30], [], ""]
} else {if (_item # 1isEqualType"") then {
_containeraddWeaponWithAttachmentsCargoGlobal [_item, 1];
// Is item a container? Form: ["abc", [container content...]]
} else {
private_subContainerClass=_item # 0;
private_subContainerContent=_item # 1;
// Backpacks need to be added with a different command than vests and uniforms.if (getNumber (configFile>>"CfgVehicles">>_subContainerClass>>"isbackpack") ==1) then {
_containeraddBackpackCargoGlobal [_subContainerClass, 1];
} else {
_containeraddItemCargoGlobal [_subContainerClass, 1];
};
// Add content to the newly added subcontainer.// This is somewhat expensive so only do it if there is content to be added.if (count_subContainerContent>0) then {
// The only way to get the container object of the newly added subcontainer is to list all container// objects and search for the one that we added. It is probably at the end of the array, so searching in// reverse order. The first that has the same class name, and is empty, is the one we are looking for.private_subContainers=everyContainer_container;
reverse_subContainers;
private_added=_subContainers # (_subContainersfindIf {
_x # 0isEqualTo_subContainerClass&& {_x # 1call fnc_isCargoEmpty}
});
// Set the subcontainer content by calling this function recursively on it.
[_added # 1, _subContainerContent] call fnc_setCargo;
};
}}};
} forEach_content;
};
The text was updated successfully, but these errors were encountered:
I recently found out that there are no such functions/commands in Arma yet, so I wrote these generic functions for getting and setting vehicle cargo inventory, such as the content of an ammo box. I think these would fit CBA well. I didn't make a PR because I don't know the conventions of the CBA project.
Details
getUnitLoadout
andsetUnitLoadout
which are meant for unit inventory management.getUnitLoadout
andsetUnitLoadout
.fnc_getCargo
andfnc_setCargo
are both recursive, they are recursively called for any subcontainers (so backpacks, vests...) in the inventory.Inventory format
Inventory is represented as an array containing the the following types of items:
["className", ammoCount]
["className", "suppressor", "pointer", "optics", ["primaryMag", ammoCount], ["secondaryMag", ammoCount], "bipod"]
["className", [container inventory...]]
"className"
Example output of
fnc_getCargo
:Functions
fnc_isCargoEmpty
Parameters:
vehicle: Object
Return value:
Boolean
fnc_getCargo
Parameters:
vehicle: Object
Return value:
Array - Inventory array
fnc_setCargo
Parameters:
[
vehicle: Object
content: Array - Inventory array
]
Return value:
Nothing
The text was updated successfully, but these errors were encountered: