Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

I NEED A SIMPLE SCRIPT EDIT im RGSS illiterate

so ive tried to put gradient hp and sp bars in battle but with the script i got this is what it looks like...
untitled.PNG
how can change the size help please i know its probably really simple but can some one please tell me how to change it or edit it themselves...script:
Code:
# Changes to the bitmap class to add a function which can draw gradient bars

class Bitmap

  

  # Draw a rectangle with a gradient color shift from color1 to color2

  # Goes from left to right, or top to bottom if vertical is set

  def draw_gradient_rect(x, y, width, height, color1, color2, vertical=true)

    # Determine what will limit the draw

    limit = vertical ? height: width

    for i in 0..limit

      # Calculate the color1 multiplier for its color

      mul = (limit - i).to_f / limit

      # Calculate the new color for this part of the gradient

      color = Color.new(

        mul * (color1.red - color2.red) + color2.red,

        mul * (color1.green - color2.green) + color2.green,

        mul * (color1.blue - color2.blue) + color2.blue

      )

      # Draw the portion of the rectangle with the new color

      if vertical

        self.fill_rect(x, y+i, width,1, color)

      else

        self.fill_rect(x+i, y, 1, height, color)

      end

    end

  end

  

end

 

#---------------------

# Changes to the Window_Base class where Draw_Actor_HP/SP reside

 

class Window_Base < Window

  # --------

  # Change the Draw_Actor_HP function so a gradient bar appears to show how

  # much HP the actor has left

  alias draw_actor_hp_healthgauges draw_actor_hp unless $@

  def draw_actor_hp(actor, x, y, width = 144)

    # First create the health gauge!

    

    # Define colors for the gauges and the empty part of the gauge

    # Color1 is the left of the gauge, Color2 is the right

    health_gauge_color_1 = Color.new(128, 64, 32)

    health_gauge_color_2 = Color.new(255, 128, 64)

    black_color = Color.new(0, 0, 0)

    

    # Define the dimensions of the gauge in pixels

    height = 6

    x_offset = 0 

    y_offset = 15

    

    # If the actor has HP left...

    if actor.hp > 0

    

      # Draw the full gauge first

      self.contents.draw_gradient_rect(

        x + x_offset,

        y + y_offset,

        width,

        height,

        health_gauge_color_1,

        health_gauge_color_2

      )

      # If HP isn't maxed out, we'll have to draw the empty part of the gauge

      if actor.hp < actor.maxhp

        # Calculate how long the empty part of thegauge is (it will be at least one pixel wide and it won't be as long as the health gauge)

        empty_width = [[(width * (1 - actor.hp.to_f / actor.maxhp)).to_i, 1].max, width - 1].min

        # Now draw the empty part of the bar using this width

        self.contents.fill_rect(

          width - empty_width + x + x_offset + 1,

          y+y_offset,

          empty_width,

          height, 

          black_color

        )

      end

    

    else

      # The actor has no HP, just show a big black bar

      self.contents.fill_rect(x+x_offset, y+y_offset, width, height, black_color)

    end

    

    # Now draw the HP value by calling the original method

    draw_actor_hp_healthgauges(actor, x, y, width)

  end

  

  # ------------

  # Change the Draw_Actor_SP function so it draws a gradient bar to show the

  # amount of SP the actor has left

  alias draw_actor_sp_healthgauges draw_actor_sp unless $@

  def draw_actor_sp(actor, x, y, width = 144)

    # First create the SP gauge!

    

    # Define colors for the gauges and the empty part of the gauge

    # Color1 is the left of the gauge, Color2 is the right

    sp_gauge_color_1 = Color.new(32, 32, 128)

    sp_gauge_color_2 = Color.new(64, 64, 255)

    black_color = Color.new(0, 0, 0)

    

    # Define the dimensions of the gauge in pixels

    height = 6

    x_offset = 

    y_offset = 15

    

    # If the actor has SP left...

    if actor.sp > 0

    

      # Draw the full gauge first

      self.contents.draw_gradient_rect(

        x + x_offset,

        y + y_offset,

        width,

        height, 

        sp_gauge_color_1,

        sp_gauge_color_2

      )

      # If SP isn't maxed out, we'll have to draw the empty part of the gauge

      if actor.sp < actor.maxsp

        # Calculate how long the empty part of thegauge is (it will be at least one pixel wide and it won't be as long as the health gauge)

        empty_width = [[(width * (1 - actor.sp.to_f / actor.maxsp)).to_i, 1].max, width - 1].min

        # Now draw the empty part of the bar using this width

        self.contents.fill_rect(

          width - empty_width + x + x_offset + 1,

          y+y_offset,

          empty_width,

          height, 

          black_color

        )

      end

 

    else

      # Just draw a big black empty bar

      self.contents.fill_rect(x+x_offset, y+y_offset, width, height, black_color)

    end

      

    # Now draw the SP value by calling the original method

    draw_actor_sp_healthgauges(actor, x, y, width)

  end

