Jump to content
chronicsilence

Adding weapon to crate with specific attachments

Recommended Posts

Let's say I have an ammo crate, and I want to add two MX rifles to it. One of them I would like to have an ACO optic attached, and the other I would like to have a flashlight attached. So when I'm done, the inventory screen for the crate should look like this:

 

Capture.png

 

So my question is, how can I add weapons with specific attachments to a crate? I know that there are some specific class names which have attachments built in, like "arifle_MX_ACO_F", but there isn't one for every combination (for this example, there's no class for an MX rifle that has a flashlight attached).

 

Any thoughts? Thanks!

Share this post


Link to post
Share on other sites

Ideally, I'd suggest creating a little config entry for that. Basically, you create weapons with those accessories, and then you can add those guns to the crate easily, since they have unique class names. The config entry might look like this:

class cfgWeapons
{
	class arifle_MX_F;
	class custom_MX_ACO_F: arifle_MX_F
	{
		class LinkedItems
		{
			class LinkedItemsOptic
			{
				slot = "CowsSlot";
				item = "optic_Aco";
			};
		};
	};

	class custom_MX_FL_F: arifle_MX_F
	{
		class LinkedItems
		{
			class LinkedItemsAcc
			{
				slot = "PointerSlot";
				item = "acc_flashlight";
			};
		};
	};
};

Share this post


Link to post
Share on other sites

Ideally, I'd suggest creating a little config entry for that.

That's great, but what if I need to add some weapons with attachments dynamically?

Imagine unit having some weapon with attachments in its backpack. Unit dies, then we require to restore its loadout on respawn. Or the list of allowed weapons and attachments is regulated by mission parameters.

Currently I have to add attachments to the backpack separated from the gun. But first I must check whether the gun itself has attachments. If I'm lucky and unit had all the same attachments as weapon in config file, I can simply add this weapon to backpack and it will have all attachments on it. But more likely I will need to put gun without attachments and all attachments separately. I can't have all weapons/attachments combinations in config.

It's too much work, isn't it? And the result is still not as desired.

 

Probably this theme was already discussed zillion of times, sorry.

Share this post


Link to post
Share on other sites

I'm not sure if I understand correctly. If you have a soldier with a certain loadout, it's very easy to restore such loadout on respawn. There are weapons[] / respawnWeapons[] and similar config properties exactly for that. But if you have a soldier grabbing some items during mission, and you want to restore those, it's of course a bit more complicated, since it will require some scripting.

  • Like 1

Share this post


Link to post
Share on other sites

But if you have a soldier grabbing some items during mission, and you want to restore those, it's of course a bit more complicated, since it will require some scripting.

This. Player grabs whatever he can see and puts it into backpack.

I figured out how to restore weapons with all attachments in primary/secondary/handgun slots, but still no luck with weapons put into the backpack.

Share this post


Link to post
Share on other sites
Guest

Wow, I was not expecting a Bohemia dev to answer here. I think he is asking for a way to add weapons with custom attachments directly in the crate.

Btw, I have a question for you. I managed to create a script witch retrieve the main class of a weapon with attachment by looking into all the parent classes (i.e Rifle_MX_RCO => Rifle_MX). Is their any function or config entry that contains the weapon base class.

Share this post


Link to post
Share on other sites

Btw, I have a question for you. I managed to create a script witch retrieve the main class of a weapon with attachment by looking into all the parent classes (i.e Rifle_MX_RCO => Rifle_MX). Is their any function or config entry that contains the weapon base class.

 

This will give all the base weapons. The part about "linked items" is where it checks for attachments. Props to Dslyecxi, he made a gear selector a while back, basically got me started understanding configs in general, and I only changed a little bit of his code.

