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.

Enemy HP/SP and Name

Status
Not open for further replies.
This is a really useful Script I found on 66RPG.com and edited slightly


What it Does

This script shows the enemies' name, HP and SP in battle.


Advice for Usage

I Advise you use some form of HP/SP bar with this script to make the HP and SP stand out.
Something like the CogWheel Plug 'n' Play Menu Bars.
If you do use bars that alias themselves to the HP and SP you have to put the code below this one.


Screenies

http://i25.photobucket.com/albums/c66/R ... ostbar.jpg[/IMG]


The Script

Code:
#==============================================================================
# 本脚本来自www.66RPG.com,使用和转载请保留此信息
#==============================================================================
# ■ エネミーHP&SP(ver 0.98)

# □ カスタマイズポイント
#==============================================================================
module PLAN_HPSP_DRAW
 FONT_NAME         = ["Arial"]    # フォント
 FONT_SIZE         =  18                            # フォントサイズ
 FONT_BOLD         = true                              # 太字
 FONT_ITALIC       = true                              # 斜体

 DRAW_NAME         = true                              # 名前の描画
 DRAW_HP           = true                              # HP の描画
 DRAW_SP           = true                              # SP の描画

 DRAW_WIDTH        =  80                               # 描画幅
 DRAW_HEIGHT       = 3 * 32                            # 描画高さ
 DRAW_SPACE        =   0                               # 行間
 DRAW_Y            =  24                               # Y 座標修正値
end


#==============================================================================
# â–  Sprite_Battler
#==============================================================================

