Item use restriction by switch or variable

I need to be able to restrict use of an item based on an arbitrary condition, such as a switch, variable, map ID, so on.  I was able to achieve this using Bobstah's Enhanced Restrictions plugin.  However, my game uses several Yanfly plugins, and Enhanced Restrictions doesn't seem to work together YEP_EquipCore and YEP_EquipRequirements.  With BOB_EnhancedRestrictions, YEP_EquipCore, and YEP_EquipRequirements all enabled, when I try to unequip an item in the Equip menu, I get the following error:


TypeError: Cannot read property 'equipRequirements' of undefined
    at Game_Actor.Game_BattlerBase.meetAllEquipRequirements (file:///C:/Users/Jeremy/Documents/RMMV/The%20Tower/js/plugins/YEP_X_EquipRequirements.js:447:12)
    at Window_EquipItem.isEnabled (file:///C:/Users/Jeremy/Documents/RMMV/The%20Tower/js/plugins/YEP_X_EquipRequirements.js:566:24)
    at Window_EquipItem.Window_ItemList.isCurrentItemEnabled (file:///C:/Users/Jeremy/Documents/RMMV/The%20Tower/js/rpg_windows.js:1939:17)
    at Window_EquipItem.Window_Selectable.processOk (file:///C:/Users/Jeremy/Documents/RMMV/The%20Tower/js/rpg_windows.js:1146:14)
    at Window_EquipItem.Window_Selectable.processHandling (file:///C:/Users/Jeremy/Documents/RMMV/The%20Tower/js/rpg_windows.js:1021:18)
    at Window_EquipItem.Window_Selectable.update (file:///C:/Users/Jeremy/Documents/RMMV/The%20Tower/js/rpg_windows.js:978:10)
    at file:///C:/Users/Jeremy/Documents/RMMV/The%20Tower/js/rpg_core.js:5745:19
    at Array.forEach (native)
    at WindowLayer.update (file:///C:/Users/Jeremy/Documents/RMMV/The%20Tower/js/rpg_core.js:5743:19)
    at file:///C:/Users/Jeremy/Documents/RMMV/The%20Tower/js/rpg_scenes.js:112:19rpg_managers.js:1722 SceneManager.catchExceptionrpg_managers.js:1683 SceneManager.update




The other strange part is when I select an equipped item, I dont get the "Remove" text from the EquipCore plugin.  When I select an empty box, thats when the error crops up.


TLDR version: Can anyone help me to restrict item use based on switches or map IDs while remaining compatible with YanflyEngine?  Thanks!!!
Actually i made before something like that, but iam not sure if it's work with other plugins.


i will try it and see.
Yep it worked with yanflyCore Engine


try it

View attachment Restrict_Items.js
That worked perfect!  One question though.  Can you "reverse" the code?  That is, make the item restricted when the switch is off and available when the switch is on?  The reason I ask is I am using this for a tent style item.  The way you have it written now, I would have to turn the on the switch on every map that I want the item restricted.  The other way, I just need to turn it on for my main map.  Thanks!!
Nevermind!  I just had to change the if statement to 


if($gameSwitches.value(Number(m[1]))==true


and now it works backwards 😛  .  Thanks for your help!
Ok


try this

View attachment Restrict_Items.js
Nevermind!  I just had to change the if statement to 



if($gameSwitches.value(Number(m[1]))==true


and now it works backwards 😛  .  Thanks for your help!



your welcome 😉

Original thread: https://forums.rpgmakerweb.com/threads/item-use-restriction-by-switch-or-variable.64818/