RMMV Using Yanfly's Second Chance Trick with HP Degeneration (ie. Poison)

maliyana

Veteran
Veteran
Joined
Jun 6, 2017
Messages
96
Reaction score
20
First Language
English
Primarily Uses
RMMV

In my game, I have "Knockout by Slip Damage" turned on, but also I have a state that prevents big attacks from lowering a characters HP below 75%, 50%, 25% and 1 point.

JavaScript:
<Custom Battle Effect>
if ($gameParty.inBattle()) {
  target._checkUno = 1;
  target._checkDos = 1;
  target._checkTres = 1;
  target._checkCuatro = 1;
}
</Custom Battle Effect>

<Custom React Effect>
if ($gameParty.inBattle()) {
  target._struggleOne = target.hp > (target.mhp*0.75);
  target._struggleTwo = target.hp > (target.mhp*0.50);
  target._struggleThree = target.hp > (target.mhp*0.25);
  target._struggleFinale = target.hp > 1;
}
</Custom React Effect>

<Custom Respond Effect>
if ($gameParty.inBattle() && target._struggleOne && target.hp <= ((target.mhp*0.75)-1) && target._checkUno == 1) {
  target.startAnimation(124);
  target.setHp(Math.floor(target.mhp*0.75));
  target._checkUno = 0;
}
else if ($gameParty.inBattle() && target._struggleTwo && target.hp <= ((target.mhp*0.50)-1) && target._checkDos == 1) {
  target.startAnimation(124);
  target.setHp(Math.floor(target.mhp*0.50));
  target._checkDos = 0;
}
else if ($gameParty.inBattle() && target._struggleThree && target.hp <= ((target.mhp*0.25)-1) && target._checkTres == 1) {
  target.startAnimation(124);
  target.setHp(Math.floor(target.mhp*0.25));
  target._checkTres = 0;
}
else if ($gameParty.inBattle() && target._struggleFinale && (target.hp <= 0) && target._checkCuatro == 1) {
  target.startAnimation(124);
  target.setHp(1);
  target._checkCuatro = 0;
}
</Custom Respond Effect>

However, if a character is inflicted with a Status Ailment, or if they use a skill that costs HP, the State is ignored. Any suggestions?
 

Trihan

Speedy Scripter
Veteran
Joined
Apr 12, 2012
Messages
5,086
Reaction score
4,714
First Language
English
Primarily Uses
RMMZ
Put in an if statement that checks for the target having the state, and adjust the damage accordingly?
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
5,526
Reaction score
3,591
First Language
English
Primarily Uses
RMMV
According to the Buffs and States documentation, Custom React and Respond effects happen when a battler is selected as a target.
Since neither taking poison damage nor that user using a skill that takes their own HP involves them being selected as a target by someone else, those state codes won't be executed at those times.

You would need to add code into your poison state that checks for the presence of this one, and similarly re-code skills that have an HP cost.
 

maliyana

Veteran
Veteran
Joined
Jun 6, 2017
Messages
96
Reaction score
20
First Language
English
Primarily Uses
RMMV
According to the Buffs and States documentation, Custom React and Respond effects happen when a battler is selected as a target.
Since neither taking poison damage nor that user using a skill that takes their own HP involves them being selected as a target by someone else, those state codes won't be executed at those times.

You would need to add code into your poison state that checks for the presence of this one, and similarly re-code skills that have an HP cost.

Any suggestions on code I can use to get the self damaging skill to check for the presence of the Second Chance status effect? Admittedly, I was gonna make it into a move that targeted the user primarily, but Yanfly's AI Core didn't like it very much.

Also, I know it probably wasn't the most practical thing, but I wound up reworking the poison state to cast a skill that does damage whenever the affected character attacks anyone who isn't themself. The only issue now is that they take multiple hits from the poison if they target more than one enemy.

2021-04-05 22_59_13-Database.png2021-04-05 22_59_27-Database.png

JavaScript:
<Custom Apply Effect>
if ($gameParty.inBattle()) {
target._poison1 = 0;
}
</Custom Apply Effect>