fnc_baseWeapons = 
{

	_primaries = [];
	_secondaries = [];
	_launchers = [];

	_count =  count (configFile >> "CfgWeapons");
	for "_x" from 0 to (_count-1) do
	{
		_weap = ((configFile >> "CfgWeapons") select _x);
						
		if (isClass _weap) then
		{
		if (getnumber (_weap >> "scope") == 2) then
		{			
			if (!isClass (_weap >> "LinkedItems")) then
			{
				if (count(getarray (_weap >> "magazines")) !=0 ) then
				{
					_type = getnumber (_weap >> "type");
					if (_type == 1) then
					{_primaries = _primaries + [configName _weap];}
			else 	{
					if (_type == 2) then
					{_secondaries = _secondaries + [configName _weap];}
			else    {
					if (_type == 4) then
					{_launchers = _launchers + [configName _weap];}};
	};	};	};	};	};	};
};

Share this post


Link to post
Share on other sites

 

 

Wow, I was not expecting a Bohemia dev to answer here.

:ph34r:

 

Apparently, there's this BIS_fnc_baseWeapon function, which should help getting the base class of a weapon, which is already configured with attachments = it has a separate config class with the LinkedItems class containing various accessories (like in my sample config above).

 

Attaching something to a weapon during a mission is a different case, though, since that does not alter the weapon class. If a player (or a unit) has a weapon with accessories equipped, weaponAccessories can be used (for example:

player weaponAccessories primaryWeapon player

returns an array of all the accessories of the primary weapon of the player. And the "player" can be replaced by another unit.

 

Finally, you can get to weapons in a backpack thanks to weaponsItemsCargo, for example:

weaponsitemscargo unitBackpack player

Hope that helps. :)

Share this post


Link to post
Share on other sites

If there were commands like addWeaponsItemsCargo/addWeaponsItemsCargoGlobal which could take array in the same form as weaponsItemsCargo returns, that would be great.

Share this post


Link to post
Share on other sites

Well, you can get inside of an array thanks to "select".

player addweapon (weaponsitemscargo unitBackpack player select 0 select 0)

This gives me the weapon I have in a backpack. The attachments of that weapon follow the weapon in the array. 1 is a suppresor, 2 is a side attachment, 3 is for optics, 5 for bipods.

player addweapon (weaponsitemscargo unitBackpack player select 0 select 0);
player addPrimaryWeaponItem (weaponsitemscargo unitBackpack player select 0 select 1);
player addPrimaryWeaponItem (weaponsitemscargo unitBackpack player select 0 select 2);
player addPrimaryWeaponItem (weaponsitemscargo unitBackpack player select 0 select 3);
player addPrimaryWeaponItem (weaponsitemscargo unitBackpack player select 0 select 5);

So this gives me an exact copy of a weapon in my backpack.

Share this post


Link to post
Share on other sites

Well, you can get inside of an array thanks to "select".

player addweapon (weaponsitemscargo unitBackpack player select 0 select 0)

This gives me the weapon I have in a backpack. The attachments of that weapon follow the weapon in the array. 1 is a suppresor, 2 is a side attachment, 3 is for optics, 5 for biopods.

player addweapon (weaponsitemscargo unitBackpack player select 0 select 0);
player addPrimaryWeaponItem (weaponsitemscargo unitBackpack player select 0 select 1);
player addPrimaryWeaponItem (weaponsitemscargo unitBackpack player select 0 select 2);
player addPrimaryWeaponItem (weaponsitemscargo unitBackpack player select 0 select 3);
player addPrimaryWeaponItem (weaponsitemscargo unitBackpack player select 0 select 5);

So this gives me an exact copy of a weapon in my backpack.

Thank you, but this is how I end with weapon copied from backpack to primary weapon slot. What I was asking is to copy weapon from one backpack to another backpack (or in general any container) with all corect attachments.

 

Imagine example situation: player has MX rifle as primary weapon and Katiba (+ some custom attachments) in backpack. Now how do I write respawn handler (it has both references to new and old unit instances) to have both weapons with all attachments for new unit? So that MX is in primary weapon slot and Katiba + attachments in backpack?

Correct me if I'm wrong, but for now I only can put "attachments" detached.

Share this post


Link to post
Share on other sites

Use an invisible unit with action "DropWeapon". For instance..

