alleycat 28 Posted March 7, 2016 I would like to check whether a weapon is within an array of weapons. The problem is not the array but the different weapons having different classnames depending on attachments. Is there a way to check if a weapon is an MX rifle (carbine) regardless of the attachments? I have tried iskindof but that appears to be completely useless. From the developer console: (currentweapon player) iskindof "srifle_LRR_camo_LRPS_F" = false currentweapon player == "srifle_LRR_camo_LRPS_F" Makes no sense. In the same console screen I put both lines in the watch field. The weapon being reported as the current weapon of the player returns false on a iskindof check. EDIT: I will check for ammo type used, should work for the purpose Share this post Link to post Share on other sites
Greenfist 1863 Posted March 7, 2016 Try isKindOf. I guess something like: primaryWeapon player isKindOf ["Rifle", configFile >> "CfgWeapons"]; where "rifle" is their parent class. You can check it in the config viewer. Share this post Link to post Share on other sites
reyhard 2082 Posted March 7, 2016 https://community.bistudio.com/wiki/isKindOf use alternate syntax currentWeapon player isKindOf ["Rifle", configFile >> "CfgWeapons]; or check getText (configFile >> "cfgWeapons" >> "rifleClassName" >> "baseWeapon") Share this post Link to post Share on other sites
alleycat 28 Posted March 7, 2016 Thanks, I do not understand these >> commands, they are so cryptic to me. As for the weapon I went for detecting the magazine, seemed the most reliable and easiest way. I am trying to check if a player was a sniper and was using a sniper rifle in an eventhandler. for the ammo I checked it against and array of ammo types and used the boolean in the condition. I tried the same with the player class, but that did not work. if ((_causedBy isKindOf "O_sniper_F") or (_causedBy isKindOf "I_sniper_F") or (_causedBy isKindOf "B_sniper_F")) then I would like to condense this check into something more elegant like with the ammo where I wrote: EDIT: would it be possible to write a check like so: _causedBy isKindOf _variablethatchecksifinsomearray _magazines = ["7Rnd_408_Mag","5Rnd_127x108_Mag"]; _ammotype = currentMagazine _causedBy; _ammotype = _ammotype in gsa_sniper_magazines; _class if ((_causedBy isKindOf "O_sniper_F") or (_causedBy isKindOf "I_sniper_F") or (_causedBy isKindOf "B_sniper_F")) then { systemchat "pass sniper class"; if (_ammotype) then { systemchat "killed by valid sniper rifle"; hint "killed by valid sniper rifle"; }; Share this post Link to post Share on other sites
Guest Posted March 7, 2016 The answer was given in a recent post. PLEASE SEARCH ! Bis_fnc_baseWeapon You're welcome. Share this post Link to post Share on other sites
alleycat 28 Posted March 7, 2016 Thanks that function is very useful. Share this post Link to post Share on other sites
Alex150201 894 Posted March 7, 2016 Wouldn't the following work too? _pWeap = primaryWeapon player; if (_pWeap == arifle_MX_F) then { hint "Player has MX rifle"; }Else{ hint "Player doesn't have MX rifle"; }; Share this post Link to post Share on other sites
alleycat 28 Posted March 7, 2016 Tested in admin console. primaryWeapon indeed reliably returns the base weapon. However the wiki description is misleading, making it appear that it will return a a subclass with an attachment Share this post Link to post Share on other sites
Alex150201 894 Posted March 7, 2016 Tested in admin console. primaryWeapon indeed reliably returns the base weapon. However the wiki description is misleading, making it appear that it will return a a subclass with an attachment So it works? Share this post Link to post Share on other sites
Guest Posted March 7, 2016 So it works? He did not told us it does not. So maybe yes... Share this post Link to post Share on other sites
Alex150201 894 Posted March 8, 2016 He did not told us it does not. So maybe yes... Yep, well if it works I must say, sometimes simple is good and when someone is writing like 1000 lines of code that can easily be done in 100 it makes me a bit mad. Like why the hell don't you got simple way that offers the same thing mate. Share this post Link to post Share on other sites
pedeathtrian 99 Posted March 8, 2016 Tested in admin console. primaryWeapon indeed reliably returns the base weapon. However the wiki description is misleading, making it appear that it will return a a subclass with an attachment Could not reproduce (1.56.134787). Put a soldier in editor. Gave him "arifle_MX_RCO_pointer_snds_F" rifle. Dropped weapon. Picked up weapon. Removed attachments. Added other attachments. "primaryWeapon player" always returns "arifle_MX_RCO_pointer_snds_F". Share this post Link to post Share on other sites
zapat 56 Posted March 8, 2016 This line is what I use to check if unit is using an MX rifle. It identifies every possible combinations correctly: if(([configfile >> "CfgWeapons" >> primaryWeapon _unit,true] call BIS_fnc_returnParents) select 1== "arifle_MX_base_F") then {}; To check only for a specific subtype (eg. carabine), I use: if(((primaryWeapon _unit) call BIS_fnc_weaponComponents) select 0 == "arifle_MXC_F" ) then {}; Share this post Link to post Share on other sites
Alex150201 894 Posted March 8, 2016 Could not reproduce (1.56.134787). Put a soldier in editor. Gave him "arifle_MX_RCO_pointer_snds_F" rifle. Dropped weapon. Picked up weapon. Removed attachments. Added other attachments. "primaryWeapon player" always returns "arifle_MX_RCO_pointer_snds_F". Okay then it doesnt work :D I dont know man arma is weird and we all know it especially if you have over 1000 hours like me :) Share this post Link to post Share on other sites
pedeathtrian 99 Posted March 8, 2016 All MX carbine classes derived from "arifle_MXC_F" class, so the fastest way to check for any derived class is to use isKindOf with this class as first element in array argument for isKindOf: (primaryWeapon player) isKindOf ["arifle_MXC_F", configFile >> "CfgWeapons"] This line is what I use to check if unit is using an MX rifle. It identifies every possible combinations correctly: if(([configfile >> "CfgWeapons" >> primaryWeapon _unit,true] call BIS_fnc_returnParents) select 1== "arifle_MX_base_F") then {}; This does not detect every possible combination. Check "arifle_MXC_F" class, it has "arifle_MX_base_F" as the very first parent (should be select 0). Same for "arifle_MX_F". As for the weapon I went for detecting the magazine, seemed the most reliable and easiest way. You can end up with MX SW using 30Rnd magazine this way. Share this post Link to post Share on other sites
Tajin 349 Posted March 8, 2016 A bit unorthodox, but In this specific case a simple string comparison should also do the trick: fnc_inStr = { _str1 = _this select 0; _str2 = _this select 1; _arr1 = _str1 splitString ""; _arr2 = _str2 splitString ""; _res = true; { if (_x != (_arr2 select _forEachIndex)) exitWith { _res = false; }; } forEach _arr1 _res }; if ( ["arifle_MX", primaryWeapon player] call fnc_inStr ) then {...}; Share this post Link to post Share on other sites