How do I make a state that recovers HP upon death that removed upon 0 HP?

I am working on an RPG where there is only one character you play as, no additional party members, and I want to make an item "Phoenix" that applies a status effect that when the character get down to 0 HP, they auto recover with 25% HP, and then the status effect is removed.


I know that this is possible because an RPG Maker game called Lisa the Joyful has "Second Wind", which basically does the same thing, but as a spell. I want it as an item.

Now I do not know what engine Lisa the Joyful is, but it is RPG Maker.


I want to do something like this in VX Ace.


Is there a way to do this?


If a script is required, feel free to move this thread into script requests, but I want to see if it is possible vanilla first.


Any help would be appreciated. Please and Thank You very much!
Vanilla... I doubt it.
There are probably a few script that do this. Here is mine.
Spoiler: Herb recover
Ruby:
# ╔═══════════════════════════════════════════════╦════════════════════╗
# ║ Title: Herb Recover After Defeat              ║  Version: 1.02b    ║
# ║ Author: Roninator2                            ║                    ║
# ╠═══════════════════════════════════════════════╬════════════════════╣
# ║ Function:                                     ║   Date Created     ║
# ║   Battle Manager                              ╠════════════════════╣
# ║   Adjust process defeat                       ║    16 Dec 2020     ║
# ╚═══════════════════════════════════════════════╩════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Requires: nil                                                      ║
# ║                                                                    ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Brief Description:                                                 ║
# ║       Come back to life if you have the herb                       ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Instructions:                                                      ║
# ║   Simple script to adjust the proces defeat                        ║
# ║   Party will recover when the party has the item indicated         ║
# ║   If not then normal defeat is processed                           ║
# ║   Only for when the party is able to lose                          ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Updates:                                                           ║
# ║ 1.00 - 16 Dec 2020 - Script finished                               ║
# ║ 1.01 - 16 Dec 2020 - change                                        ║
# ║ 1.02 - 16 Dec 2020 - bug fix                                       ║
# ║ 1.02a - 10 Dec 2025 - altered for no switch                        ║
# ║ 1.02b - 18 Dec 2025 - Added sound file                             ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Credits and Thanks:                                                ║
# ║   Roninator2                                                       ║
# ║                                                                    ║
# ╚════════════════════════════════════════════════════════════════════╝
# ╔════════════════════════════════════════════════════════════════════╗
# ║ Terms of use:                                                      ║
# ║  Follow the original Authors terms of use where applicable         ║
# ║    - When not made by me (Roninator2)                              ║
# ║  Free for all uses in RPG Maker except nudity                      ║
# ║  Anyone using this script in their project before these terms      ║
# ║  were changed are allowed to use this script even if it conflicts  ║
# ║  with these new terms. New terms effective 03 Apr 2024             ║
# ║  No part of this code can be used with AI programs or tools        ║
# ║  Credit must be given                                              ║
# ╚════════════════════════════════════════════════════════════════════╝

module R2_HERB_RECOVER
    HERB_ITEM = 7     # item that will recovery party.
    HEAL = 50         # specify value to recover health. % value
             # "ME Sound File", Volume, Pitch
    SOUND = RPG::ME.new("Item", 80, 100)    # designed for ME
    # change to SE.new if you want to use SE files
end

# ╔════════════════════════════════════════════════════════════════════╗
# ║                      End of editable region                        ║
# ╚════════════════════════════════════════════════════════════════════╝

module BattleManager

  class << self
    alias_method :process_herb, :process_defeat
  end  

  def self.process_defeat
    @herb = "#{$game_party.leader.name} used Medicinal Herbs, \n#{R2_HERB_RECOVER::HEAL}%% HP was restored"
    if !@can_lose
      if $game_party.has_item?($data_items[R2_HERB_RECOVER::HERB_ITEM], false)
        R2_HERB_RECOVER::SOUND.play
        $game_message.add(sprintf(@herb, $game_party.name))
        wait_for_message
        revive_battle_members
        $game_party.battle_members.each do |actor|
          actor.hp += [(actor.mhp * R2_HERB_RECOVER::HEAL).to_i / 100 - 1, actor.mhp].min
        end
        $game_party.lose_item($data_items[R2_HERB_RECOVER::HERB_ITEM], 1, false)
        return false
      else
        process_herb
      end
    else
      process_herb
    end
  end
end
What does the "Switch ID" do? And can I set it to 0 if I do not want to use switches? Or do I need to initialize a "Switch On" at game start for it?
Actually, the custom script would be as easy to make as checking the given state ID before all states are removed by applying the death state. Then after removing states check if the state is no longer listed, and boom! Apply the 25% revitalia effect at once.
Especially if you only have one actor, you could make a troop event that triggers when your actors HP drop to 0% (you can use Span: Moment as long as you only have one actor), which would then call a common event where you can process the healing.

You would have to copy that event into each of your troops, but once you have done so you only need to edit the common event if you want to make changes to the state.

If you have multiple actors and don't want to create a troop event page for each, you can instead update the state by calling a "On Action End" common event as an effect in each skill/item (if a skill/item already calls another common event, that event has to call the "On Action End" event instead). Although this would also cause a 2 frame delay on each action.

Edit: Assuming your Phoenix state has a "State Resist: Death" feature.
What does the "Switch ID" do? And can I set it to 0 if I do not want to use switches? Or do I need to initialize a "Switch On" at game start for it?
changed the script above. No switch used
Could you make it so that an animation or at least a sound effect plays upon being resurrected from death with this script?

That would be awesome.

Please and Thank You very much.
sound effect plays
Done. code above changed. Should work, but I didn't test.

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-make-a-state-that-recovers-hp-upon-death-that-removed-upon-0-hp.181378/