Chug! Chug! Chug! (multiple potions at once)

Hello fellow forum-goers! I have a character who generates items (potions) by using specific skills. I'd like to create a skill that has variable effects based on how many items are used at once.

The skill I'm trying to make is a self heal that uses up to 4 of these items at a time. At 1 it heals 25%, at 2 it heals 50%, at 3 it heals 75% and at 4 it heals 100%.

Currently it calls a Common Event (cunningly called Potions) that checks the number currently held. If 4 it adds a State called Heal 100% that adds the Ex-Parameter HP Regeneration +100% and then removes -4 potions. Each item less than 4 reduces the healing by 25% (each a different State with the Ex-Parameter HP Regeneration + whatever %).

It works. Kind of. The problem is the healing hits at the very end of the turn, because it's a Regen effect. Does anyone know how to do this so the healing hits immediately? Another problem is it can be used even if there are 0 potions in the inventory (it currently pops up a text window that says it can't be used, oops).

There has to be an easier way to do this, right? I'd love to hear any ideas ya'll have. Thanks in advance! potions.png
OK, several things.

1) code:
instead of using a state, you could use the change HP command directly in the common event.
that would allow you to calculate how many HP are recovered by control variable (read maxHP, divide by four, multiply by number of potions used).

2) execution at end of turn
I'm not entirely sure if this is still true for the time based variant of MZ battlesystem, but in all turn based battles in the past the common events triggered by skills have always been executed at the end of the turn. to change that you needed a plugin.

3) skill cost
by default the engine can't handle items as skill cost, but there have always been plugins to add that functionality.
and you need that to prevent the skill from being used if there are no potions available.
you could also handle it differently.

variable 14 = potions in inventory.
if potions >= 4
potions -4
heal party 100%
else
if potions >= 3
potions -3
heal 75%
else etc

if potions <= 0
you dont have any potions left.

but like andar said, it based on end of turn, unless you can do an instant cast
to use the skill directly.
A slightly different way is to check if both the target is missing HP and there are potions. If so, heal 25%, remove a potion, and loop back, otherwise break the loop.
I dont have MZ, but I need to see if there is a way to check actor
HP < 0.75 for first check, before checking the potions.

but another question would be also, do you want to check the average
check of the HP of all actors in parts or seperately?

as you heal the entire party.
Thanks, everyone! That gives me a lot of options to try. I'll spend some time this afternoon and see what I can get to work.
Ultimately, you'll need something like VisuStella Skills and States to have a custom usable condition on the skill if you want it to be unusable if there are 0 potions.

As for the rest...I would just do it all directly in the damage formula. You can do this very concisely using JavaScript and it would happen when you execute the skill, not afterward from a common event.

Code:
a.mhp*(.25*Math.min(4, $gameParty.numItems($dataItems[potionId])))
where potionId is the ID of your potion item.

Then you just remove up to 4 potions in a common event.
Ultimately, you'll need something like VisuStella Skills and States to have a custom usable condition on the skill if you want it to be unusable if there are 0 potions.

As for the rest...I would just do it all directly in the damage formula. You can do this very concisely using JavaScript and it would happen when you execute the skill, not afterward from a common event.

Code:
a.mhp*(.25*Math.min(4, $gameParty.numItems($dataItems[potionId])))
where potionId is the ID of your potion item.

Then you just remove up to 4 potions in a common event.
Damage formulas. Is there anything they can't do?

Thanks, everyone! Thanks to a combination of your comments and the Skills/States plugin I think I've got it working. Appreciate all of your help and time!

Original thread: https://forums.rpgmakerweb.com/threads/chug-chug-chug-multiple-potions-at-once.151285/