HP Barrier Script, Version 1.1 (Updated 10/23/2014)

This really could be a great addition to my game! I thank you so very much for making such a script.

But I am going to have trouble already, knowing I'm using MOG's battle system. I don't mind making an bar for it... but how is the real question... Unless I accidentally skipped the answer when reading this.
What will happen if I re-cast a barrier on the target that still has a barrier in effect? Will the barrier be reset or the effect added to the existing barrier?
Depends on how you set it. You can use a notetag to have it create the barrier (which will recast it), or to restore it (which will add to it).
Depends on how you set it. You can use a notetag to have it create the barrier (which will recast it), or to restore it (which will add to it).
Thanks! I'm ooking for something like this for my project. It seems to be very easy to set up with simple note tags.
It does take a few minutes, but once you get it all set up a simple copy/paste can expand on it. For instance, in my game I have the skill Earth Barrier which uses these notetags:

<HP Barrier: Create>

<HP Barrier State: 132>

<HP Barrier Heal Multiplier: 0.8>

<cooldown: 5>

The cooldown is from Yanfly's script, so the player cannot spam it every turn. The first one tells the system we are going to create a barrier, with the HP as noted in the damage box above (also make sure it is on HP Restore, I have no idea what will happen if you don't).

The second links it to the state noted here, and tells the system you have a barrier that when state 132 is removed, remove the barrier too.

The third tells them to heal the player of 80% of the same HP that is put to the barrier (optional, but I use it as a split healing/damage prevention spell).

Then, I also tell it to add state 132 in the effects column, so the state is added. If that is missing, the barrier will probably fail.

Only weakness is the system is not set up for more than one barrier, as that would require an array, and I'm weak in how to use those in Ruby. Maybe once I learn them I can update this to add arrays and then multiple barriers will be possible.
Hope this script is still supported...

but is there a way to restore the users barrier on a damaging skill?

I have a shield pummel attack that I want to strike the foe 3 times and add more HP to the user's barrier for each strike that connects.

Maybe a script call i can use on a common event to add HP to a specific actor's barrier?
Hmmm...I think what you want will require a call common event, as you can add to the barrier via a script call. Let me investigate and see what the call is.

Edit: Here it is. I added a variable called hp_barrier to the entire Game_Battler class. A direct script call via x.hp_barrier, where x is the identifying information of whose barrier to modify should allow you to add onto it. I made the variable an accessor, so anyone should be able to modify it at their own risk.

Unfortunately, I never did figure out the command to tell you who the target was in common events, maybe someone else can help with that? However, try self.hp_barrier += amount to add in a script call via a common event, and see if it works.

Edit2: Maybe this will work too. Under the damage formula:

a.hp_barrier += amount to add; your damage formula? Afraid I can't test it right now but I think this would work.
a.hp_barrier += amount to add; your damage formula? Afraid I can't test it right now but I think this would work.
This worked! thanks bgillisp for such a speedy response to this.

Have a nice weekend!
Just a small update to the FAQ before the inevitable MV questions come in. Summary: Yes, I plan to convert it to MV, but I need to learn the language first, so it will take a while (as in, a few months).
I tested your script HP Barrier Bar, version 1.1 with Crystal Engine - Basic Module v. 1.14 or upper, but the color of the barrier doesn't show up.
The HP bar code it calls is from Yanfly's Battle Engine which is why it would not show up. I never heard of Crystal Engine when I coded this so had no way to incoporate that in.

I probably can't attempt to add in support for that for a couple weeks due to work obligations, but would need a link to Crystal Engine to even begin to attempt it. If you need it sooner than 2 - 4 weeks though someone else is free to patch it for you (The code's open so anyone can attempt it if they wish as long as ToS stay the same).
This works without yanfly battle engine
Ruby:
class Window_BattleStatus < Window_Selectable
  alias r2_barrier_draw_item draw_item
  #Draw Actor Barrier
  def draw_actor_barrier(actor, dx, dy, width = 124)
    barrier_rate = (actor.hp_barrier.to_f) / (actor.hp_barrier_max)
    draw_gauge(dx, dy, width, barrier_rate, text_color(BGHP_Barrier::Color_bar), text_color(BGHP_Barrier::Color_bar))
    change_color(system_color)
    cy = (Font.default_size - contents.font.size) / 2 + 1
    draw_text(dx+2, dy+cy, 45, line_height, "SH")
    change_color(text_color(0))
    draw_text(dx + width - 42, dy+cy, 42, line_height, actor.hp_barrier.to_i, 2)
  end #End draw_actor_barrier method
  #Alias method draw_item
  def draw_item(index)
 
    #Call aliased method
    r2_barrier_draw_item(index)
 
    #Return if index or actor nil. The orginal method already cleared everything
    #so no clear called.
    return if index.nil?
    actor = $game_party.battle_members[index]
    rect = item_rect(index)
    return if actor.nil?
    offset = 0
    if(actor.hp_barrier > 0)
   
      #This is the line that draws the barrier. If you wish to move
      #the bar, edit the line_height*2+offset to move the starting y value,
      #Edit the rect.x+2 to move the starting x value.
      draw_actor_barrier(actor, rect.x+80, line_height*index+offset, rect.width-320)
    end
  end #End draw_item method
end
Say @bgillisp in your script HP Barrier Bar, version 1.1... is there a way to see the number of the bar when you get hit or show a barrier damage number when you get hit like in the Yanfly's mv version of Absorb barrier?
It pops up the damage valuesit takes for me automatically, though just as a normal damage popup. But that is with Yanfly's Battle Core and Yanflys popups too, as I set it up to send the command to the popup from that engine.

I never really got a chance to code it with other battle engines sadly.

Original thread: https://forums.rpgmakerweb.com/threads/hp-barrier-script-version-1-1-updated-10-23-2014.32536/