How do I make a player character come back to life automatically (sometimes) <Resolved>

Hey all!

So, here's the situation: I want to create an equip item that gives a player character a small chance to, upon death, come back to life automatically with full HP. Additionally, I need this to function in the event that the party only has one character, living or dead, in it, without combat/the game ending during the revival process due to no living allies.

As a stretch goal, I would like to be able to customise how much HP the character gets when they revive, and also apply a status effect upon revival, such as "prevent additional revival this turn."

Is this something that can be done in MV as standard? Is there a plugin that exists already which can do this? I tried looking for something like this in prior threads but found nothing conclusive.

Any help at all would be greatly appreciated. Thanks for reading and have a good tuesday!
@marbeltoast Here's a Yanfly tips and tricks video about how to do something very much like what you're asking...if not entirely. Take a look! 🙂

Best!

Sincerely,
Well, I tried the method that Yanfly demonstrates in the video, but something appears to have gone wrong. Here's my code:
Code:
<Custom Apply Effect>
if (target.isActor() ) {
  var trinket = $dataArmors[50] ;
  if (target.hasArmor(trinket) ) {
    target.discardEquip(trinket) ;
    var hp = Math.floor(target.mhp) ;
    target.gainHP(hp) ;
  }
}
</Custom Apply Effect>
It's returning that ever so helpful "undefined is not a function" error message. If it's going to be that obtuse, it might as well just say "NO."

If it's not obvious, I'm not fluent in javascript. Anybody able to explain where I went wrong?
Do you have the latest Buff & State Core plugin?
Code is case sensitive: use gainHp instead of gainHP. The rest looks OK to me~ 🙏
Code is case sensitive: use gainHp instead of gainHP. The rest looks OK to me~ 🙏
That was indeed the problem! It works! Thanks a bundle chums!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/how-do-i-make-a-player-character-come-back-to-life-automatically-sometimes-resolved.108995/