Enemy HP Bars

Discussion in 'RGSS3 Scripts (RMVX Ace)' started by Vlue, Mar 20, 2012.

    Tags:
  1. Vlue

    Vlue Talent Extraordinaire Member

    Messages:
    589
    Likes Received:
    376
    Location:
    Canada
    First Language:
    English
    Basic Enemy HP Bars v2.1
    Basic Enemy HP Bars Lite v1.0.2

    by V.M.
    Introduction
    Provides basic hp gauges over enemies in battle with options for displaying percentage or absolute value of remaining hp, as well as customizing color, size, and position. And now with the option to use a custom image from file!

    New Lite version without the option for a customizable gauge, for use with Sleek Gauges

    Features
    - Plug and play with default settings
    - Customizable colors, size, position
    - Can display remaining hp as percentage or absolute value
    - Can use custom image from file

    Screenshots
    [​IMG][​IMG][​IMG]
    How to Use
    Plug and play, no editing required for default bars.
    Customization can be found right in the script with comments explaining the values.

    Script
    Convenient pastebin right... over there >> Here!
    And to play around, a image file I made for the custom image feature: [​IMG]

    Lite version: http://pastebin.com/dEkBwmPw


    FAQ
    None Available

    Credit and Thanks
    - By V.M. of D.T.
    - Free to use in any project with credit given
     
    Last edited by a moderator: Apr 8, 2014
    #1
  2. DarkWaker

    DarkWaker Villager Member

    Messages:
    9
    Likes Received:
    1
    Location:
    Earth
    First Language:
    English
    This is a great script! Awesome! :)
     
    #2
    Vlue likes this.
  3. amerk

    amerk Veteran Member

    Messages:
    1,439
    Likes Received:
    510
    First Language:
    English
    Very simple but effective. I like the setup with the rats (2nd screenshot) the best, mainly because it's based on a percentage of remaining health.
     
    #3
    Vlue likes this.
  4. Chaos17

    Chaos17 Dreamer Veteran

    Messages:
    1,253
    Likes Received:
    420
    Location:
    France
    First Language:
    French
    Hi,

    How can I move the percentage to be at the same level as the bar ?

    I want like to put the percentage at the right of the bar, next to it.
     
    Last edited by a moderator: Apr 28, 2012
    #4
  5. Vlue

    Vlue Talent Extraordinaire Member

    Messages:
    589
    Likes Received:
    376
    Location:
    Canada
    First Language:
    English
    Get the newest version and play with the values under XT_OFFSET and YT_OFFSET to move the percentage to wherever you want to.
     
    #5
    Chaos17 likes this.
  6. Chaos17

    Chaos17 Dreamer Veteran

    Messages:
    1,253
    Likes Received:
    420
    Location:
    France
    First Language:
    French
    It's good and now how can I change the font size, please ?

    I tried to change the number 24 in the script but it didn't change the size and the number was cut in half.
     
    #6
  7. Vlue

    Vlue Talent Extraordinaire Member

    Messages:
    589
    Likes Received:
    376
    Location:
    Canada
    First Language:
    English
    Below the line "percentage = enemy.hp_rate * 100" Add "self.contents.font.size = ##" Where ## is equal to the font size you want.
     
    Last edited by a moderator: Apr 29, 2012
    #7
    Chaos17 likes this.
  8. Chaos17

    Chaos17 Dreamer Veteran

    Messages:
    1,253
    Likes Received:
    420
    Location:
    France
    First Language:
    French
    Thank you very much.
     
    #8
  9. Megablackdragon31

    Megablackdragon31 Veteran Veteran

    Messages:
    215
    Likes Received:
    35
    Location:
    Argentina
    First Language:
    Spanish
    This is a great script! Thanks you very much Vlue.
     
    Last edited by a moderator: Apr 30, 2012
    #9
    Vlue likes this.
  10. Kaiser

    Kaiser Veteran Veteran

    Messages:
    1,578
    Likes Received:
    79
    First Language:
    English
    I got scared by the spider screenshot ;_; but this is a really good script, been wanting to show enemy health bars so players (or even myself) has that sense of "is it dead yet!?"
     
    #10
    Jonathang and Vlue like this.
  11. Morpheus

    Morpheus Graphic Designer Veteran

    Messages:
    111
    Likes Received:
    8
    First Language:
    english
    Primarily Uses:
    N/A
    How do I make it display the actual HP of the enemy and not percentages?

    Nevermind.
     
    Last edited by a moderator: May 22, 2012
    #11
  12. deilin

    deilin Ranger/Elementalist Veteran

    Messages:
    1,189
    Likes Received:
    173
    First Language:
    English
    I modified the script to do some extra stuff.

    if interested...

    Screens:

    [​IMG]

    [​IMG]

    [​IMG]
    Script:

    ## Basic Enemy HP Bars (DeiLin mod)
    ### Adds slightly customizable hp bars to enemies in battle. See configuration
    # below for more detail.
    ## Usage: Plug and play, no editing required.
    #------
    ##-- Script by: V.M of D.T
    #--- Free to use in any project with credit given
    #Edited by DeiLin
    #no outside bars anymore
    #Now can do MP and TP as well
    #----------------------------------
    #can exclude enemy id to show none on certain enemies by changing the 0 in
    # " and enemy.enemy_id != 0"
    # to a specific enemy id to have no bars appear
    #in my troops, this ID is what spawns, then on turn 0,
    #they morph to other enemies, and the bars appear.
    #the morph script is in the troop event to randomize troop encounter
    #also, it says "enemy" appears then what will actually appear until they do like
    #the half hide option.
    #-------------------------------
    #This script also colors your bars with similar colors.
    #--------------------------------
    class Window_HPBar < Window_Base
    #-----#
    #Sets the colors for the frame and hp bars: (Values in RGB mode, 0-255)
    #-----#
    $COLOR_OUTSIDE = Color.new( 0, 0, 0) #Border of guage
    $COLOR_INSIDE = Color.new(255,255,255) #Base of guage(between hp and border)
    $COLOR_BACK = Color.new( 50, 0, 0) #Back of guage(behind hp)
    $COLOR_HP = Color.new(250, 50, 50) #Color of HP bar
    $COLOR_HP2 = Color.new(250, 200, 200) #Second HP bar color, for gradient
    $COLOR_BACK2 = Color.new( 0, 0, 50) #Back of guage(behind mp)
    $COLOR_MP = Color.new(50, 50, 250) #Color of MP bar
    $COLOR_MP2 = Color.new(200, 200, 250) #Second MP bar color, for gradient
    $COLOR_BACK3 = Color.new( 0, 50, 0) #Back of guage(behind hp)
    $COLOR_TP = Color.new(50, 250, 50) #Color of TP bar
    $COLOR_TP2 = Color.new(200, 255, 200) #Second TP bar color, for gradient
    #-----#
    #Sets the parameters of the bar
    #-----#
    WITH_BORDER = true
    BAR_HEIGHT = 8 #Sets the height of the bar(Value of 5 or greater)
    BAR_WIDTH = 75 #Sets the width of the bar(Value of 5 or greater)
    #-----#
    #Sets the location of the bar
    #-----#
    X_OFFSET = -35 #Offsets location of bar on the x-axis
    Y_OFFSET = -35 #Offsets location of bar on the y-axis
    ABOVE_MONSTER = false #Sets whether to draw bar above or below monster
    #-----#
    #Deals with displaying hp numbers with the bar
    #-----#
    WITH_MP = true #Displays enemies MP bar
    WITH_TP = true #Displays enemies TP bar. will be right under hp if mp isn't active
    DISPLAY_NUMBER = true #True to display enemy's hp in number
    SHOW_ABSOLUTE = true #True for absolute hp, false for percentage hp
    DISPLAY_ABOVE = true #Display number above or below the hp bar
    THRESHOLD = 20 #Only show number if hp below this percentage
    #(101 to disable)
    #-----#
    def initialize
    super(0,0,544,416)
    self.z = 0
    self.opacity = 0
    end
    def update
    refresh
    end
    def refresh
    self.contents.clear
    for enemy in $game_troop.members
    if enemy.hp_rate != 0 and enemy.enemy_id != 3
    $bh = BAR_HEIGHT
    $bh = $bh + 5 if WITH_MP
    $bh = $bh + 5 if WITH_TP
    hpwidth = ((BAR_WIDTH - 4) * enemy.hp_rate).to_i
    mpwidth = ((BAR_WIDTH - 4) * enemy.mp_rate).to_i
    tpwidth = ((BAR_WIDTH - 4) * enemy.tp_rate).to_i
    if ABOVE_MONSTER
    tmpbit = Cache.battler(enemy.battler_name, 0)
    yy = (enemy.screen_y - tmpbit.height) - 35 + Y_OFFSET
    yyy = enemy.screen_y + Y_OFFSET + 4
    yyyy = enemy.screen_y + Y_OFFSET + 4 #no mp bar
    yyyy = enemy.screen_y + Y_OFFSET + 8 if WITH_MP #mp bar active
    if yy < BAR_HEIGHT + 24 then yy = BAR_HEIGHT + 24 end
    else
    yy = enemy.screen_y + Y_OFFSET
    yyy = enemy.screen_y + Y_OFFSET + 4
    yyyy = enemy.screen_y + Y_OFFSET + 4 #no mp bar
    yyyy = enemy.screen_y + Y_OFFSET + 8 if WITH_MP #mp bar active
    end
    xx = enemy.screen_x + X_OFFSET
    $bh = BAR_HEIGHT
    $bh = $bh + 4 if WITH_MP
    $bh = $bh + 4 if WITH_TP
    self.contents.fill_rect(xx, yy, BAR_WIDTH, $bh, $COLOR_OUTSIDE) if WITH_BORDER
    self.contents.fill_rect(xx+1,yy+1, BAR_WIDTH-2, $bh - 2, $COLOR_INSIDE) if WITH_BORDER
    self.contents.fill_rect(xx+2,yy+2, BAR_WIDTH-4, BAR_HEIGHT-4, $COLOR_BACK)
    self.contents.gradient_fill_rect(xx+2,yy+2, hpwidth, BAR_HEIGHT-4, $COLOR_HP, $COLOR_HP2)
    if WITH_MP
    self.contents.fill_rect(xx+2,yyy+2, BAR_WIDTH-4, BAR_HEIGHT-4, $COLOR_BACK2)
    self.contents.gradient_fill_rect(xx+2,yyy+2, mpwidth, BAR_HEIGHT-4, $COLOR_MP, $COLOR_HP2)
    end
    if WITH_TP
    self.contents.fill_rect(xx+2,yyyy+2, BAR_WIDTH-4, BAR_HEIGHT-4, $COLOR_BACK3)
    self.contents.gradient_fill_rect(xx+2,yyyy+2, tpwidth, BAR_HEIGHT-4, $COLOR_TP, $COLOR_HP2)
    end
    if DISPLAY_NUMBER
    percentage = enemy.hp_rate * 100
    if DISPLAY_ABOVE then yy -= BAR_HEIGHT + 24 end
    if SHOW_ABSOLUTE
    draw_text(xx,yy+BAR_HEIGHT,width,24,enemy.hp)
    elsif percentage < THRESHOLD
    draw_text(xx,yy+BAR_HEIGHT,width,24,percentage.to_i.to_s + "%")
    end
    end
    end
    end

    Code:
    
    
    EDIT: Re added the outside border option, and it will adjust to wether or not MP and TP are shown
     
    Last edited by a moderator: Aug 6, 2012
    #12
    Roxas162 and Puppet of Fate like this.
  13. Vlue

    Vlue Talent Extraordinaire Member

    Messages:
    589
    Likes Received:
    376
    Location:
    Canada
    First Language:
    English
    Cool beans
     
    #13
    Puppet of Fate likes this.
  14. Jetstopia

    Jetstopia Villager Member

    Messages:
    22
    Likes Received:
    1
    Location:
    Australia
    First Language:
    English
    I had trouble getting the Basic Enemy HP Bars v1.1 by V.M. (First script) to work as a Plug and Play script (I also have ZERO scripting experience and don't plan on getting involved anytime soon).

    I got a dynamic constant assignment error for line 51: for Enemy in $game_troop.members

    I did a quick look on the net and found someting about capital letters and dynamic constant assignment errors so changed it to this:

    51: for enemy in $game_troop.members

    simple matter of chaning the 'E' in Enemy to a 'e' and it worked fine after that.

    I can't get the DeiLin (second script) to work though. It has the same Enemy/enemy change that needs to be made (Line 71)

    After that I get a syntax error on line 118. After a little search I found that it is because the 'end' terms are not right or something but I haven't got it to work.

    All I wanted was an energy bar for enemies though, and the first one by V.M works fine now after that line 51 fix.

    Thanks

    EDIT:

    I have also found that when V.M's script is on you can not cancel an action in a battle window. Such as selecting 'Magic' then wanting to go back a menu screen.

    I got around this by copying the entire Scene_Battle script and pasting it above V.M's script. Far from an elegant solution but it got the job done for now.
     
    Last edited by a moderator: Sep 8, 2012
    #14
  15. Chickan117

    Chickan117 Villager Member

    Messages:
    5
    Likes Received:
    2
    First Language:
    English
    This script is fantastic :) So nice and simple.

    I was wondering; is it possible to make the enemy HP display as current / max. So 37/150 for example?

    I'm new to scripting and tried a couple of things that seemed logical without success. I couldn't even get it to add a string to the end of the number displayed! Lol
     
    #15
  16. Vlue

    Vlue Talent Extraordinaire Member

    Messages:
    589
    Likes Received:
    376
    Location:
    Canada
    First Language:
    English
    Change the line that reads:

    draw_text(xx + XT_OFFSET,yy+YT_OFFSET+BAR_HEIGHT,width,24,enemy.hp)

    To read:

    draw_text(xx + XT_OFFSET,yy+YT_OFFSET+BAR_HEIGHT,width,24,enemy.hp.to_s + "/" + enemy.mhp.to_s)
     
    Last edited by a moderator: Sep 17, 2012
    #16
    Chickan117 likes this.
  17. Chickan117

    Chickan117 Villager Member

    Messages:
    5
    Likes Received:
    2
    First Language:
    English
    Looks like I'd done all the code right... except adding .to_s (which I assume converts the values to a string).

    Thank you so much! This really helps make the game look that much better :)
     
    #17
    Vlue likes this.
  18. Jonathang

    Jonathang Level 3 Beginner EXP: 36% Veteran

    Messages:
    53
    Likes Received:
    3
    Location:
    In front of my computer, At home,Jakarta, Indonesi
    First Language:
    English
    Does this script work for the Side battle system? (Showing HP % left)

    Hm it doesn't seem to work because of an error in line 80....

    Is there a script like this for the Side battle system script?
     
    Last edited by a moderator: Nov 25, 2012
    #18
  19. Vlue

    Vlue Talent Extraordinaire Member

    Messages:
    589
    Likes Received:
    376
    Location:
    Canada
    First Language:
    English
    That was a weird coincidence, I spend the morning rewriting the entire thing and someone posts! Oh well.

    New version up, 2.0, that I've completely rewritten. Just all around better and easier (hopefully) to use, as well as a nice little feature to use a custom image file as an hp bar!

    And just as it happens I made a very simple one just for random use: http://i1175.photobu...e/Custom_HP.png

    As for your error Jonathang, I'm not sure. If you tell me what the error says however, I can tell you if it's fixable or not (Or you can grab the new version and see if that helps)
     
    #19
    Jonathang likes this.
  20. Jonathang

    Jonathang Level 3 Beginner EXP: 36% Veteran

    Messages:
    53
    Likes Received:
    3
    Location:
    In front of my computer, At home,Jakarta, Indonesi
    First Language:
    English
    Whoops, used it in the wrong RPM engine..... I used it in XP, sorry, it worked for ace BTW. Love the script :D , and sorry for my carelessness....

    EDIT: Hello Vlue, I think I can think of a new feature for the script (Sorry if it has been implemented). You see, in my game when an enemy dies, they can revive. I want the revived enemies to have the bar, but the bar doesn't appear... Again, I'm sorry if it was actually a feature already, but if its not, I'd appreciate it if you added the feature. Thank you for your attention. :)
     
    Last edited by a moderator: Dec 2, 2012
    #20
    Vlue likes this.

Share This Page