# 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

Fun question - how do you manage the scope of your projects? All of my projects seem to balloon until they pop and they are suddenly nonexistent!
no I did not just have to write a song three different times because my music software doesn't support tempo changes!!
I WILL defeat this demonic USB connection notification bug

Mike trying to dodge the Memory Pawns invading Bantam Street. I like how the filters I used on the map almost make it look like the street is wet in a sense.
Come watch as Studio Blue plays OMORI live on the final RPG Maker Critiques stream!