This requires the tier 3 Auto Skill Triggers plugin.
The state code should be:
JavaScript:
<JS Post-Damage As Target>
if (value > 0) {
target._tookDamage = true;
}
</JS Post-Damage As Target>
<JS Post-End Action>
target._tookDamage = false;
</JS Post-End Action>
And the skill code should be:
JavaScript:
<Auto Trigger: Certain Hit Enemy>
<Auto Trigger: Physical Enemy>
<Auto Trigger: Magical Enemy>
<Auto Trigger: Item Enemy>
<JS Skill Visible>
visible = false;
</JS Skill Visible>
<JS Skill Enable>
enabled = false;
if (user.isActor()) {
const potions = [];
potions.push(7, 8, 9);
for (let i = 0; i < potions.length; ++i) {
const id = potions[i];
if ($gameParty.numItems($dataItems[id]) > 0) {
enabled = true;
break;
}
}
} else {
enabled = true;
}
</JS Skill Enable>
<JS Pre-Apply>
if (target._tookDamage) {
const potions = [];
potions.push(7, 8, 9);
for (let i = 0; i < potions.length; ++i) {
const id = potions[i];
if ($gameParty.numItems($dataItems[id]) > 0) {
const item = $dataItems[id];
if (user.isActor()) {
$gameParty.loseItem(item, 1);
}
this.setItem(id);
const text = '<CENTER>' + user.name() + ' uses \\i[' + item.iconIndex + ']' + item.name + '!';
const logWindow = SceneManager._scene._logWindow;
logWindow._lines.push(text);
break;
}
}
}
</JS Pre-Apply>
<Custom Action Sequence>
The action sequence is just
◆If:Script:BattleManager._action.subject()._tookDamage
◆Plugin Command:VisuMZ_1_BattleCore, ACSET: Setup Action Set
: :Display Action = true
: :Immortal: On = true
: :Battle Step = true
: :Wait For Movement = true
: :Cast Animation = false
: :Wait For Animation = false
◆Plugin Command:VisuMZ_1_BattleCore, ACSET: All Targets Action Set
: :Dual/Multi Wield? = false
: :Perform Action = true
: :Wait Count = Sprite_Battler._motionSpeed
: :Action Animation = true
: :Wait For Animation = false
: :Action Effect = true
: :Immortal: Off = false
◆Plugin Command:VisuMZ_1_BattleCore, ACSET: Finish Action
: :Immortal: Off = true
: :Wait For New Line = true
: :Wait For Effects = true
: :Clear Battle Log = true
: :Home Reset = true
: :Wait For Movement = true
◆
:End
Note that the state needs the "Add Skill: Auto Potion" trait for this to work. Replace 7, 8, 9 with the IDs of the potions you want to use with the effect, in the order they should be prioritised.
If you want to limit the effect as per the original T&T, you'll also need the tier 3 Limited Skill Uses plugin. Add a <Limited Uses: x> tag to the Auto Potion skill.