How to close the window automatically when the quantity of an item reaches 0?

Hi, guys~

I recently find an inconvenient acting in default menu.

When an item is used in menu, a new window is poped up and you can choose who would drink the potion, after you choose the right actor, the potion is used, its number come down to 0, but the  poped up window for choosing actor does not close, although you cannot use the potion again. What you can do is only to press X and quit the window.

Is it possible to close the window automatically when the quantity of an item reaches 0?
I see you followed my advice. 🙂

Here is a little snippet which should do what you ask.

Spoiler
class Scene_Item < Scene_ItemBase alias sixth_zeroitem1222 start def start sixth_zeroitem1222 @zero = false end alias sixth_zeroitem7765 on_item_ok def on_item_ok if @item_window.current_item_enabled? && @zero == false Sound.play_ok sixth_zeroitem7765 elsif !@item_window.current_item_enabled? && @zero == false Sound.play_buzzer @item_window.activate else @item_window.activate @zero = false end end alias sixth_zeroitem3354 use_item def use_item sixth_zeroitem3354 if item.is_a?(RPG::Item) && $game_party.item_number(item) == 0 @zero = true @item_window.select(0) hide_sub_window(@actor_window) end endendclass Window_ItemList < Window_Selectable def process_ok Input.update deactivate call_ok_handler endend
Put this below all the default scripts, but above all custom scripts.

I haven't tested this with any custom script, but it should not have any issue, unless they overwrite the methods I aliased.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-close-the-window-automatically-when-the-quantity-of-an-item-reaches-0.37091/