Yanfly's Absorbtion Barrier

Hello, I am using RPG Maker MV.

I want to make one of my healers use absorbtion barrier's instead of actually healing HP.

Correct me if I am wrong, but I believe I can use the following notetag and change the bold and underlined part to any formula I wish. (Ex. a.mat * 2)

<Custom Target Barrier>
value = target.level;
</Custom Target Barrier>



But, then the player would be able to spam the spell and continue to add an absorbtion barrier forever.
My issue is how do I give the barrier a cap, at say the target HP, or target HP + target mdf?
Might try:
(Java) (lunatic)
PHP:
<Custom Target Barrier>
if (target.level > 100) {  //max 100 in this case
   var barrierHP = 100;
   }
else {
   var barrierHP = target.level;
   };
value = barrierHP;
</Custom Target Barrier>

I havn't tried this code, just threw it together in 10 min.
Thanks for the reply!
I see how this works, I think.

It limits the amount of absorbtion barrier of the single cast by the desired amount.

<Custom Target Barrier>
if ((a.mat*120)> target.mhp) { //max 100 in this case
var barrierHP = target.mhp;
}
else {
var barrierHP = (a.mat*120);
};
value = barrierHP;
</Custom Target Barrier>

So it uses the formula (a.mat*120) to calculate the potential barrier can be, but limits the amount of barrier that can be given by that cast to the target's max hp.
This is kind of what I was looking for. The problem I have is that the player could then cast this spell forever, and accumulate the barrier forever. It just has a limit per cast.

What I was hoping for is that when I cast the spell, if a single cast reach the limit of the target max hp, then a second cast would add no additional barrier, as I would like the barrier to be hard capped at a level that I can determine. So, the player is not able to spam the ability forever continuing to increase the barrier.

I hope that makes sense.
Think i understand:
PHP:
<Custom Target Barrier>
   if ((a.mat*120) > target.mhp) {
      var barrierHP =  (target.mhp - target.barrierPoints());
      }
   else {
      var barrierHP = ((a.mat*120) - target.barrierPoints());
   };
value = barrierHP;
</Custom Target Barrier>
This should mean that if the hero already has a barrier with 20 points and maxhp of 100, the barrier spell will add 100 - 20 = 80 points to the barrier. The more barrier the hero has, the less the code adds.

Still, I am not at home right now so i can't test this code.
Thanks again. This isn't quite what I am looking for, but I could make this work if needed. Although, it is entirely possible that I don't know how to change the suggested code properly to meet my needs.


I was hoping to have 2 variables; The strength of the absorbtion barrier and the max amount the absorbtion barrier can be.

The way it currently works, if the barrier strength is 1,000 but the target only has 450 mhp, then the barrier will be applied at 450 points. If it cast again, it will add 0 barrier points.
It will work the same way if the barrier strength is 450 and the max hp is 450. 450 will be added one the first cast, and 0 will be added on the next cast.
These 2 aspects are exactly what I want.


However, if the barrier strength is 350, and the target has a max hp of 450, then the barrier will be capped at 350. If it is cast again, 0 points will be added to the barrier. So if the barrier strength is less than the target hp, then the barrier strength becomes the cap.

In this case, I was hoping that 350 would be added in the first cast, then 100 barrier points will be added in the second cast, bringing the barrier to the cap.
If the barrier strength were only 45, with the target max hp being 450, I would like to be able to cast the spell 10 times in a row adding 45 each time to reach the cap of 450. But, then an 11th cast would add 0 points as the cap would be met.



But, I would like to be able to change the barrier strength with a formula of my choosing, as I would like different ranks of spells to add different amounts with a single cast.