end

 

#-------------------

# Change the RPG::Sprite class so it doesn't force it's viewport

# Overwrite required since you can't change the viewport of a created image

module RPG

  class Sprite < ::Sprite

    def damage(value, critical)

      dispose_damage

      if value.is_a?(Numeric)

        damage_string = value.abs.to_s

      else

        damage_string = value.to_s

      end

      bitmap = Bitmap.new(160, 48)

      bitmap.font.name = "Arial Black"

      bitmap.font.size = 32

      bitmap.font.color.set(0, 0, 0)

      bitmap.draw_text(-1, 12-1, 160, 36, damage_string, 1)

      bitmap.draw_text(+1, 12-1, 160, 36, damage_string, 1)

      bitmap.draw_text(-1, 12+1, 160, 36, damage_string, 1)

      bitmap.draw_text(+1, 12+1, 160, 36, damage_string, 1)

      if value.is_a?(Numeric) and value < 0

        bitmap.font.color.set(176, 255, 144)

      else

        bitmap.font.color.set(255, 255, 255)

      end

      bitmap.draw_text(0, 12, 160, 36, damage_string, 1)

      if critical

        bitmap.font.size = 20

        bitmap.font.color.set(0, 0, 0)

        bitmap.draw_text(-1, -1, 160, 20, "CRITICAL", 1)

        bitmap.draw_text(+1, -1, 160, 20, "CRITICAL", 1)

        bitmap.draw_text(-1, +1, 160, 20, "CRITICAL", 1)

        bitmap.draw_text(+1, +1, 160, 20, "CRITICAL", 1)

        bitmap.font.color.set(255, 255, 255)

        bitmap.draw_text(0, 0, 160, 20, "CRITICAL", 1)

      end

      @_damage_sprite = ::Sprite.new#(self.viewport)

      @_damage_sprite.bitmap = bitmap

      @_damage_sprite.ox = 80

      @_damage_sprite.oy = 20

      @_damage_sprite.x = self.x

      @_damage_sprite.y = self.y - self.oy / 2

      @_damage_sprite.z = 3000

      @_damage_duration = 40

    end

  end

end




*** or if you have a better script for sharing that would be awesome :biggrin:
 
That is actually quite easy. Open the Battle Status script and adjust lines
40 and 41 to the following:
Code:
      draw_actor_hp(actor, actor_x, 32, [b]120[/b])

      draw_actor_sp(actor, actor_x, 64, [b]120[/b])

 
The bolded text is the 'length' of the bar. Just reduce the number until it looks right.
 
thank you Gubid... i was acually using your battle system till i switched to this one. GTBS was awesome and the customizable options were great im just not good enough at scripting... but thank you it worked :biggrin:
 
It was bothering me that the SP gauge was shifted to the right, so I had to dig into it.

Line 101 in your script reads:

x_offset =

should be:

x_offset = 0


Took me a while to realize the interpreter is reading the line as (including the next line)

x_offset = y_offset = 15
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top