Chaos Project

RPG Maker => RPG Maker Scripts => Script Requests => Topic started by: BeAddicted on December 05, 2010, 08:52:59 am

Title: [Resolved]Blizzabs enemy mp bar
Post by: BeAddicted on December 05, 2010, 08:52:59 am
Im searching for an script to show the enemys mp under the hpbar. So that there is a greenbar for hp and a blue for mp. An maybe that I could dissable this for some enemys. That when I set the MP of an enemy to 0 in the database that there is no mp bar shown or that I can enable/dissable this in the eventname or something like this
Hadn't found such a script here so I think it doesn't exist so could anyone make such a script?
Title: Re: Blizzabs enemy mp bar
Post by: WhiteRose on December 05, 2010, 01:39:23 pm
There isn't such a script here on CP, but I don't think it would be that difficult to make. That's actually a pretty good idea for a plug-in, or even a native features of BABS in the next release.
Title: Re: Blizzabs enemy mp bar
Post by: Aqua on December 05, 2010, 02:00:26 pm
Sec... working on it ;)

Spoiler: ShowHide
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=#
# Blizz-ABS Magic Bars for Enemies Script by TerreAqua
# Version: 1.00
# Type: Blizz-ABS Add-on
# Key Term: Battle Add-on
# Date: 12/05/10
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=#

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=#
# ~ Plug & Play ~
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=#

class Control_Sprite_Character
  #----------------------------------------------------------------------------
  # create_health_sprite
  #  Creates a health sprite.
  #----------------------------------------------------------------------------
  def create_magic_sprite
    # if magic bars active and observing enemy
    if BlizzABS::Config::ENEMY_HEALTH_BARS > 0 &&
        @character.is_a?(Map_Enemy) && !@character.hide_health &&
        @character.opacity > 0 && @character.battler.maxsp != 0
      # create a sprite
      @magic = Sprite.new(@viewport)
      # whether ENEMY_HEALTH_BARS_MATCH_WIDTH is active and tile graphic
      if @character.tile_id < 384 &&
          BlizzABS::Config::ENEMY_HEALTH_BARS_MATCH_WIDTH
        # set the width
        width = @sprite.bitmap.width / 4
      else
        # set the width to default
        width = 32
      end
      # x offset
      @magic.ox = width / 2
      # create bitmap
      @magic.bitmap = Bitmap.new(width, 6)
      # fill bitmap background for better display
      @magic.bitmap.fill_rect(0, 0, width, 6, Color.new(0, 26, 0))
      # set magic bar z coordinate
      @magic.z = 1
      # set magic bar opacity
      @magic.opacity = BlizzABS::Config::ENEMY_HEALTH_BARS
    end
  end
  #----------------------------------------------------------------------------
  # update_magic
  #  Handles magic sprite updating.
  #----------------------------------------------------------------------------
  def update_magic
    # move health sprite along with sprite
    @magic.x = @sprite.x
    @magic.y = @sprite.y - @sprite.oy
    @magic.z = @sprite.z + 1
    # if enemy SP have changed
    if @sp != @character.battler.sp || @battler_id != @character.battler_id
      # rate of filling
      rate = @character.battler.sp.to_f / @character.battler.maxsp
      # get empty bar bitmap
      bitmaps = [$BlizzABS.cache.image('empty_enemy_bar'),
          $BlizzABS.cache.image('enemy_bar')]
      # change hue of bar bitmap
      bitmaps[1].hue_change((rate / 0.8 - 1.25) * 120 + 90)
      # temporary variable
      width = @magic.bitmap.width - 2
      # draw empty bar bitmap
      @magic.bitmap.stretch_blt(Rect.new(1, 0, width, 6), bitmaps[0],
          Rect.new(0, 0, 1, 6))
      # draw bar bitmap
      @magic.bitmap.stretch_blt(Rect.new(1, 0, rate * width, 6), bitmaps[1],
          Rect.new(0, 0, 1, 6))
      # store new values
      @sp, @battler_id = @character.battler.sp, @character.battler_id
    end
  end
 
  alias mp_bars_update update
  def update
    mp_bars_update
    # if character within ABSEAL range or special character
    if self.character_valid?
      # if sprite doesn't exists yet
      if @sprite == nil || @sprite.disposed?
        # create magic sprite
        create_magic_sprite
        # update magic bar if health bar exists
        update_magic if @magic != nil
      else
        if @character.is_a?(Map_Battler) && @character.valid? &&
           @character.battler.maxsp != 0
          # create magic sprite if magic sprite doesn't exist yet
          create_magic_sprite if @magic == nil
        end
        # update magic bar if magic bar exists and character is not dead
        update_magic if @magic != nil && !@character.battler.dead?
      end
    # if sprite exists
    elsif @sprite != nil
      # delete magic sprite if it exists and not freed yet
      @magic.dispose unless @magic == nil || @magic.disposed?
      # remove sprite from memory
      @magic = @sp = nil
    end
  end
 
end


