MV Leave Item/Skill Selection if can't use item/skill

So I'm trying to rig it so the item/skill actor selection menu outside of combat (eg. using something from the inventory) closes by itself when you cannot use the action in question. (EX. You ran out of the item, or you ran out of MP, or the skill has Yanfly's cooldown function, etc.)

Spoiler: The actor selection screen in question
bandicam 2024-11-21 21-08-20-335.png

This bugs me because you'd never know if you ran out of the item in question until you back out + it's more convenient to just leave this selection screen if you can't use the thing, since it removes an extra unnecessary click.

(Plus, I also don't want the selection to pop up for single actor parties or for "only user" scope items/skills.)

Edit: I know for skills it's "this._actor.canUse(x)", but I dunno.
I haven't tested it, but it looked pretty straightforward. Try this, lemme know if it's busted.

Code:
var origUseItem = Scene_ItemBase.prototype.useItem;
Scene_ItemBase.prototype.useItem = function()
{
    origUseItem.call(this);
    if (!this.canUse())
        this.hideSubWindow(this._actorWindow);
};
I haven't tested it, but it looked pretty straightforward. Try this, lemme know if it's busted.

Code:
var origUseItem = Scene_ItemBase.prototype.useItem;
Scene_ItemBase.prototype.useItem = function()
{
    origUseItem.call(this);
    if (!this.canUse())
        this.hideSubWindow(this._actorWindow);
};

It works! But it did invite two new problems:

* Status removing skills trigger the "leave screen" function, even if I set it to do a redundant repeatable action like "Recover MP 0".

EX. Gal uses Esca to heal herself, and it doesn't trigger the leave screen function. But when she heals someone else it does.

Dunno what's going on there.

* It's hard to tell what happened after the screen leaves. I know, a necessary evil given that clicking back is meant to be done at your own will since you're supposed to see what changed.

A little message or the screen hanging for a bit would be good enough.
* Status removing skills trigger the "leave screen" function, even if I set it to do a redundant repeatable action like "Recover MP 0".
That makes sense, since you can't remove that status from the highlighted actor again. And I don't think recover MP 0 would be a valid thing? Did you try making it add then remove another state after the one it's supposed to remove?

* It's hard to tell what happened after the screen leaves. I know, a necessary evil given that clicking back is meant to be done at your own will since you're supposed to see what changed.

A little message or the screen hanging for a bit would be good enough.
Hrm. That's more complicated. Making the game wait for stuff in a scene without an interpreter is trickier.

I'll ponder it, and someone else might jump in with a quicker solution.
That makes sense, since you can't remove that status from the highlighted actor again. And I don't think recover MP 0 would be a valid thing? Did you try making it add then remove another state after the one it's supposed to remove?

Oh, hey. Very interesting - that works. Running out of MP makes the screen pop too, so it's working perfectly there.

As for the message thing... there was a thing in VX Ace, a Himeworks script, that allowed "show text" messages to play inside of menus. But there's no such equivalent thing in MV far as I know, sadly. I'd love it to say "Ran out of MP" / "Ran out of [item]" / "Cooldown applied".
Is that the help window that's visible at the top of the screenshot? If so, you could try an approach where you set some contextual text to the help window (e.g. "Out of MP, press X to exit."), and then potentially follow that with returning to the previous menu after 30 frames or so.

Doing something within a scene after a set number of frames generally just requires a wait count managed by the update method. Window_BattleLog is an example of something that is constantly doing things with a hard wait count between tasks.

Otherwise, this feels like more of a UX-related task. Something like an on-screen display of the caster's resources could make it apparent why the cast fails. Alternatively, this problem could be why some games automatically fall back to the previous menu after any successful or failed cast.

Original thread: https://forums.rpgmakerweb.com/threads/leave-item-skill-selection-if-cant-use-item-skill.173388/