class Sprite_Battler < RPG::Sprite
 #--------------------------------------------------------------------------
 # ● オブジェクト初期化
 #--------------------------------------------------------------------------
 alias plan_enemy_hpsp_draw_initialize initialize
 def initialize(viewport, battler = nil)
   # 元のメソッドに戻す
   plan_enemy_hpsp_draw_initialize(viewport, battler)
   # エネミーの場合
   if @battler.is_a?(Game_Enemy)
     width = PLAN_HPSP_DRAW::DRAW_WIDTH + 32
     height = PLAN_HPSP_DRAW::DRAW_HEIGHT + 32
     x = @battler.screen_x - width / 2
     y = @battler.screen_y - height + 32 + PLAN_HPSP_DRAW::DRAW_Y
     @enemy_hpsp_window = Window_Base.new(x, y, width, height)
     @enemy_hpsp_window.contents = Bitmap.new(width - 32, height - 32)
     @enemy_hpsp_window.contents.font.name = PLAN_HPSP_DRAW::FONT_NAME
     @enemy_hpsp_window.contents.font.size = PLAN_HPSP_DRAW::FONT_SIZE
     @enemy_hpsp_window.contents.font.bold = PLAN_HPSP_DRAW::FONT_BOLD
     @enemy_hpsp_window.contents.font.italic = PLAN_HPSP_DRAW::FONT_ITALIC
     y = 0
     @old_enemy_hpsp = []
     one_line = ((PLAN_HPSP_DRAW::FONT_SIZE * 100 / 28) * 32) / 100
     if PLAN_HPSP_DRAW::DRAW_NAME
       @enemy_hpsp_window.draw_actor_name(@battler, 0, y, width - 32)
       y += one_line + PLAN_HPSP_DRAW::DRAW_SPACE
       @old_enemy_hpsp.push(@battler.name)
     end
     if PLAN_HPSP_DRAW::DRAW_HP
       @enemy_hpsp_window.draw_actor_hp(@battler, 0, y, width - 32)
       y += one_line + PLAN_HPSP_DRAW::DRAW_SPACE
       @old_enemy_hpsp.push(@battler.hp)
     end
     if PLAN_HPSP_DRAW::DRAW_SP
       @enemy_hpsp_window.draw_actor_sp(@battler, 0, y, width - 32)
       @old_enemy_hpsp.push(@battler.sp)
     end
     @enemy_hpsp_window.opacity = 0
     @enemy_hpsp_window.contents_opacity = 0
     @enemy_hpsp_window.z = -2
   end
 end
 #--------------------------------------------------------------------------
 # ● 解放
 #--------------------------------------------------------------------------
 alias plan_enemy_hpsp_draw_dispose dispose
 def dispose
   # エネミーの場合
   if @battler.is_a?(Game_Enemy)
     @enemy_hpsp_window.dispose
   end
   # 元のメソッドに戻す
   plan_enemy_hpsp_draw_dispose
 end
 #--------------------------------------------------------------------------
 # ● フレーム更新
 #--------------------------------------------------------------------------
 alias plan_enemy_hpsp_draw_update update
 def update
   # 元のメソッドに戻す
   plan_enemy_hpsp_draw_update
   # エネミーの場合
   if @battler.is_a?(Game_Enemy)
     @enemy_hpsp_window.visible = @battler_visible
   # スプライトの座標を設定
     width = PLAN_HPSP_DRAW::DRAW_WIDTH + 32
     @enemy_hpsp_window.x = self.x - width / 2
     @now_enemy_hpsp = []
     if PLAN_HPSP_DRAW::DRAW_NAME
       @now_enemy_hpsp.push(@battler.name)
     end
     if PLAN_HPSP_DRAW::DRAW_HP
       @now_enemy_hpsp.push(@battler.hp)
     end
     if PLAN_HPSP_DRAW::DRAW_SP
       @now_enemy_hpsp.push(@battler.sp)
     end
     if @old_enemy_hpsp != @now_enemy_hpsp and $game_temp.enemy_hpsp_refresh
       @old_enemy_hpsp = @now_enemy_hpsp
       @enemy_hpsp_window.contents.clear
       y = 0
       width = PLAN_HPSP_DRAW::DRAW_WIDTH + 32
       one_line = ((PLAN_HPSP_DRAW::FONT_SIZE * 100 / 28) * 32) / 100
       if PLAN_HPSP_DRAW::DRAW_NAME
         @enemy_hpsp_window.draw_actor_name(@battler, 0, y, width - 32)
         y += one_line + PLAN_HPSP_DRAW::DRAW_SPACE
       end
       if PLAN_HPSP_DRAW::DRAW_HP
         @enemy_hpsp_window.draw_actor_hp(@battler, 0, y, width - 32)
         y += one_line + PLAN_HPSP_DRAW::DRAW_SPACE
       end
       if PLAN_HPSP_DRAW::DRAW_SP
         @enemy_hpsp_window.draw_actor_sp(@battler, 0, y, width - 32)
       end
       Graphics.frame_reset
     end
   end
 end
 #--------------------------------------------------------------------------
 # ● visible の設定
 #--------------------------------------------------------------------------
 if !method_defined?("plan_enemy_hpsp_draw_visible=")
   alias plan_enemy_hpsp_draw_visible= visible=
 end
 def visible=(bool)
   # エネミーの場合
   if @battler.is_a?(Game_Enemy)
     @enemy_hpsp_window.visible = bool
   end
   # 元のメソッドに戻す
   self.plan_enemy_hpsp_draw_visible=(bool)
 end
 #--------------------------------------------------------------------------
 # ● 不透明度の設定
 #--------------------------------------------------------------------------
 if !method_defined?("plan_enemy_hpsp_draw_opacity=")
   alias plan_enemy_hpsp_draw_opacity= opacity=
 end
 def opacity=(n)
   # 元のメソッドに戻す
   self.plan_enemy_hpsp_draw_opacity=(n)
   # エネミーの場合
   if @battler.is_a?(Game_Enemy)
     @enemy_hpsp_window.contents_opacity = n
   end
 end
 #--------------------------------------------------------------------------
 # ● ダメージ
 #--------------------------------------------------------------------------
 def damage(value, critical)
   super(value, critical)
   bitmap = @_damage_sprite.bitmap
   @_damage_sprite.dispose
   @_damage_sprite = ::Sprite.new(Viewport.new(0, 0, 640, 480))
   @_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.viewport.z = self.viewport.z + 1
   @_damage_sprite.z = 3000
   @_damage_duration = 40
 end
 #--------------------------------------------------------------------------
 # ● ダメージ解放
 #--------------------------------------------------------------------------
 def dispose_damage
   if @_damage_sprite != nil
     @_damage_sprite.viewport.dispose
   end
   super
 end
end

 

 

#==============================================================================
# â–  Game_Temp
#==============================================================================

class Game_Temp
 #--------------------------------------------------------------------------
 # ● 公開インスタンス変数
 #--------------------------------------------------------------------------
 attr_accessor :enemy_hpsp_refresh
 #--------------------------------------------------------------------------
 # ● オブジェクト初期化
 #--------------------------------------------------------------------------
 alias plan_enemy_hpsp_draw_initialize initialize
 def initialize
   # 元のメソッドに戻す
   plan_enemy_hpsp_draw_initialize
   @enemy_hpsp_refresh = false
 end
end

#==============================================================================
# â–  Scene_Battle
#==============================================================================

