MZ [Solved] Close character selection window when last item is used

Hey folks,

Looking for something very simple. If the player has multiple of the same item and uses one, the game character selection window stays open. This is good. However, if the player only has one of an item and uses it in the menu, the character selection screen stays open and trying to use the item again just plays a sound effect. I would like a plugin that changes this behavior so if the player uses the last item, it closes the character selection screen and takes you back to the item screen.
This should work (not 100% sure if you need to do some conditionals if your items use common events to exit the menu):

Scene_Item.prototype.useItem = function() {
Scene_ItemBase.prototype.useItem.call(this);
this._itemWindow.redrawCurrentItem();
if ($gameParty.numItems(this.item()) === 0) {
this.hideActorWindow();
this.activateItemWindow();
}
};
This should work (not 100% sure if you need to do some conditionals if your items use common events to exit the menu):

Scene_Item.prototype.useItem = function() {
Scene_ItemBase.prototype.useItem.call(this);
this._itemWindow.redrawCurrentItem();
if ($gameParty.numItems(this.item()) === 0) {
this.hideActorWindow();
this.activateItemWindow();
}
};

Works perfectly! I tested an item that runs a Common Event and it behaves as expected, simply closing the entire menu and taking me back to the map.

Original thread: https://forums.rpgmakerweb.com/threads/solved-close-character-selection-window-when-last-item-is-used.182898/