Jump to content
chronicsilence

Determining if an item is "assignable"

Recommended Posts

Some items in "CfgWeapons" are "assignable", that is, the "assignItem" command will stick it in a specific slots (such as radio, compass, NVGs, Binoculars, etc.). For a given config in CfgWeapons, is there a simple way to tell if it is "assignable"? Meaning, if the "assignItem" command will work on it?

Thanks!

Share this post


Link to post
Share on other sites

Thanks KK, but I need a way to know if a given config class is "assignable" without actually trying to assign it. How can I know if linkItem will work before actually trying it?

Share this post


Link to post
Share on other sites

I cannot see one particular config entry that will give you this information.

Heres some working information..

//Is an item assignable
_item = _this;
_itemType = typeOf _item;

_hasItemInfo = isClass ( configFile >> "CfgWeapons" >> _itemType >> "ItemInfo" );
_invType = getNumber ( configFile >> "CfgWeapons" >> _itemType >> "type" );
_invVal = getNumber ( configFile >> "CfgWeapons" >> _itemType >> "value" );
_invInfoType = getNumber ( configFile >> "CfgWeapons" >> _itemType >> "ItemInfo" >> "type" );

if ( _hasItemInfo && _invType in [ 131072, 4096 ] && _invVal in [ 2, 5 ] && _invInfoType in [ 0, 616 ] ) then {
//Item is assignable
};


//Get all assignable items from config weapons
assignableItems = [];
"
if ( isclass ( _x >> 'ItemInfo' )  && { getNumber ( _x >> 'scope' ) isEqualTo 2 }  ) then {
	_invType = getNumber ( _x >> 'type' );
	_invInfoType = getNumber ( _x >> 'ItemInfo' >> 'type' );
	_invVal = getNumber ( _x >> 'value' );

	if ( _invType in [ 131072, 4096 ] && _invInfoType in [ 0, 616 ] && _invVal in [ 2, 5 ] ) then {
		assignableItems pushBack ( configName _x );
	};
};
"configClasses ( configFile >> "CfgWeapons" );



//Item information

//assignedItems player
//["ItemWatch","ItemCompass","ItemGPS","ItemRadio","ItemMap","NVGoggles","NVGoggles_OPFOR","NVGoggles_INDEP","Binocular","Rangefinder","Laserdesignator","Laserdesignator_02","Laserdesignator_03"]


//"ItemWatch","ItemCompass","ItemGPS","ItemRadio","ItemMap"
//type 131072 		value 2		infoVal 0( isNil )		assignable

//"NVGoggles","NVGoggles_OPFOR","NVGoggles_INDEP"
//type 4096 		value 5		infoVal 616				assignable

//"Binocular","Rangefinder","Laserdesignator","Laserdesignator_02","Laserdesignator_03",
//type 4096 		value 5		infoVal 0( itemInfo does not exist )		not assignable

//"Zasleh2"
//type 131072 		value 2		infoVal 0( itemInfo does not exist )		not assignable 

There may be a better way but im just not seeing it at the moment.

Edited by Larrow
  • Like 1

Share this post


Link to post
Share on other sites

I'm a bit confused here. Since "assignedItems player" returns "Rangefinder" in the array, why does it return as "not assignable"? Also, this is even stranger because in my testing it seems that "linkItem" doesn't work with "Rangefinder".

---------- Post added at 13:52 ---------- Previous post was at 13:21 ----------

I guess I should clarify my question a bit. Instead of returning items that "linkItem" will work on, how can I get a list of items that "assignedItems" will return?

Edited by ChronicSilence

Share this post


Link to post
Share on other sites

The bino slot (rangefinder included) is the wildcard in there. You have to use addWeapon and assignItem for it. Kind of annoying.

This is how I tested for it in the past when adding assigned items back to the player.

_items = assignedItems player;


{
if (([(configFile >> "CfgWeapons" >> _x),"optics",0] call BIS_fnc_returnConfigEntry) > 0) then {
	player addWeapon _x;
	player assignItem _x; 
} else {
	player linkItem _x;
};
} forEach _items;

I guess I should clarify my question a bit. Instead of returning items that "linkItem" will work on, how can I get a list of items that "assignedItems" will return?

Larrows configClasses code will do that.

Share this post


Link to post
Share on other sites

From what I know, linkItem is simply a combination of addItem and assignItem, so in "theory" the list of assignedItems should be linkable items. But that's simply not true. The rangefinder requires that you use addWeapon to get it "assigned", while addItem will simply put it in your inventory. Then there are the large objects like FirstAidKit, Medikit, ToolKit, MineDetector that you can only addItem with, never assign or link. In fact, assignItem will cause those items to be removed from inventory! In other words, I don't have an answer to your question.

Share this post


Link to post
Share on other sites
I guess I should clarify my question a bit. Instead of returning items that "linkItem" will work on, how can I get a list of items that "assignedItems" will return?

Just remove the check for the itemInfo class from both of those snippets...

//Get all assignedItems items from a nearby weaponHolder
assignableItems = [];
{

_invType = getNumber ( configFile >> "CfgWeapons" >> _x >> "type" );
_invVal = getNumber ( configFile >> "CfgWeapons" >> _x >> "value" );
_invInfoType = getNumber ( configFile >> "CfgWeapons" >> _x >> "ItemInfo" >> "type" );

if ( _invType in [ 131072, 4096 ] && _invVal in [ 2, 5 ] && _invInfoType in [ 0, 616 ] ) then {
    assignableItems pushBack _x;
};
}forEach itemCargo ( nearestObject [ player, "WeaponHolder" ] ) ;


//Get all assignedItems items from config weapons
assignableItems = [];
"
   if (  getNumber ( _x >> 'scope' ) isEqualTo 2 ) then {
       _invType = getNumber ( _x >> 'type' );
       _invInfoType = getNumber ( _x >> 'ItemInfo' >> 'type' );
       _invVal = getNumber ( _x >> 'value' );

       if ( _invType in [ 131072, 4096 ] && _invInfoType in [ 0, 616 ] && _invVal in [ 2, 5 ] ) then {
           assignableItems pushBack ( configName _x );
       };
   };
"configClasses ( configFile >> "CfgWeapons" );

Is there a listing anywhere of the meanings of the different "types" and "values"?
For the values not that i can think of. The types are commented in the UI script for the inventory handleGear.sqf.

#define WeaponNoSlot		0	// dummy weapons
#define WeaponSlotPrimary	1	// primary weapons
#define WeaponSlotSecondary	4	// secondary weapons
#define WeaponSlotHandGun	2	// HandGun
#define WeaponSlotHandGunItem	16 // HandGun magazines
#define WeaponSlotItem		256	// items
#define WeaponSlotBinocular	4096	// binocular
#define WeaponHardMounted	65536
#define WeaponSlotInventory 131072 // inventory items

Edited by Larrow
  • Like 1

Share this post


Link to post
Share on other sites
On 2/6/2015 at 8:58 AM, Larrow said:

For the values not that i can think of. The types are commented in the UI script for the inventory handleGear.sqf.

 

Hello there to everyone ! 

 

# It might be an old thread , but scripting , is scripting !

 

I was searching on how to do this , so thank you very much  Larrow !

I would like also to ask , if there is any more information provided , since 2015 , or if someone has any other solution about it.

 

Thanks !

 

 

  • Like 1

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

×