MV Need JavaScript help setting the barrier points amount with Yanflys Absorption Barrier Plugin

This thread is in regards to needing help with accomplishing a function within http://www.yanfly.moe/wiki/Absorption_Barrier_(YEP)

However, anyone with a little JS knowledge I think should be able to help me here, as I'm pretty sure I know how to get the effect I want, but I'm lacking in syntax knowledge.

Surprisingly enough, the plugin doesn't have an option to simply set a battlers barrier points to a particular amount. What it does have, however, is the ability to read the current value of the battlers barrier points, as part of a lunatic mode script.
If I can just read the battlers barrier points, remove 1 from that variable, and then subtract the barrier points by that amount (also a function) then I should be able to set the barrier points to 1 (which is what I'm aiming to do).

In "wrong-syntax words"
<battler.barrierPoints() - read to variable X>
<variable x - 1>
<battler.loseBarrier(value X)>

As I said before, however, I'm pretty lacking in JS knowledge, especially syntax, so I'll need some help with actually making this work.
Thankyou for your help in advance ^.^
Surprisingly enough, the plugin doesn't have an option to simply set a battlers barrier points to a particular amount.
id introduce a function to do just that then. untested, but give this a shot
Code:
Game_Battler.prototype.setBarrier = function(value, turn) {
  if (value <= 0) return;
  this.initAbsorptionBarrier();
  value = Math.floor(value);
  if (turn > 0) {
    turn -= 1;
    this._turnBarrier[turn] = value;
  } else {
    this._permBarrier = value;
  }
  this._barrierAltered = true;
  this.refresh();
};
Thankyou so much! Where do I put this?
id introduce a function to do just that then. untested, but give this a shot
Code:
Game_Battler.prototype.setBarrier = function(value, turn) {
  if (value <= 0) return;
  this.initAbsorptionBarrier();
  value = Math.floor(value);
  if (turn > 0) {
    turn -= 1;
    this._turnBarrier[turn] = value;
  } else {
    this._permBarrier = value;
  }
  this._barrierAltered = true;
  this.refresh();
};
save it as a .js file and add it to your project as its own plugin, or paste it in at the end of the barrier plugin if you can remember that its there incase you have to return to it later.
I got it in, I'm sorry to ask again lol, but how do I call upon the function in-engine
the same way you'd use the battler.gainBarrier() and battler.loseBarrier(), you'd use battler.setBarrier() . its copied from gainBarrier(), so give a value argument and a optional turn argument
I'll look through and see if there's an example script for that in the help file and alter it. When I said idk the syntax stuff too well I really meant it 😅
the same way you'd use the battler.gainBarrier() and battler.loseBarrier(), you'd use battler.setBarrier() . its copied from gainBarrier(), so give a value argument and a optional turn argument
@Robro33 I'm very sorry, but reading through the help file, I can't find an argument to place "battler.gainBarrier" in, or at least, that I'm at all confident in. At least from what I've seen "battler.gainBarrier" isn't in any of the example arguments, and the section it is found in doesn't have any example arguments next to it, only the functions.

In other words, I have no way to actually use what you gave me with my current knowledge.
I'm basically flailing around in the dark here. I could go crazy with the trial and error, but I would really appreciate it if you could just send me what to put inside my notes box. I'll focus on other things until then.
Again, thankyou so much for your help ^.^
I'm confused as to why you can't use the existing notetags and some math for this.

If you want a target to have 1000 barrier points from a skill, you'd just do
Code:
<Custom Target Barrier>
value = 1000 - target.barrierPoints();
</Custom Target Barrier>

If you need to do this via script calls outside of a notetag, again, you don't need to install any new extension plugins, just do the same math. For example, to make the first actor in the party have 400 barrier points:
Code:
$gameParty.members()[0].gainBarrier(400 - $gameParty.members()[0].barrierPoints(), 0);
Thankyou. The notetag code works, however it shows damage numbers when used, which is something I didn't think of, but the change needs to be invisible to the player.

I tried the script code but it didn't seem to do anything. I placed it as a script in a common event, the only thing I changed was the "400" to be "1" instead, as that's the amount I want to set the barrier to.
I also tried replacing "gainBarrier" with "setBarrier" from Robro33's script, but still no luck. It seems to do absolutely nothing that I can notice.
I'm confused as to why you can't use the existing notetags and some math for this.

If you want a target to have 1000 barrier points from a skill, you'd just do
Code:
<Custom Target Barrier>
value = 1000 - target.barrierPoints();
</Custom Target Barrier>

If you need to do this via script calls outside of a notetag, again, you don't need to install any new extension plugins, just do the same math. For example, to make the first actor in the party have 400 barrier points:
Code:
$gameParty.members()[0].gainBarrier(400 - $gameParty.members()[0].barrierPoints(), 0);
Using math and existing notetags was my initial suggestions, but honestly anything that gets the job done is perfectly fine with me.

To fully articulate exactly what I am trying to accomplish here (which I seem to have forgotten is a must, avoid only giving the "necessary" details at all cost on this site XD)

I'm doing a tutorial, where the final attack the player makes at the end shatters the absorption barrier of the enemy. None of the attacks beforehand can shatter the barrier, so I have the barrier set to a very high amount. (I'll add barrier regen as well.)

The shattering of the barrier is scripted, so I need to set it so that the next hit from the player will shatter the barrier near the end of the tutorial (thus, setting the BP to being 1).
Naturally, this needs to be invisible to the player, they can't see the BP being set to 1 with big damage numbers.
I tried the script code but it didn't seem to do anything. I placed it as a script in a common event, the only thing I changed was the "400" to be "1" instead, as that's the amount I want to set the barrier to.
the final attack the player makes at the end shatters the absorption barrier of the enemy.
you havent shown us the common event, but if youre using the script Turan provided with the only change being the number, youre not setting the barrier of the enemy. its the barrier of an actor. change $gameParty to $gameTroop
It works! Thankyou so much ^.^
you havent shown us the common event, but if youre using the script Turan provided with the only change being the number, youre not setting the barrier of the enemy. its the barrier of an actor. change $gameParty to $gameTroop
(note: $gameParty appears twice in the string
[B]$gameParty[/B].members()[0].gainBarrier([COLOR=rgb(184, 49, 47)]1[/COLOR] - [B]$gameParty[/B].members()[0].barrierPoints(), 0);

So if anyone else stumbles upon this thread, make sure you set both to be the troop or party depending on what you want. Almost didn't realize it myself lol, so that's why I pointed it out 😉

Original thread: https://forums.rpgmakerweb.com/threads/need-javascript-help-setting-the-barrier-points-amount-with-yanflys-absorption-barrier-plugin.171840/