# Yanfly Barrier question

#### sheeshkebab1812

##### Veteran
I'm using the Yanfly's Barrier plugin and I was wondering if there is a way to make a Barrier that will regenerate per turn but only up to the amount of shield they have. So if a barrier is 50% of their hp then heal 20% of that barrier per turn.

#### oooNUKEooo

##### Veteran
set up a state to go along with the barrier in which every turn start or end it calculates what you need.

#### sheeshkebab1812

##### Veteran
set up a state to go along with the barrier in which every turn start or end it calculates what you need.
What would I put in the state and will it only affect the barrier from the armour or all barriers that the user will get?

#### oooNUKEooo

##### Veteran
state:
Code:
``````<custom turn start effect>
//get the battler hp rate
var userHP = user.hpRate();

//create variable to store the points to be regen'ed. here they start off as the max hp
var rPoints = user.mhp;

//do you math below. in this example, it restores the remaining hp rate as barrier points
rPoints = Math.floor(rPoints * userHP);

//add the barrier points. those are unexpiring points. to make then expire, change zero to a number of turns
user.gainBarrier(rPoints, 0);
</custom turn start effect>``````

all of this could have been done without creating variables, but i wanted to make things easier to understand and edit.

#### sheeshkebab1812

##### Veteran
state:
Code:
``````<custom turn start effect>
//get the battler hp rate
var userHP = user.hpRate();

//create variable to store the points to be regen'ed. here they start off as the max hp
var rPoints = user.mhp;

//do you math below. in this example, it restores the remaining hp rate as barrier points
rPoints = Math.floor(rPoints * userHP);

//add the barrier points. those are unexpiring points. to make then expire, change zero to a number of turns
user.gainBarrier(rPoints, 0);
</custom turn start effect>``````

all of this could have been done without creating variables, but i wanted to make things easier to understand and edit.
Thank you so much

### Latest Profile Posts

Well, I hope things go well tomorrow. I think I might be coming down with a cold, so gonna warm up some chicken soup and sleep.
Status too sad. Pls delete, mods. Thanks.
The most important thing to design your game for is fun. If a game isn't fun, why would anyone want to play it? Well, that and "can you play the game?". Anything else is incidental.
I just realized that I have been on this site for nearly 1/3 of my life...
How awesome is that?! Just in love with those eyes!!