Just plug & play.
It'll draw SP bars if HP bars are drawn or the enemy's max SP is greater than 0.

Tell me if you want to change positioning or colors.
Title: Re: Blizzabs enemy mp bar
Post by: BeAddicted on December 05, 2010, 03:44:53 pm
looks good thank you
Title: Re: Blizzabs enemy mp bar
Post by: Blizzard on December 05, 2010, 04:39:19 pm
*coughs for a script topic as Blizz-ABS plugin* ::D
Title: Re: Blizzabs enemy mp bar
Post by: ForeverZer0 on December 05, 2010, 04:41:22 pm
I have some Hall's cough drops for that. They're the sugar-free kind. I figured your sweet enough.
Title: Re: Blizzabs enemy mp bar
Post by: LiTTleDRAgo on December 19, 2010, 04:16:17 am
Quote from: Aqua on December 05, 2010, 02:00:26 pm
Sec... working on it ;)

Spoiler: ShowHide
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=#
# Blizz-ABS Magic Bars for Enemies Script by TerreAqua
# Version: 1.00
# Type: Blizz-ABS Add-on
# Key Term: Battle Add-on
# Date: 12/05/10
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=#

#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=#
# ~ Plug & Play ~
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=#

class Control_Sprite_Character
  #----------------------------------------------------------------------------
  # create_health_sprite
  #  Creates a health sprite.
  #----------------------------------------------------------------------------
  def create_magic_sprite
    # if magic bars active and observing enemy
    if BlizzABS::Config::ENEMY_HEALTH_BARS > 0 &&
        @character.is_a?(Map_Enemy) && !@character.hide_health &&
        @character.opacity > 0 && @character.battler.maxsp != 0
      # create a sprite
      @magic = Sprite.new(@viewport)
      # whether ENEMY_HEALTH_BARS_MATCH_WIDTH is active and tile graphic
      if @character.tile_id < 384 &&
          BlizzABS::Config::ENEMY_HEALTH_BARS_MATCH_WIDTH
        # set the width
        width = @sprite.bitmap.width / 4
      else
        # set the width to default
        width = 32
      end
      # x offset
      @magic.ox = width / 2
      # create bitmap
      @magic.bitmap = Bitmap.new(width, 6)
      # fill bitmap background for better display
      @magic.bitmap.fill_rect(0, 0, width, 6, Color.new(0, 26, 0))
      # set magic bar z coordinate
      @magic.z = 1
      # set magic bar opacity
      @magic.opacity = BlizzABS::Config::ENEMY_HEALTH_BARS
    end
  end
  #----------------------------------------------------------------------------
  # update_magic
  #  Handles magic sprite updating.
  #----------------------------------------------------------------------------
  def update_magic
    # move health sprite along with sprite
    @magic.x = @sprite.x
    @magic.y = @sprite.y - @sprite.oy
    @magic.z = @sprite.z + 1
    # if enemy SP have changed
    if @sp != @character.battler.sp || @battler_id != @character.battler_id
      # rate of filling
      rate = @character.battler.sp.to_f / @character.battler.maxsp
      # get empty bar bitmap
      bitmaps = [$BlizzABS.cache.image('empty_enemy_bar'),
          $BlizzABS.cache.image('enemy_bar')]
      # change hue of bar bitmap
      bitmaps[1].hue_change((rate / 0.8 - 1.25) * 120 + 90)
      # temporary variable
      width = @magic.bitmap.width - 2
      # draw empty bar bitmap
      @magic.bitmap.stretch_blt(Rect.new(1, 0, width, 6), bitmaps[0],
          Rect.new(0, 0, 1, 6))
      # draw bar bitmap
      @magic.bitmap.stretch_blt(Rect.new(1, 0, rate * width, 6), bitmaps[1],
          Rect.new(0, 0, 1, 6))
      # store new values
      @sp, @battler_id = @character.battler.sp, @character.battler_id
    end
  end
 
  alias mp_bars_update update
  def update
    mp_bars_update
    # if character within ABSEAL range or special character
    if self.character_valid?
      # if sprite doesn't exists yet
      if @sprite == nil || @sprite.disposed?
        # create magic sprite
        create_magic_sprite
        # update magic bar if health bar exists
        update_magic if @magic != nil
      else
        if @character.is_a?(Map_Battler) && @character.valid? &&
           @character.battler.maxsp != 0
          # create magic sprite if magic sprite doesn't exist yet
          create_magic_sprite if @magic == nil
        end
        # update magic bar if magic bar exists and character is not dead
        update_magic if @magic != nil && !@character.battler.dead?
      end
    # if sprite exists
    elsif @sprite != nil
      # delete magic sprite if it exists and not freed yet
      @magic.dispose unless @magic == nil || @magic.disposed?
      # remove sprite from memory
      @magic = @sp = nil
    end
  end
 
end


Just plug & play.
It'll draw SP bars if HP bars are drawn or the enemy's max SP is greater than 0.

Tell me if you want to change positioning or colors.


bug : the sp bar didn't dissapear after defeating the enemy