class Scene_Battle
 #--------------------------------------------------------------------------
 # ● プレバトルフェーズ開始 (エネミー名+アルファベット用)
 #--------------------------------------------------------------------------
 alias plan_enemy_hpsp_draw_start_phase1 start_phase1
 def start_phase1
   $game_temp.enemy_hpsp_refresh = true
   # 元のメソッドに戻す
   plan_enemy_hpsp_draw_start_phase1
 end
 #--------------------------------------------------------------------------
 # ● パーティコマンドフェーズ開始 (エネミー名+アルファベット用)
 #--------------------------------------------------------------------------
 alias plan_enemy_hpsp_draw_start_phase2 start_phase2
 def start_phase2
   $game_temp.enemy_hpsp_refresh = false
   # 元のメソッドに戻す
   plan_enemy_hpsp_draw_start_phase2
 end
 #--------------------------------------------------------------------------
 # ● フレーム更新 (メインフェーズ ステップ 5 : ダメージ表示)
 #--------------------------------------------------------------------------
 alias plan_enemy_hpsp_draw_update_phase4_step5 update_phase4_step5
 def update_phase4_step5
   # 元のメソッドに戻す
   plan_enemy_hpsp_draw_update_phase4_step5
   $game_temp.enemy_hpsp_refresh = true
 end
 #--------------------------------------------------------------------------
 # ● フレーム更新 (メインフェーズ ステップ 6 : リフレッシュ)
 #--------------------------------------------------------------------------
 alias plan_enemy_hpsp_draw_update_phase4_step6 update_phase4_step6
 def update_phase4_step6
   # 元のメソッドに戻す
   plan_enemy_hpsp_draw_update_phase4_step6
   $game_temp.enemy_hpsp_refresh = false
 end
end


#==============================================================================
# â–  Window_Base
#==============================================================================

class Window_Base < Window
 #--------------------------------------------------------------------------
 # ● 名前の描画
 #--------------------------------------------------------------------------
 def draw_actor_name(actor, x, y, width = 220, align = 0)
   if $scene.is_a?(Scene_Battle)
     flag = actor.name.sub!(/\*f/, '').nil? ? false : true
     self.contents.font.color = Color.new(0, 0, 0, 192)
   self.contents.draw_text(x+1, y, width, 32, actor.name, align)
   self.contents.draw_text(x, y+1, width, 32, actor.name, align)
 end
   self.contents.font.color = normal_color
   self.contents.draw_text(x, y, width, 32, actor.name, align)
 end
 
 alias draw_actor_hp_original draw_actor_hp
 def draw_actor_hp(actor, x, y, width = 144)
    # Calculate if there is draw space for MaxHP
    if width - 32 >= 108
      hp_x = x + width - 108
      flag = true
    elsif width - 32 >= 48
      hp_x = x + width - 48
      flag = false
    end
    # Draw Shadow Effects for Battles
    if $scene.is_a?(Scene_Battle)
      self.contents.font.color = Color.new(0, 0, 0, 192)
      self.contents.draw_text(x, y+1, 32, 32, $data_system.words.hp)
      self.contents.draw_text(x+1, y, 32, 32, $data_system.words.hp)
      self.contents.draw_text(hp_x, y+1, 48, 32, actor.hp.to_s, 2)
      self.contents.draw_text(hp_x+1, y, 48, 32, actor.hp.to_s, 2)
    if flag
      self.contents.draw_text(hp_x + 49, y, 12, 32, "/", 1)
      self.contents.draw_text(hp_x + 48, y+1, 12, 32, "/", 1)
      self.contents.draw_text(hp_x + 60, y+1, 48, 32, actor.maxhp.to_s)
      self.contents.draw_text(hp_x + 61, y, 48, 32, actor.maxhp.to_s)
    end
    end
    # Draw "HP" text string
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 32, 32, $data_system.words.hp)
    # Draw HP
    self.contents.font.color = actor.hp == 0 ? knockout_color :
      actor.hp <= actor.maxhp / 4 ? crisis_color : normal_color
    self.contents.draw_text(hp_x, y, 48, 32, actor.hp.to_s, 2)
    # Draw MaxHP
    if flag
      self.contents.font.color = normal_color
      self.contents.draw_text(hp_x + 48, y, 12, 32, "/", 1)
      self.contents.draw_text(hp_x + 60, y, 48, 32, actor.maxhp.to_s)
    end
  end
  
  alias draw_actor_sp_original draw_actor_sp
  def draw_actor_sp(actor, x, y, width = 144)
    # Calculate if there is draw space for MaxHP
    if width - 32 >= 108
      sp_x = x + width - 108
      flag = true
    elsif width - 32 >= 48
      sp_x = x + width - 48
      flag = false
    end
    # Draw Shadow Effects for Battles
    if $scene.is_a?(Scene_Battle)
      self.contents.font.color = Color.new(0, 0, 0, 192)
      self.contents.draw_text(x, y+1, 32, 32, $data_system.words.sp)
      self.contents.draw_text(x+1, y, 32, 32, $data_system.words.sp)
      self.contents.draw_text(sp_x, y+1, 48, 32, actor.sp.to_s, 2)
      self.contents.draw_text(sp_x+1, y, 48, 32, actor.sp.to_s, 2)
    if flag
      self.contents.draw_text(hp_x + 49, y, 12, 32, "/", 1)
      self.contents.draw_text(hp_x + 48, y+1, 12, 32, "/", 1)
      self.contents.draw_text(hp_x + 60, y+1, 48, 32, actor.maxsp.to_s)
      self.contents.draw_text(hp_x + 61, y, 48, 32, actor.maxsp.to_s)
    end
    end
    # Draw "SP" text string
    self.contents.font.color = system_color
    self.contents.draw_text(x, y, 32, 32, $data_system.words.sp)
    # Draw SP
    self.contents.font.color = actor.sp == 0 ? knockout_color :
      actor.sp <= actor.maxsp / 4 ? crisis_color : normal_color
    self.contents.draw_text(sp_x, y, 48, 32, actor.sp.to_s, 2)
    # Draw MaxSP
    if flag
      self.contents.font.color = normal_color
      self.contents.draw_text(sp_x + 48, y, 12, 32, "/", 1)
      self.contents.draw_text(sp_x + 60, y, 48, 32, actor.maxsp.to_s)
    end
  end
 
 #--------------------------------------------------------------------------
 # ● ステートの描画
 #--------------------------------------------------------------------------
 def draw_actor_state(actor, x, y, width = 120)
   # 元のメソッドに戻す
   text = make_battler_state_text(actor, width, true)
   self.contents.draw_text(x, y, width, 32, text, 1)
 end