fnc_addWeaponWithItems = {
    params [ "_weapon", "_items", "_container", [ "_useBaseWeapon", false ] ];
    
    if ( _useBaseWeapon ) then {
        _weapon = _weapon call BIS_fnc_baseWeapon;
    };
    
    _fnc_clearUnit = {
        params[ "_unit" ];
        removeAllWeapons _unit;
        removeAllItems _unit;
    };
    
    if ( isNil "LARs_containerFiller" ) then {
        _center = createCenter civilian;
        _grp = createGroup _center;
        LARs_containerFiller = _grp createUnit [ "C_Man_1", [ 0,0,0 ], [], 0, "NONE" ];
        LARs_containerFiller addEventHandler [ "HandleDamage", {
            0
        }];
        hideObjectGlobal LARs_containerFiller;
        {
            LARs_containerFiller disableAI _x
        }forEach [
            "TARGET",
            "AUTOTARGET",
            "MOVE",
            "ANIM",
            "TEAMSWITCH",
            "FSM",
            "CHECKVISIBLE",
            "COVER",
            "AUTOCOMBAT"
        ];

        LARs_containerFiller call _fnc_clearUnit;
    };
    
    LARs_containerFiller addWeapon _weapon;
    {
        LARs_containerFiller addPrimaryWeaponItem _x;
    }forEach _items;
    
    LARs_containerFiller action [ "DropWeapon", _container, _weapon ];
    
};

[ "arifle_MX_F", ["optic_ACO"], myBox ] spawn fnc_addWeaponWithItems;
[ "arifle_MX_F", ["acc_flashlight"], myBox ] spawn fnc_addWeaponWithItems;

Would do as per the OP.

Not particularly efficient to have a unit hanging around even if he is a mere shell of an AI and it would be extremely useful if BI gave us the ability to reference any containers (weapon container) like we can for uniforms and backpacks etc.

  • Like 2

Share this post


Link to post
Share on other sites

Thank you, but this is how I end with weapon copied from backpack to primary weapon slot.

Exactly, kind sir, that's what I wrote in my post. ;) Basically, that's the way to get to the items you need, so then you can look for how to move them wherever you please. :) (I can take a look at that myself, but no sooner than tomorrow, apologies.)

 

 

Use an invisible unit with action "DropWeapon".

 

Thank you, larrow, for mentioning that. I personally prefer config solutions over script ones whenever possible, but I understand it might not be always efficient to create an addon for little things.

Share this post


Link to post
Share on other sites
Thank you, larrow, for mentioning that. I personally prefer config solutions over script ones whenever possible, but I understand it might not be always efficient to create an addon for little things.

I can understand that a config solution is the more concise way to go about this but if you are only making missions the trouble you have to go to to make an addon, then make sure people have your addon for A mission.

The whole thing would be a mess with lots of little addons that do nothing particular floating around the community, let alone flooding end users addon lists with something that may only be needed for A particular mission they play.

The solution to this problem as i mention in my previous post would be for BI to give us the commands to access a weapon container like we do for others like uniform, backpack etc

 

An even better solution would be that we can manipulate the config from the mission directory so we could add those one off items or make the changes necessary for a mission, but I'm guessing this is not possible without a lot of engine side changes. One can dream :D

  • Like 2

Share this post


Link to post
Share on other sites

Exactly, kind sir, that's what I wrote in my post. ;) Basically, that's the way to get to the items you need, so then you can look for how to move them wherever you please. :) (I can take a look at that myself, but no sooner than tomorrow, apologies.)

 

 

 

Thank you, larrow, for mentioning that. I personally prefer config solutions over script ones whenever possible, but I understand it might not be always efficient to create an addon for little things.

 

Geeze, this kind of exploded overnight. Thanks for getting involved Locklear. So the thread got a little off-track from the OP and what I'm trying to do. I know I could do it by defining new configs with pre-defined attachments, but

1) I need a solution that does not require an addon

2) this needs to be a dynamic solution that can handle any combination of weapons/attachments; with ~50 weapons and 10+ different attachments for each, that's well into the thousands of configs I would need to define to account for every possible combination, and