And I would like the cap, the max amount of absorbtion barrier, to be adjustable with a formula also. Because I am not sure yet what will be best to cap at. Target hp may be too high, so I may need to adjust it accordingly.
PHP:
<Custom Target Barrier>
  var barrierHP = 45;
  var barrierMax = target.mhp;
  if (barrierMax >= (target.barrierPoints() + barrierHP) {
    value = barrierHP;
  else {
    value = (barrierMax - target.barrierPoints());
};
</Custom Target Barrier>
in this 45 is the number of points added to the barrier, unless the barrier is getting close to the value of barrierMax.
Thanks for the help, you've helped me to understand how it works.

So I think I know what I need mathematically, but I am unsure on if my code is correct. I don't understand why there is sometimes an open close bracket at the end, but i added some. Not sure if that is right.


So I need to use an if / else statement saying;



If (target's max hp - current absorbtion barrier) >= skill strength
then use skill strength

else
use (target's max hp - current absorbtion barrier)



I'm not home to test it at the moment, so if someone could look over my code, and let me know if I have it right, otherwise I can test it later.



<Custom Target Barrier>
if((target.mhp - target.barrierPoints) >= 300()) {
var barrierHP = 300;
}
else {
var barrierHP = (target.mhp - target.barrierPoints());
};
value = barrierHP;
</Custom Target Barrier>


Yea.. This code doesn't work :/
Would someone be able to tell me what is wrong with it based on the mathematical if else function I need.
Thanks!
Assuming what you want is:
A skill that gives an ally barrier.
but the max barrier the ally can get is equal to its max hp.
here's what i did:

<custom target barrier>
if (target.barrierPoints(-1) == null)
{
var currentbarrier = 0;
}
else
{
var currentbarrier = target.barrierPoints(-1);
}

var maxbarrier = (target.mhp - currentbarrier) * 1; \\change '1' to match your skill strength. (ex. 0.6 will give barrier = 60% of target maxhp)

value = maxbarrier;
</custom target barrier>
Thanks for the help, you've helped me to understand how it works.

So I think I know what I need mathematically, but I am unsure on if my code is correct. I don't understand why there is sometimes an open close bracket at the end, but i added some. Not sure if that is right.


So I need to use an if / else statement saying;



If (target's max hp - current absorbtion barrier) >= skill strength
then use skill strength

else
use (target's max hp - current absorbtion barrier)



I'm not home to test it at the moment, so if someone could look over my code, and let me know if I have it right, otherwise I can test it later.



<Custom Target Barrier>
if((target.mhp - target.barrierPoints) >= 300()) {
var barrierHP = 300;
}
else {
var barrierHP = (target.mhp - target.barrierPoints());
};
value = barrierHP;
</Custom Target Barrier>
Yea.. This code doesn't work :/
Would someone be able to tell me what is wrong with it based on the mathematical if else function I need.
Thanks!

remove the 2 () after 300 and it looks good.
it should be 300 not 300().
Assuming what you want is:
A skill that gives an ally barrier.
but the max barrier the ally can get is equal to its max hp.
here's what i did:

<custom target barrier>
if (target.barrierPoints(-1) == null)
{
var currentbarrier = 0;
}
else
{
var currentbarrier = target.barrierPoints(-1);
}

var maxbarrier = (target.mhp - currentbarrier) * 1; \\change '1' to match your skill strength. (ex. 0.6 will give barrier = 60% of target maxhp)

value = maxbarrier;
</custom target barrier>

First of all, thanks for posting and helping out!

This code has interesting results.
For my testing, the target.mhp was 450, and I used a 0.5 coefficient for my skill strength.

The first cast, I gained a 225 barrier, as expected. (450 - 0) * 0.5 = 225
But, the second cast added only 112 to the barrier. Because (450 - 225) * 0.5 = 112.5
Third cast adds 56
Fourth cast adds 28

This is assuming no damage is taken. So, the hard cap of target.mhp can never be reached.
But, by adding diminishing returns in this way, it does solve the problem of spamming the skill forever and getting an unlimited barrier amount. This is interesting and may have uses.






But, looking at your code, Kiryuu, I thought that the problem may lie with defining target.barrierPoints = 0
So I tried combining the codes.

<custom target barrier>
if (target.barrierPoints(-1) == null)
{
var currentbarrier = 0;
}
else
{
var currentbarrier = target.barrierPoints(-1);
}
var maxbarrier = (target.mhp);
if((target.mhp - currentbarrier) >= 300) {
var barrierHP = 300;
}
else {
var barrierHP = (target.mhp - currentbarrier);
};
value = barrierHP;
</Custom Target Barrier>

For anyone who wants to use this.
This code works to have 2 independent variables:
The max barrier cap which is show in the code as bold. You should be able to change this to anything you want. This is set as target.mhp
And then the barrier strength which is show in the code as underlined. You should be able to change this to anything you want, even using complex healing formulas. This is set as 300 for testing.

Thanks for all your help, digger6, and Kiryuu!!
Sorry for double posting, but it's been a while since I did and I have a new question that may be missed if I simply edit the prior post.


I am trying to make a barrier regen skill that works the same way as the above single cast skill. I tried the code below onto a state, and made skill to place the state. For the code, I simply changed the start and the end to say <Custom Barrier Regen>

I'm wondering if someone who knows coding can help me figure out what is wrong with this?
Thanks!

<Custom Barrier Regen>
if (target.barrierPoints(-1) == null)
{
var currentbarrier = 0;
}
else
{
var currentbarrier = target.barrierPoints(-1);
}
var maxbarrier = (target.mhp);
if((target.mhp - currentbarrier) >= 350) {
var barrierHP = 350;
}
else {
var barrierHP = (target.mhp - currentbarrier);
};
value = barrierHP;
</Custom Barrier Regen>
Sorry for no reply, have been svamped at work.
Will look into this on saturday.
No need to apologize. I appreciate any help.

Original thread: https://forums.rpgmakerweb.com/threads/yanflys-absorbtion-barrier.86208/