end


Credit

Credit to which ever bit of Japanese is a name in the comments, otherwise just to 66RPG.com
And mini credit to me if you're kind :D




Enjoy :D
 
syvkal, I recommend you put a black shadow or outline round the enemies hp/sp. Then if someone has a monster like a ghost you can see it clearly. :P
 
Yeah I have, just like a said it's an oldish screenie.

And sorry if I sounded a bit rude when I posted that on your thread -_- ...



I'll get a new screenie and put it up.
 
You didn't sound rude, don't worry. No, I meant the actual script, I tried it out and even if you have the bars, if you have an enemy like a ghost, the hp/sp isn't well shown. I like how the enemy's name is shown, maybe you should do the same thing with the hp and sp.
 
Oh sorry I get you :D
K I'll do that too :D


:EDIT:


*Update*

The HP and SP have now been lined with a shadow.
If you are using a gradient bar script read the updated 'Advice for Usage'

If someone does see the strange aliasing that I've done and knows how to make it shorter without causing the script to hang please tell me :D
 
Is there any way this script could be toggled on and off so that it could be used as a sort of "scan" type skill? That would rock.
 
ryanwh said:
Is there any way this script could be toggled on and off so that it could be used as a sort of "scan" type skill? That would rock.

I was just about to ask that exact question.
 
I guess so. I'll have a looky, I'm sure I can do it, but I really busy at the moment (hence why I haven't been on for a while)...
 
Hey great script...everything works good, until i try to heal I get this error:

?????' ' ? 327 ??? NameError ???????

undefined local variable or method `hp_x' for #<Window_help:0x46532a0>

Anyway to fix this...?
 
Hey nevermind I found the error, It was in these lines:

if flag
self.contents.draw_text(hp_x + 49, y, 12, 32, "/", 1)
self.contents.draw_text(hp_x + 48, y+1, 12, 32, "/", 1)
self.contents.draw_text(hp_x + 60, y+1, 48, 32, actor.maxsp.to_s)
self.contents.draw_text(hp_x + 61, y, 48, 32, actor.maxsp.to_s)
^^
The "hp" is supposed to be sp, looks halfway done. So just change all of the "hp"s with "sp" and it fixes it. Might wanna update your script :P

One question: How do you add an outline or a shadow around the enemy's HP text...?
 
Umm I think I updated that in the script already
And thanks for that for some reason I missed that... but it works fine on mine...
 
So this just goes in it's own script, right?
It doesn't alter the other scripts?

Sorry, I'm a complete newb to scripting... I don't have a clue.

And afterwards, where does the plug-and-play script go?
 
excuse me, syvkal? i am having problems with your script, it wont let me heal T_T when i use a potion or a cure spell in battle i getz an error and it goes kaboom, but if i do it outside battle im fine.
 
if flag
self.contents.draw_text(hp_x + 49, y, 12, 32, "/", 1)
self.contents.draw_text(hp_x + 48, y+1, 12, 32, "/", 1)
self.contents.draw_text(hp_x + 60, y+1, 48, 32, actor.maxsp.to_s)
self.contents.draw_text(hp_x + 61, y, 48, 32, actor.maxsp.to_s)
^^
The "hp" is supposed to be sp, looks halfway done. So just change all of the "hp"s with "sp" and it fixes it.

(line 327 btw)

I had the same problem earlier...
 
Status
Not open for further replies.

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