3) this solution would not allow adding weapons to crates that have magazines loaded. In-game, you can load a mag into your primary weapon and then stick it in a crate and it will remain loaded; there is no way to do this through creating a custom config (that I'm aware of)

 

I found larrow's "DropWeapon" solution in a previous thread after much Googling (here) and made it work. The problem is that it's extremely slow, I couldn't get it below 1 second to add 10 weapons with attachments to a crate. This is especially an issue when you consider that if you want to remove a weapon from a crate, you have to delete all of them at once (clearWeaponCargo) and then re-add all the ones you didn't want to remove (so if I have a crate of 20 weapons with custom attachments and I want to remove one of them, I have to remove all of them and then it will take 2 seconds to re-add all the others). That and it creates an AI that adds unnecessary network traffic. What we really need is a scripting command for it, like what is suggested in this feedback thread (cached version while the feedback.arma3.com site is down). Something like:

_container addWeaponWithAttachments ["weapon", "muzzle_attachment", "pointer_attachment", "optics_attachment", ["magazine_classname", bulletCount], ["grenade_magazine_classname", bulletCount], "bipod_attachment"];

This functionality is obviously already in the game code somewhere, because this is exactly what happens when you drag a weapon with attachments from your primary slot to your backpack or a cargo container while in the inventory screen. There's just no scripting command right now to do it.

Share this post


Link to post
Share on other sites

This functionality is obviously already in the game code somewhere, because this is exactly what happens when you drag a weapon with attachments from your primary slot to your backpack or a cargo container while in the inventory screen. There's just no scripting command right now to do it.

Indeed it is. But how do you know it's not implemented on top of "DropWeapon"? How do you know it is not that slow?

Anyway, list me in for the new nice proper command(s).

Share this post


Link to post
Share on other sites

Indeed it is. But how do you know it's not implemented on top of "DropWeapon"? How do you know it is not that slow?

Anyway, list me in for the new nice proper command(s).

 

It could be done using "DropWeapon" I suppose. That would be a strange process when moving a weapon with attachments/mags from your backpack to a crate, it would have to load it on the player and then drop it.

 

If there was a way to do DropWeapon without the animation, it could work pretty well. Just have your character drop a series of weapons into the crate very quickly, and you wouldn't even notice. Unfortunately, you can't skip the animation it seems.

Share this post


Link to post
Share on other sites

Sorry for the bump, but what's been discussed in this thread is pretty much what I've written over in the suggestions thread. I was wondering if there were any news on this?

 

 

Just being able to manipulate specific items in an inventory container would already go a long way. Essentially, being able to drop/remove a certain item/magazine/weapon, aswell as being able to add weapons/magazines with specific attachments (ie "spawn a gun with an attached mag that is half full") would prevent us from having to use workarounds like the one Larrow posted (which works, but is tedious and not exactly suited for large-scale use).

 

I understand that this would take time, but I can't help but wonder how the engine currently handles inventory. Surely there is already some kind of array system that keeps track of what's in a container, so I imagine we merely need a way to access and manipulate that system. :)

Edited by Cre8or
(Fixed link after forums update)

Share this post


Link to post
Share on other sites
On 22/02/2016 at 1:22 PM, Locklear said:

Ideally, I'd suggest creating a little config entry for that. Basically, you create weapons with those accessories, and then you can add those guns to the crate easily, since they have unique class names. The config entry might look like this:


class cfgWeapons
{
	class arifle_MX_F;
	class custom_MX_ACO_F: arifle_MX_F
	{
		class LinkedItems
		{
			class LinkedItemsOptic
			{
				slot = "CowsSlot";
				item = "optic_Aco";
			};
		};
	};

	class custom_MX_FL_F: arifle_MX_F
	{
		class LinkedItems
		{
			class LinkedItemsAcc
			{
				slot = "PointerSlot";
				item = "acc_flashlight";
			};
		};
	};
};

 

Where to put it? in SQF file? 

Share this post


Link to post
Share on other sites

It's a config entry, not a script, so it's to be used in a custom addon.

Share this post


Link to post
Share on other sites

Description.ext does not support all config classes (e.g. CfgWeapons, CfgVehicles), they have to be declared in addons and loaded when the game starts.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×