Contraband or Illegal Items (+ Ability to Change Contraband Status)

I'm trying to develop a mechanic where certain items are considered "contraband" or "illegal" for various purposes in-game.

I know at least one way to make illegal items unable to be sold in "legitimate" stores (i.e. either set the sell value to 0 or use Yanfly's Item Core's <Cannot Sell> note tag). I also know how to "check" if a player is possessing a contraband item for purposes of developing features like being searched by a guard / police. But I'm trying to come up with a way to change the contraband status of an item mid-game.

So, just to give an example, imagine that a faction in-game outlaws possession and sale of a particular drug. But further imagine that I want to have the faction legalize possession of that drug mid-game. Can anyone think of an efficient way that I can make it so the player will then be able to sell the item and the player will not be flagged as possessing contraband during a hypothetical guard search? Bonus points if you can think of a way to implement this so that certain items can be illegal in one faction's shops but not others.

I'm comfortable using switches, variables, common events, and script calls as necessary, so feel free to suggest anything you think would work. I'm also using Yanfly's Item Core and a lot of associated Yanfly plugins, in case that helps or matters. Any creative ideas appreciated!
Internally, the "cannot sell" notetag just sets the cannotSell property of the item to true. You can do this programmatically using a script command on the item in question when you want to switch it from contraband to not.

In cases of shops where you want to circumvent it, you could set it to false, then have the shop command in the event, then set it back to true. I *think* that'll wait to set it until after the player exits the shop, but I may be mistaken. You'd have to have a play with that.
Internally, the "cannot sell" notetag just sets the cannotSell property of the item to true. You can do this programmatically using a script command on the item in question when you want to switch it from contraband to not.

In cases of shops where you want to circumvent it, you could set it to false, then have the shop command in the event, then set it back to true. I *think* that'll wait to set it until after the player exits the shop, but I may be mistaken. You'd have to have a play with that.

Thank you so much! Going to try this but it sounds like it should allow for exactly what I want.
I just tried it with the consumable property on an item and it works perfectly. The setting back to true/false doesn't happen until you close the shop.
Can confirm this worked perfectly! Thank you!

For anyone else who comes across this thread in the future, here are the script calls you can use to alter the "canSell" or "cannotSell" property of an item for purposes of Yanfly's Shop Core plugin:

Can Sell
$dataItems[1].cannotSell=false;
$dataItems[1].canSell=true;

Cannot Sell
$dataItems[1].cannotSell=true;
$dataItems[1].canSell=false;
Glad to be of assistance! Note that you only need to bother with canSell if you want to be able to sell an item that has no sell price in the database normally.

I've moved this thread to MV Support. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/contraband-or-illegal-items-ability-to-change-contraband-status.123352/