Yanfly's Auto-Life and Absorbtion Barrier

Auto-Life is a tips a tricks video that requires 3 different plugins
http://yanfly.moe/2016/05/28/tips-tricks-auto-life-rpg-maker-mv/

Here are the pugins:

Battle engine core
http://yanfly.moe/2015/10/10/yep-3-battle-engine-core/

buffs and states core
http://yanfly.moe/2015/12/25/yep-50-buffs-states-core/

State Categories
http://yanfly.moe/2016/04/03/yep-89-state-categories/


Yanfly's Absorbtion Barrier
http://yanfly.moe/2016/02/13/yep-70-absorption-barrier-rpg-maker-mv/

Here is the code suggested to make auto-life work which goes into the notetag of a state.
<Category: Bypass Death Removal>

<Custom Deselect Effect>
// Check if the target's HP is 0 or is currently in the death state.
if (target.hp <= 0 || target.isDead()) {
// Play the auto-life animation on target.
target.startAnimation(49);
// Set the amount of HP recovered to 10%.
var rate = 0.10;
// Calculate the HP healed.
var heal = Math.floor(target.mhp * rate);
// Remove the Auto-Life state.
target.removeState(stateId);
// Heal the target.
target.gainHp(heal);
// Make the damage popup show for the heal.
target.startDamagePopup();
// Clear the target's results.
target.clearResult();
}
</Custom Deselect Effect>


If possible, I'd like to adjust this code to for use with 2 different skills. If anyone knows a better way I can do either of these 2 skills, please let me know.

I would like auto life to work in conjunction with absorbtion barrier. For the actor to come back to life with 1 hp and then with an absorbtion barrier of variable amount. I am able to adjust the code for the 1 hp part, but I am struggling to add the barrier.
Since the absorbtion plugin requires it's own notetag code
<custom target barrier>
value = target.mhp*0.1
</custom target barrier>
I am not sure if it's possible to add code within code like this. I tested adding the barrier code before the </Custom Deselect Effect> part of the auto-life code, but that doesn't work.


Secondly, I would like to turn the code into a 'final attack' instead of bringing the actor back to life. Which seems like it should be simple, make it do damage instead of heal?, but it's not working. Here is what I tried.

<Category: Bypass Death Removal>

<Custom Deselect Effect>
var rand = this.opponentsUnit().randomTarget();
// Check if the target's HP is 0 or is currently in the death state.
if (target.hp <= 0 || target.isDead()) {
// Remove the Auto-Life state.
target.removeState(123);
// Heal the target.
rand.gainHp(-500);
rand.startDamagePopup();
// Clear the target's results.
target.clearResult();
}
</Custom Deselect Effect>



Thanks in advance for any help

Edit: After some testing, it looks like my 'final attack' attempt is doing damage to random party member. I am still not sure how to fix it, though.
I would like auto life to work in conjunction with absorbtion barrier. For the actor to come back to life with 1 hp and then with an absorbtion barrier of variable amount. I am able to adjust the code for the 1 hp part, but I am struggling to add the barrier.
Since the absorbtion plugin requires it's own notetag code
<custom target barrier>
value = target.mhp*0.1
</custom target barrier>
I am not sure if it's possible to add code within code like this. I tested adding the barrier code before the </Custom Deselect Effect> part of the auto-life code, but that does work.
You cannot use the barrier note tags in that way, but you can use the function that the note tags call to add barriers in the original effect. target.gainBarrier(value, x) will add a barrier to the target of size value, with a turn duration of x. If you leave out the turn value, the barrier won't expire. You can use this function in your deselect effect to add a barrier of whatever size to the target when he comes back to life:
Code:
<Custom Deselect Effect>
// Check if the target's HP is 0 or is currently in the death state.
if (target.hp <= 0 || target.isDead()) {
// Play the auto-life animation on target.
target.startAnimation(49);
// Set the amount of HP recovered to 10%.
var rate = 0.10;
// Calculate the HP healed.
var heal = Math.floor(target.mhp * rate);
// Remove the Auto-Life state.
target.removeState(stateId);
// Heal the target.
target.gainHp(1);
//add barrier equal to heal (10%)
target.gainBarrier(heal)
// Make the damage popup show for the heal.
target.startDamagePopup();
// Clear the target's results.
target.clearResult();
}
</Custom Deselect Effect>
Secondly, I would like to turn the code into a 'final attack' instead of bringing the actor back to life. Which seems like it should be simple, make it do damage instead of heal?, but it's not working. Here is what I tried.

Code:
<Category: Bypass Death Removal>

<Custom Deselect Effect>
var rand = this.opponentsUnit().randomTarget();
// Check if the target's HP is 0 or is currently in the death state.
if (target.hp <= 0 || target.isDead()) {
// Remove the Auto-Life state.
target.removeState(123);
// Heal the target.
rand.gainHp(-500);
rand.startDamagePopup();
// Clear the target's results.
target.clearResult();
}
</Custom Deselect Effect>


Thanks in advance for any help

Edit: After some testing, it looks like my 'final attack' attempt is doing damage to random party member. I am still not sure how to fix it, though.
As far I as I can see for the second skill, it should probably affect an ally of the enemy of the target of the skill that triggered the state, but if it's striking an ally of the target of the skill that triggered the state, obviously that's not the case. try changing 'this.opponentsUnit().randomTarget();' to 'target.opponentsUnit().randomTarget();' instead and see if that makes a difference. You're also going to run into a similar problem to your other topic that I also replied to, where this damage will "kill" an enemy, but they won't die unless you do a 'rand.performCollapse()' after confirming the enemy has been killed by the 'final attack' damage.
Awesome, thanks. I got both working.

Edit: To clarify, changing to target.opponentsUnit().randomTarget(); allows me attack a random enemy target instead of a party member.

Would you happen to know the code I can use to target the following?

player party
enemy party
last enemy who attacked the player



Also, thanks for answering my other thread. I see now that I will need to add that code anytime I attack a random target, thanks!

Original thread: https://forums.rpgmakerweb.com/threads/yanflys-auto-life-and-absorbtion-barrier.87100/