Tip and trick : second chance, need a tweak!

Hi,


I would like a tweak to Yanfly tip a trick : second chance.


I would like the code check if the target is under 30% HP, it will heal him 10% of his HP.


I understand where to change the part but I don't know the code to calculate that in %.

Code:
<Custom React Effect>
// Check to see if the party is in battle.
if ($gameParty.inBattle()) {
  // Sets the flag if the target has more than 1 HP at the time of death.
  target._secondChance = target.hp > 1;
}
</Custom React Effect>

<Custom Respond Effect>
// Check to see if the party is in battle, has the Second Chance flag, and if the target is dead with 0 HP.
if ($gameParty.inBattle() && target._secondChance && target.hp <= 0) {
  // Play the revival animation.
  target.startAnimation(49);
  // Set the target's HP to 1.
  target.setHp(1);
}
</Custom Respond Effect>
For the "below 30%" check, try


target._secondChance = target.hp < target.mhp * 0.3 && target.hp > 1;


This should ensure that the target passes the check if it is below 30% health but not dead.


For the healing, do you want to set the target's hp to 10% of its max hp


target.setHp(target.mhp * 0.10);


or adding 10% on top of its current hp?

Code:
target.gainHp(target.mhp * 0.10);
Thank you very much.


The first line didn't worked but I was able to find the formula for it.


The second line you suggested did actualy worked.


🙂
Thank you very much.


The first line didn't worked but I was able to find the formula for it.


The second line you suggested did actualy worked.


🙂



I saw a typo in my formulas for the 10% hp.


It should be target.mhp * 0.10 and not target.mhp * 10
While we are at it, I'd like my tweak on the Second Chance state...


I want my version to work no matter the HP the actor had before the fatal blow. It heals more than one HP, but will only work once.


I tried to do this, but it returns that "ressurect is not defined"

Code:
<Custom Battle Effect>
var ressurect = 1;
</Custom Battle Effect>

<Custom Respond Effect>
// Check to see if the party is in battle, has not died once, and if the target is dead with 0 HP.
if ($gameParty.inBattle() && resurrect <=  && target.hp <= ) {
  // Play the revival animation.
  target.startAnimation(49);
  // Set the target's HP to half full.
  target.setHp(target.mhp / 2);
  // Set ressurect to 0, to prevent another reraise.
  ressurect = ;
}
</Custom Respond Effect>
While we are at it, I'd like my tweak on the Second Chance state...


I want my version to work no matter the HP the actor had before the fatal blow. It heals more than one HP, but will only work once.


I tried to do this, but it returns that "ressurect is not defined"



I looked up the info about the Custom Battle Effect.


This occures at the start of a battle only if the character already has the passive state with that tag at that time.


That's why you get that error.


I haven't tested it, but you could try the following:


Give all actors an auto-passive state which only contains this notetag


<Custom Battle Effect>
target._ressurect = 1;
</Custom Battle Effect>




And then try it with this notetage inside your Second Chance state:

Code:
<Custom Respond Effect>
if ($gameParty.inBattle()) {
  if(target._ressurect > 0 && target.hp <= 0 ) {
    target.startAnimation(49);
    target.setHp(target.mhp/2);
    target._ressurect = 0;
  }
}
</Custom Respond Effect>
I looked up the info about the Custom Battle Effect.


This occures at the start of a battle only if the character already has the passive state with that tag at that time.


That's why you get that error.


I haven't tested it, but you could try the following:


Give all actors an auto-passive state which only contains this notetag



<Custom Battle Effect>
target._ressurect = 1;
</Custom Battle Effect>




And then try it with this notetage inside your Second Chance state:

Code:
<Custom Respond Effect>
if ($gameParty.inBattle()) {
  if(target._ressurect > 0 && target.hp <= 0 ) {
    target.startAnimation(49);
    target.setHp(target.mhp/2);
    target._ressurect = ;
  }
}
</Custom Respond Effect>

That worked! Thanks a lot!

Original thread: https://forums.rpgmakerweb.com/threads/tip-and-trick-second-chance-need-a-tweak.60130/