<Custom Initiate Effect>
if (user !== target) {
target._poison1 = 1;
}
</Custom Initiate Effect>

<Custom Conclude Effect>
if (target._poison1 == 1) {
var skill = 950;
var target = -1;
target._poison1 = 0;
BattleManager.queueForceAction(user, skill, target);
}
</Custom Conclude Effect>
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
5,526
Reaction score
3,591
First Language
English
Primarily Uses
RMMV
Any suggestions on code I can use to get the self damaging skill to check for the presence of the Second Chance status effect?
Yanfly's Skill Core allows you to define a custom HP cost, inside of that you can put code that makes the cost 0 if they have the appropriate state on.
Also, I know it probably wasn't the most practical thing, but I wound up reworking the poison state to cast a skill that does damage whenever the affected character attacks anyone who isn't themself.
Why do something convoluted with another skill instead of just doing damage? And put it in a Custom Turn End instead of attaching it to their attacks.
Inside of that, say if the actor is not affected by your second chance state, it takes an appropriate amount of poison damage.
 

maliyana

Veteran
Veteran
Joined
Jun 6, 2017
Messages
96
Reaction score
20
First Language
English
Primarily Uses
RMMV
Yanfly's Skill Core allows you to define a custom HP cost, inside of that you can put code that makes the cost 0 if they have the appropriate state on.
The issue here is that I wouldn't want the Second Chance skill to make the user immune to taking damage from the specific skill.

Why do something convoluted with another skill instead of just doing damage? And put it in a Custom Turn End instead of attaching it to their attacks.
Inside of that, say if the actor is not affected by your second chance state, it takes an appropriate amount of poison damage.
It's more complicated, yes, but I like the poison animation each time it takes effect. Also, it's technically a solution to the problem. The Custom Turn End doesn't work well, as in order to get the code above in the Conclude Effect notetag to function, I need an Initiate Effect. Otherwise, the poison damage loops until the infected character dies.

But now, whenever a poisoned character attacks a target and reduce their HP to 0, the "forceaction" that triggers poison damage skill interrupts the target dying, so they do not get knocked out until someone who isn't poisoned attacks them.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
5,526
Reaction score
3,591
First Language
English
Primarily Uses
RMMV
The issue here is that I wouldn't want the Second Chance skill to make the user immune to taking damage from the specific skill.
Then I don't understand what you want. In your original post, you asked:
if they use a skill that costs HP, the State is ignored. Any suggestions?
That says you you don't want them to lose HP for using that skill if they have Second Chance on, which is what I told you how to do. So...which way it is?
The Custom Turn End doesn't work well, as in order to get the code above in the Conclude Effect notetag to function, I need an Initiate Effect. Otherwise, the poison damage loops until the infected character dies.
Those things don't have anything to do with each other. You would replace the normal functionality of your poison state (the options chosen in the Effects list) with a Custom Turn End notetag that checks for Second Chance.
But now, whenever a poisoned character attacks a target and reduce their HP to 0, the "forceaction" that triggers poison damage skill interrupts the target dying, so they do not get knocked out until someone who isn't poisoned attacks them.
And that would no longer happen. You could also keep the setup you made and program it using Yanfly's Action Sequences, which again allow you to check for if the target is supposed to be dead before applying the new effect.
 

maliyana

Veteran
Veteran
Joined
Jun 6, 2017
Messages
96
Reaction score
20
First Language
English
Primarily Uses
RMMV
Then I don't understand what you want. In your original post, you asked:

That says you you don't want them to lose HP for using that skill if they have Second Chance on, which is what I told you how to do. So...which way it is?
There is a misunderstanding. What my second chance state does is that it prevents those who possess it from essentially taking full damage in some cases. Specifically, if the user has 100 max HP at the beginning of a battle, but take a hit that does 3000 damage, they will only take 25 damage and drop to 75 HP. If they heal to full health, and again take a 3000 damage hit, their HP will drop to 50 HP, thanks to variables that I put into place. This repeats for 25 HP and 1 HP, and then they are KO'd.

