schadler17 36 Posted November 11, 2015 Basically I'm trying to create a script that detects if a player has a radio in his inventory, and if not, to assign him one. My problem is, sometimes the radio classname shows up as tf_anprc152, tf_anprc152_1, tf_anprc152_2, etc. My question is an easy way to find out which one is equipped without having to add an endless array of radio classname possibilities. What I want: if (!("tf_anprc152" in assignedItems player)) then {player linkItem "tf_anprc152";} else {hint "Radio Found!";}; Share this post Link to post Share on other sites
Lala14 135 Posted November 11, 2015 Basically I'm trying to create a script that detects if a player has a radio in his inventory, and if not, to assign him one. My problem is, sometimes the radio classname shows up as tf_anprc152, tf_anprc152_1, tf_anprc152_2, etc. My question is an easy way to find out which one is equipped without having to add an endless array of radio classname possibilities. What I want: if (!("tf_anprc152" in assignedItems player)) then {player linkItem "tf_anprc152";} else {hint "Radio Found!";}; if (!({tolower(_x) find "tf_anprc152" > 0} count (assignedItems player) > 0)) then {player linkItem "tf_anprc152";} else {hint "Radio Found!";}; Share this post Link to post Share on other sites
schadler17 36 Posted November 11, 2015 Doesn't work. https://community.bistudio.com/wiki/toLower My issue, is sometimes the classname is "tf_anprc152" If you assign another radio, or if the player picks one up, it'll switch to "tf_anprc152_1", "tf_anprc152_2", "tf_anprc152_2", etc. I need to detect all possibilities of the _x up to about 10. Share this post Link to post Share on other sites
terox 316 Posted November 11, 2015 // make sure all these classnames are lower case _found = false; _radios =[ tf_anprc152, tf_anprc152_1, tf_anprc152_2, tf_anprc152_3, tf_anprc152_4, tf_anprc152_5, tf_anprc152_6 ]; { if((ToLower_x) in assigneditems player)exitwith{_found = true}; }foreach _radios; if !(_found)then{Player linkitem "tf_anprc152";}; Share this post Link to post Share on other sites
Larrow 2821 Posted November 12, 2015 _hasRadio = { toLower _x find "tf_anprc152" >= 0 } count ( items player + assignedItems player ) > 0 Share this post Link to post Share on other sites
schadler17 36 Posted November 12, 2015 Fixed. _unit = _this select 0; while {true} do { sleep 3; _assignedItems = assignedItems _unit; _Items = items _unit; _hasRadio = { toLower _x find "tf_anprc152" >= 0 } count (_items + _assignedItems) > 0; { if (_hasRadio) then { hint format ["Radio Found!"]; } else { hint format ["Radio Not Found!"]; }; } forEach [ "tf_anprc152", "tf_anprc152_1", "tf_anprc152_2", "tf_anprc152_3", "tf_anprc152_4", "tf_anprc152_5", "tf_anprc152_6", "tf_anprc152_7", "tf_anprc152_8", "tf_anprc152_9" ]; }; Share this post Link to post Share on other sites
Larrow 2821 Posted November 12, 2015 No need for the foreach the Find will automatically find all tf_anprc152_# variants.. _unit = _this select 0; while {true} do { sleep 3; _assignedItems = assignedItems _unit; _Items = items _unit; _hasRadio = { toLower _x find "tf_anprc152" >= 0 } count (_items + _assignedItems) > 0; if (_hasRadio) then { hint format ["Radio Found!"]; } else { hint format ["Radio Not Found!"]; }; }; OR //Give player radio at start player linkItem "tf_anprc152"; //If he drops the radio re-add it player addEventHandler [ "Put", { params[ "_unit", "_container", "_item" ]; //If its a radio if ( toLower _item find "tf_anprc152" >= 0 ) then { //Re add it player linkItem "tf_anprc152"; //Remove dropped radio _itemCargo = getItemCargo _container; clearItemCargoGlobal _container; { if ( toLower _x find "tf_anprc152" < 0 ) then { _container addItemCargoGlobal [ _x, _itemCargo select 1 select _forEachIndex ]; }; }forEach ( _itemCargo select 0 ) ; }; }]; //If he uses arsenal and does not have radio when exiting arsenal re-add it [ missionNamespace, "arsenalClosed", { if ( { toLower _x find "tf_anprc152" >= 0 } count ( assignedItems player ) isEqualTo 0 ) then { player linkItem "tf_anprc152"; }; } ] call BIS_fnc_addScriptedEventHandler; So they cant drop or move it out of the assigned slot at all. Share this post Link to post Share on other sites