Jump to content
JPreston

Adding attachments to weapon in backpack

Recommended Posts

Ok, so I'm trying to equip a soldier for a mission I'm working on. The soldier carries a sniper rifle as a primary weapon and has a short barrelled rifle in his backpack. Now I'm running into trouble when trying to put attachments on the weapon in the backpack.

Is it possible to do so, in which case...any ideas? Or am I just barking up the wrong tree.

Thanks

J

Here is the relevant section of the script:

(unitBackpack this) addmagazineCargo ["30Rnd_65x39_caseless_mag",5];

(unitBackpack this) addweaponCargo ["arifle_MXC_F",1];

(unitBackpack this) additemCargo ["FirstAidKit",1];

(unitBackpack this) addmagazineCargo ["SatchelCharge_Remote_Mag",1];

Share this post


Link to post
Share on other sites

There should be configs for weapons with attachments already on. Check the six browser.

Share this post


Link to post
Share on other sites

I'm digging this one out of the grave cause I have the same issue.  I either need a way to remove an acessory from a weapon in the backpack or add it.  Is there a way now in 2017 ?

Share this post


Link to post
Share on other sites

This should help:

 

When I want to place a second scope for snipers in my mission I just open the game, click on Arsenal, select a weapon and equip it with the scope I want to be in the backpack.

Click on try and while playing I just open my inventory and drag the scope into the backpack.

I go back to the arsenal menu and the weapon I have tried has no longer got a scope (its in the backpack). I place another scope. I save the loadout. I open the editor, right click on the needed unit, click on edit arsenal, load the previously saved loadout and success!!!

I got one scope in the backpack and another on my weapon.

 

This makes snipers that play our missions so grateful!!!

At least the ones that I know  :whistle:

Share this post


Link to post
Share on other sites

Well my use case is slightly different.  I have a weapon with attachments in my inventory, and I have a GUI where I say to remove that attachment.  What I want to have is some kind of script command: _weapon removeWeaponItem _item;  

 

You have removePrimaryWeaponItem, removeSecondaryWeaponItem and remvoeHandgunWeaponItem but not a single decent way to remove one from a weapon in the inventory, it's frustrating

Share this post


Link to post
Share on other sites

If you can use addons, you just need to make a really simple config for your weapon with attachments as linkedItems. 

So you'll have a classname for your weapon with attachments on it.

and then : (unitBackpack this) addweaponCargo ["YourCustomClassname",1];

Share this post


Link to post
Share on other sites

Well addons isn't an option

 

I solved it with a workaround an ugly one.  So I want to remove an attachment from a gun in my backpack fe: acc_pointer_IR.  

 

FINE: so I do the following

- I fetch the weaponItems of the weapon you get something like ["arifle_MX_GL_F","","acc_pointer_IR","optic_Aco",["30Rnd_65x39_caseless_mag",30],["1Rnd_HE_Grenade_shell",1],""]

- I delete the weapon from inventory with removeItem _weaponItems select 0;

- Then I loop over the array adding the gun and each attachment to the backpack except the acc_pointer_IR

 

Pro: I managed to delete the attachment from the weapon in my backpack

Con: When I open my backpack now I have a disassembled weapon

 

What I want BI to GIVE US ASAP is a method like

 

["acc_pointer_IR", <<weaponID>>] call BIS_fnc_removeWeaponItem;

Share this post


Link to post
Share on other sites
43 minutes ago, celludriel said:

What I want BI to GIVE US ASAP is a method like

 

["acc_pointer_IR", <<weaponID>>] call BIS_fnc_removeWeaponItem;

Good luck with that, we've been asking for BI to give us better handling of inventory weapons for ages. Even though there has been some excellent progress in handling most inventory items it is always just enough for us not to be able to handle weapons efficiently. There is weaponAccessoriesCargo, removeWeaponAttachmentCargo & removeWeaponCargo but its anyones guess what weaponID and creatorID actually are.

Be so much easier if BI gave us a command so we could retrieve these needed Ids, weaponIDs backpackContainer player, to just return an array of arrays of [ weapon classname, weaponID, creatorID ] then we can use the previous commands to manipulate weapons and their attachments as cargo.

We can get some form if ID for containers, backpackContainer player will return "1da70339600# 10: backpack_tortila.p3d" where I presume "1da70339600# 10" is some form of internal ID for the players backpack and is what we likely need for weaponID.

 

4 hours ago, celludriel said:

When I open my backpack now I have a disassembled weapon

About the closest you can get that I can think of is the "DropWeapon" action from a hidden dummy unit.

TAG_fnc_updateContainerWeapons = {
	
	params[ "_container", "_weaponInfo", "_itemToRemove" ];
	
	_dummy = if ( isNil { player getVariable "dummy" } ) then {
		
		_dummy = createGroup side player createUnit [ typeOf player, [0,0,0], [], 0, "NONE" ];
		_dummy hideObjectGlobal true;
		{
			_dummy disableAI _x;
		}forEach [
			"TARGET", 
			"AUTOTARGET", 
			"MOVE", 
			"ANIM", 
			"TEAMSWITCH", 
			"FSM", 
			"AIMINGERROR", 
			"SUPPRESSION", 
			"CHECKVISIBLE", 
			"COVER", 
			"AUTOCOMBAT", 
			"PATH"
		];
		
		_dummy addBackpack "B_Carryall_mcamo";
		
		player setVariable[ "dummy", _dummy ];
		
		_dummy
	}else{
		player getVariable "dummy";
	};
	
	
	_weaponData = weaponsItemsCargo _container;
	{
		if ( _x isEqualTo _weaponInfo ) exitWith {
			_weaponData select _forEachIndex set [ _x find _itemToRemove, "" ];
		};
	}forEach _weaponData;
	clearWeaponCargoGlobal _container;
	
	removeAllWeapons _dummy;
	removeAllItems _dummy;
	removeAllAssignedItems _dummy;
	
	
	{
		_x params[ "_weapon" ];
		_dummy addWeapon ( _weapon call BIS_fnc_baseWeapon );
		{
			if !( ( _x isEqualType "" && { _x isEqualTo "" } ) || ( _x isEqualType [] && { _x isEqualTo [] } ) ) then {
				if !( _x isEqualType [] ) then {
					_x = [ _x ];
				};
				_dummy addWeaponItem [ _weapon, _x ];
			};
		}forEach ( _x - [ _weapon ] );
		_dummy action [ "DropWeapon", _container, _weapon ];
	}forEach _weaponData;	
	
};

[ backpackContainer player, ( weaponsItemsCargo backpackContainer player ) select 0, "optic_Aco" ] call TAG_fnc_updateContainerWeapons;

Where the first weapon in the players backpack has a "optic_Aco" attached.

  • Like 3

Share this post


Link to post
Share on other sites

 

15 hours ago, Larrow said:

About the closest you can get that I can think of is the "DropWeapon" action from a hidden dummy unit.

 

yep, great method.

 that's exactly what i used to make this

 

 

  • Like 2

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

×