This works in most cases, but in the case of someone with this state using a skill that costs HP, or being afflicted with a state like poison, it doesn't function correctly. Specifically, if they have 100 HP at the start of the battle, and the skill that costs HP or poison does more than 25 damage, they WILL take more than 25 damage. What I want is for them to only take 25 in this case also.

I've tried using the normal poison state with this notetag:
JavaScript:
<Custom Apply Effect>

if ($gameParty.inBattle()) {

  target._checkUno = 1;

  target._checkDos = 1;

  target._checkTres = 1;

  target._checkCuatro = 1;

}

</Custom Apply Effect>





<Custom React Effect>

if (target.isStateAffected(71)) {

  target._struggleOne = target.hp > (target.mhp*0.75);

  target._struggleTwo = target.hp > (target.mhp*0.50);

  target._struggleThree = target.hp > (target.mhp*0.25);

  target._struggleFinale = target.hp > 1;

}

</Custom React Effect>



<Custom Turn End Effect>
if (target.isStateAffected(71) && target._struggleOne && target.hp <= ((target.mhp*0.75)-1) && target._checkUno == 1) {
  target.startAnimation(124);
  target.setHp(Math.floor(target.mhp*0.75));
  target._checkUno = 0;
}
else if (target.isStateAffected(71) && target._struggleTwo && target.hp <= ((target.mhp*0.50)-1) && target._checkDos == 1) {
  target.startAnimation(124);
  target.setHp(Math.floor(target.mhp*0.50));
  target._checkDos = 0;
}
else if (target.isStateAffected(71) && target._struggleThree && target.hp <= ((target.mhp*0.25)-1) && target._checkTres == 1) {
  target.startAnimation(124);
  target.setHp(Math.floor(target.mhp*0.25));
  target._checkTres = 0;
}
else if (target.isStateAffected(71) && target._struggleFinale && (target.hp <= 0) && target._checkCuatro == 1) {
  target.startAnimation(124);
  target.setHp(1);
  target._checkCuatro = 0;
}
</Custom Turn End Effect>

However, it seems to not work consistently. It seems to stop the damage form dropping below 75%, but beyond that, the character takes more damage than they are supposed to. I think it is because the poison does damage during the unaffected character's turns, so the notetag is sometimes ignored.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
5,526
Reaction score
3,591
First Language
English
Primarily Uses
RMMV
There is a misunderstanding...Specifically, if they have 100 HP at the start of the battle, and the skill that costs HP or poison does more than 25 damage, they WILL take more than 25 damage. What I want is for them to only take 25 in this case also.
And that's exactly what the solution I gave you with a Custom HP Cost would fix, so I don't understand why you said it wasn't what you wanted. If there's a misunderstanding, it's not on my part :wink:

You'd take your HP Cost out of the skill info and replace it with a Custom HP Cost notetag that includes calculations to determine how much HP it costs them for whatever stage they're at of Second Chance (or not having it at all).
I've tried using the normal poison state with this notetag:
You don't want that. I feel like you're copying stuff from Second Chance to Poison without understanding what it does. A Custom React Effect runs when the person with the state is targeted in battle - there's no reason you want your poison status to do anything then. I don't see why you would want it to set any variables on the actor when it's applied, either. Having those notetags is going to screw up how your Second Chance works entirely. The only thing poison does is at the end of the turn.

And at that point you wouldn't be referencing "target" because the actor isn't in the process of being attacked, and so isn't a target - you'd be using "user".

So take out those other tags, replace target with user, and test from there.
 

maliyana

Veteran
Veteran
Joined
Jun 6, 2017
Messages
96
Reaction score
20
First Language
English
Primarily Uses
RMMV
@ATT_Turan So this is what I have as the notetag now:

