Make items cost MP when used in battle

Is there a way to do this? I mean, when in battle, items should cost MP when used. I guess something can be done with yanfly's item requirements, but sadly Idk javascript. Can someone help me with this? Thanks.

Yanfly's plugin in case that's your approach.
Item Requirements can make you require the actor to have a certain amount of MP, but it won't make them spend it.

Code:
<Custom Enable Requirement>
condition=battler.mp>=X;
</Custom Enable Requirement>

You could combine it with a notetag from Yanfly's Skill Core:
Code:
<After Eval>
user.gainMp(-X);
</After Eval>
Item Requirements can make you require the actor to have a certain amount of MP, but it won't make them spend it.

Code:
<Custom Enable Requirement>
condition=battler.mp>=X;
</Custom Enable Requirement>

You could combine it with a common event on the item to remove MP from the user afterward, but you'd have to jump through some hoops to figure out which actor used the item and use JavaScript to check whether you're in battle.

Another approach would be to use Yanfly's Skill Cost Items. Remove the actual Item command from battle, copy every item with a skill version (of an Items type), and have that skill require one of the item using the plugin settings.
Second option sounds like a lot of work, but it might be the cleanest and only possible solution for this. Thanks a lot for your answer.
Code:
<Custom Enable Requirement>
   condition = user.mp >= 0;
</Custom Enable Requirement>
youll need to make the cost be paid by putting the code somewhere. either damage or effect will do.

Item Requirements can make you require the actor to have a certain amount of MP, but it won't make them spend it.

Code:
<Custom Enable Requirement>
condition=battler.mp>=X;
</Custom Enable Requirement>

You could combine it with a notetag from Yanfly's Skill Core:
Code:
<After Eval>
user.gainMp(-X);
</After Eval>
LOL.

you beat me to it.
Second option sounds like a lot of work, but it might be the cleanest and only possible solution for this. Thanks a lot for your answer.
Yeah, I don't know if you saw my edit to my first reply, I forgot the Skill Core notetags could be used on items. Much simpler.

The only thing it doesn't address is letting the user know why they can't use the item. It will grey out the item if the actor doesn't have enough MP, but it won't tell them why or show how much they do need or anything.

If you want that, you'll have to go the Skill route.
youll need to make the cost be paid by putting the code somewhere. either damage or effect will do.


LOL.

you beat me to it.

Mechanically, it works almost perfectly fine. Thanks a lot for your answer. The only minor thing is that items that use those notetags disappear when the conditions are not met. I know that that's how the plugin works. I just think it'd be good if the item names stayed grey as any other unusable skill would. If anyone knows how to modify yanfly's plugin to do this, please tell me. But for now, it works.
Yeah, I don't know if you saw my edit to my first reply, I forgot the Skill Core notetags could be used on items. Much simpler.

The only thing it doesn't address is letting the user know why they can't use the item. It will grey out the item if the actor doesn't have enough MP, but it won't tell them why or show how much they do need or anything.

If you want that, you'll have to go the Skill route.

That's fine. The game would warn the player that all actions during battle consume a fixed amount of MP. My only worry is the one posted above. Thanks for worrying.


EDIT: I want items to only consume MP when in battle. Outside battle they should work even if the user doesn't have any MP.
i dont think the plugin will differentiate battle from field if not listed in its parameters or notetags... youll probably have to choose one way or another.

Original thread: https://forums.rpgmakerweb.com/threads/make-items-cost-mp-when-used-in-battle.148960/