JavaScript:
<Custom Turn End Effect>
user.gainHp(-user.mhp*0.1);
user.startDamagePopup();
if (user.isStateAffected(71) && user._struggleOne && user.hp <= ((user.mhp*0.75)-1) && user._checkUno == 1) {
  user.startAnimation(124);
  user.setHp(Math.floor(user.mhp*0.75));
  user._checkUno = 0;
}
else if (user.isStateAffected(71) && user._struggleTwo && user.hp <= ((user.mhp*0.50)-1) && user._checkDos == 1) {
  user.startAnimation(124);
  user.setHp(Math.floor(user.mhp*0.50));
  user._checkDos = 0;
}
else if (user.isStateAffected(71) && user._struggleThree && user.hp <= ((user.mhp*0.25)-1) && user._checkTres == 1) {
  user.startAnimation(124);
  user.setHp(Math.floor(user.mhp*0.25));
  user._checkTres = 0;
}
else if (user.isStateAffected(71) && user._struggleFinale && (user.hp <= 0) && user._checkCuatro == 1) {
  user.startAnimation(124);
  user.setHp(1);
  user._checkCuatro = 0;
}
</Custom Turn End Effect>

The 'Traits' are empty.

And it starts out working perfectly, but for some reason, it expires 3 turns before it is supposed to. Initially, I had it reduce the HP by 60% per turn for testing purposed. So by around turn 3 of being poisoned, the character's HP would drop to 0 only for the code to revive them at 50%, which resulted in the poison state being removed prematurely.

So I assumed lowering it the degeneration to 10% would solve the problem, but for some reason, it is prematurely removed when the user's HP is at 50%.
 
Last edited:

maliyana

Veteran
Veteran
Joined
Jun 6, 2017
Messages
96
Reaction score
20
First Language
English
Primarily Uses
RMMV
Accidental doublepost
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
5,526
Reaction score
3,591
First Language
English
Primarily Uses
RMMV
This seems like a bad way to go about it, as you are potentially killing the character, doing everything that results from that, removing all of their states, then putting them back. Why not just calculate how much damage they should take before applying it?
Code:
var damage=user.mhp*0.6; // Or whatever
if (user.isStateAffected(71) && user._struggleOne && user.hp-damage<=user.mhp*0.75 && user._checkUno==1)
{
    damage=user.hp-(user.mhp*0.75);
    user.startAnimation(124);
    user.gainHp(-damage);
    user.startDamagePopup();
    user._checkUno=0;
}
What's the purpose of checking for the damage to leave them at 75% hit points minus one? I left that out, but if it matters to you for some reason, just stick it back.
So I assumed lowering it the degeneration to 10% would solve the problem, but for some reason, it is prematurely removed at 50% in this case as well.
I don't see anything here that would affect the number of turns the state lasts, if you're not killing the actor off. Try my suggestion, see if it's still a problem.
 

maliyana

Veteran
Veteran
Joined
Jun 6, 2017
Messages
96
Reaction score
20
First Language
English
Primarily Uses
RMMV
This seems like a bad way to go about it, as you are potentially killing the character, doing everything that results from that, removing all of their states, then putting them back. Why not just calculate how much damage they should take before applying it?
Code:
var damage=user.mhp*0.6; // Or whatever
if (user.isStateAffected(71) && user._struggleOne && user.hp-damage<=user.mhp*0.75 && user._checkUno==1)
{
    damage=user.hp-(user.mhp*0.75);
    user.startAnimation(124);
    user.gainHp(-damage);
    user.startDamagePopup();
    user._checkUno=0;
}
What's the purpose of checking for the damage to leave them at 75% hit points minus one? I left that out, but if it matters to you for some reason, just stick it back.

I don't see anything here that would affect the number of turns the state lasts, if you're not killing the actor off. Try my suggestion, see if it's still a problem.
This code works perfectly! Thank you for all of your help!
 

Latest Threads

Latest Profile Posts

I've never felt prouder of my little game!! *o*
DamageEvil_2.png added!
index.php

Forum statistics

Threads
125,674
Messages
1,172,728
Members
164,799
Latest member
PurpleClouds
Top