设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 3405|回复: 23
打印 上一主题 下一主题

[已经解决] 战斗显示角色名字 HP SP

[复制链接]

Lv3.寻梦者

梦石
0
星屑
3186
在线时间
1863 小时
注册时间
2010-6-19
帖子
1205
跳转到指定楼层
1
发表于 2022-4-6 09:51:19 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 黑米馒头 于 2022-4-7 16:35 编辑

下面这个显示敌人名字 HP SP的脚本如何改成给角色也能使用,有会脚本的帮忙看下,谢谢


RUBY 代码复制
  1. #==============================================================================
  2. module PLAN_HPSP_DRAW
  3.   FONT_NAME         = ["宋体","黑体"]    # フォント
  4.   FONT_SIZE         =  16                               # 字体大小
  5.   FONT_BOLD         = true                              # 太字
  6.   FONT_ITALIC       = false #true                       # 斜体
  7.  
  8.   DRAW_NAME         = true                              # 名前の描画
  9.   DRAW_HP           = true#false                        # HP の描画
  10.   DRAW_SP           = true#false                         # SP の描画
  11.  
  12.   DRAW_WIDTH        = 80 * 2 + 20                     # 描画幅
  13.   DRAW_HEIGHT       = 3 * 32                            # 描画高さ
  14.   DRAW_SPACE        = 0                                 # 行間
  15.   DRAW_Y            = 24                                # Y 座標修正値
  16. end
  17.  
  18. class Sprite_Battler < RPG::Sprite
  19.   #--------------------------------------------------------------------------
  20.   # ● 对象初始化
  21.   #--------------------------------------------------------------------------
  22.   alias plan_enemy_hpsp_draw_initialize initialize
  23.   def initialize(viewport, battler = nil)
  24.     # 元のメソッドに戻す
  25.     plan_enemy_hpsp_draw_initialize(viewport, battler)
  26.     # エネミーの場合
  27.     if @battler.is_a?(Game_Enemy)
  28.       width = PLAN_HPSP_DRAW::DRAW_WIDTH + 32
  29.       height = PLAN_HPSP_DRAW::DRAW_HEIGHT + 32
  30.       x = @battler.screen_x - width / 2
  31.       y = @battler.screen_y - height + 32 + PLAN_HPSP_DRAW::DRAW_Y
  32.  
  33.       #@enemy_hpsp_window = Window_Base.new(x, y, width, height) 原来这样
  34.       # 这样设置可以调整Z坐标了
  35.       ObjectSpace.each_object(Spriteset_Battle) {|obj|
  36.       @enemy_hpsp_window = Window_Base.new(x, y, width, height,obj.instance_eval("@viewport1"))}
  37.       @enemy_hpsp_window.contents = Bitmap.new(width - 32, height - 32)
  38.       @enemy_hpsp_window.contents.font.name = PLAN_HPSP_DRAW::FONT_NAME
  39.       @enemy_hpsp_window.contents.font.size = PLAN_HPSP_DRAW::FONT_SIZE
  40.       @enemy_hpsp_window.contents.font.bold = PLAN_HPSP_DRAW::FONT_BOLD
  41.       @enemy_hpsp_window.contents.font.italic = PLAN_HPSP_DRAW::FONT_ITALIC
  42.       y = 0
  43.       @old_enemy_hpsp = []
  44.       one_line = ((PLAN_HPSP_DRAW::FONT_SIZE * 100 / 28) * 32) / 100
  45.       # 窗口名字的位置
  46.       if PLAN_HPSP_DRAW::DRAW_NAME
  47.         @enemy_hpsp_window.draw_actor_name(@battler, -10, y, width - 32)
  48.         y += one_line + PLAN_HPSP_DRAW::DRAW_SPACE
  49.         @old_enemy_hpsp.push(@battler.name)
  50.       end
  51.       # 窗口HP的位置
  52.       if PLAN_HPSP_DRAW::DRAW_HP
  53.         @enemy_hpsp_window.draw_actor_hp(@battler, 0, y, width - 32)
  54.         y += one_line + PLAN_HPSP_DRAW::DRAW_SPACE
  55.         @old_enemy_hpsp.push(@battler.hp)
  56.       end
  57.       # 窗口SP的位置
  58.       if PLAN_HPSP_DRAW::DRAW_SP
  59.         @enemy_hpsp_window.draw_actor_sp(@battler, 0, y, width - 32)
  60.         @old_enemy_hpsp.push(@battler.sp)
  61.       end
  62.       # 窗口透明度
  63.       @enemy_hpsp_window.opacity = 150
  64.       @enemy_hpsp_window.contents_opacity = 150
  65.       #@enemy_hpsp_window.z = -2
  66.     end
  67.   end
  68.   #--------------------------------------------------------------------------
  69.   # ● 解放
  70.   #--------------------------------------------------------------------------
  71.   alias plan_enemy_hpsp_draw_dispose dispose
  72.   def dispose
  73.     # エネミーの場合
  74.     if @battler.is_a?(Game_Enemy)
  75.       @enemy_hpsp_window.dispose
  76.     end
  77.     # 元のメソッドに戻す
  78.     plan_enemy_hpsp_draw_dispose
  79.   end
  80.   #--------------------------------------------------------------------------
  81.   # ● 框架更新
  82.   #--------------------------------------------------------------------------
  83.   alias plan_enemy_hpsp_draw_update update
  84.   def update
  85.     # 元のメソッドに戻す
  86.     plan_enemy_hpsp_draw_update
  87.     # エネミーの場合
  88.     if @battler.is_a?(Game_Enemy)
  89.       @enemy_hpsp_window.visible = @battler_visible
  90.       # 调整窗口坐标
  91.       width = PLAN_HPSP_DRAW::DRAW_WIDTH
  92.       @enemy_hpsp_window.x = self.x - width / 2 - 18
  93.       @enemy_hpsp_window.y = self.y - 30
  94.       @enemy_hpsp_window.z = 0
  95.       @now_enemy_hpsp = []
  96.       if PLAN_HPSP_DRAW::DRAW_NAME
  97.         @now_enemy_hpsp.push(@battler.name)
  98.       end
  99.       if PLAN_HPSP_DRAW::DRAW_HP
  100.         @now_enemy_hpsp.push(@battler.hp)
  101.       end
  102.       if PLAN_HPSP_DRAW::DRAW_SP
  103.         @now_enemy_hpsp.push(@battler.sp)
  104.       end
  105.       if @old_enemy_hpsp != @now_enemy_hpsp and $game_temp.enemy_hpsp_refresh
  106.         @old_enemy_hpsp = @now_enemy_hpsp
  107.         @enemy_hpsp_window.contents.clear
  108.         y = 0
  109.         width = PLAN_HPSP_DRAW::DRAW_WIDTH + 32
  110.         one_line = ((PLAN_HPSP_DRAW::FONT_SIZE * 100 / 28) * 32) / 100
  111.         if PLAN_HPSP_DRAW::DRAW_NAME
  112.           @enemy_hpsp_window.draw_actor_name(@battler, 0, y, width - 32)
  113.           y += one_line + PLAN_HPSP_DRAW::DRAW_SPACE
  114.         end
  115.         if PLAN_HPSP_DRAW::DRAW_HP
  116.           @enemy_hpsp_window.draw_actor_hp(@battler, 0, y, width - 32)
  117.           y += one_line + PLAN_HPSP_DRAW::DRAW_SPACE
  118.         end
  119.         if PLAN_HPSP_DRAW::DRAW_SP
  120.           @enemy_hpsp_window.draw_actor_sp(@battler, 0, y, width - 32)
  121.         end
  122.         Graphics.frame_reset
  123.       end
  124.     end
  125.   end
  126.   #--------------------------------------------------------------------------
  127.   # ● visible の設定
  128.   #--------------------------------------------------------------------------
  129.   if !method_defined?("plan_enemy_hpsp_draw_visible=")
  130.     alias plan_enemy_hpsp_draw_visible= visible=
  131.   end
  132.   def visible=(bool)
  133.     # 虚拟的情况
  134.     if @battler.is_a?(Game_Enemy)
  135.       @enemy_hpsp_window.visible = bool
  136.     end
  137.     # 恢复原来的方法
  138.     self.plan_enemy_hpsp_draw_visible=(bool)
  139.   end
  140.   #--------------------------------------------------------------------------
  141.   # ● 设置不透明度
  142.   #--------------------------------------------------------------------------
  143.   if !method_defined?("plan_enemy_hpsp_draw_opacity=")
  144.     alias plan_enemy_hpsp_draw_opacity= opacity=
  145.   end
  146.   def opacity=(n)
  147.     # 恢复原来的方法
  148.     self.plan_enemy_hpsp_draw_opacity=(n)
  149.     # 虚拟的情况
  150.     if @battler.is_a?(Game_Enemy)
  151.       @enemy_hpsp_window.contents_opacity = n
  152.     end
  153.   end
  154.   #--------------------------------------------------------------------------
  155.   # ● 伤害
  156.   #--------------------------------------------------------------------------
  157.   def damage(value, critical)
  158.     super(value, critical)
  159.     bitmap = @_damage_sprite.bitmap
  160.     @_damage_sprite.dispose
  161.     @_damage_sprite = ::Sprite.new(Viewport.new(0, 0, 640, 480))
  162.     @_damage_sprite.bitmap = bitmap
  163.     @_damage_sprite.ox = 80
  164.     @_damage_sprite.oy = 20
  165.     @_damage_sprite.x = self.x
  166.     @_damage_sprite.y = self.y - self.oy / 2
  167.     @_damage_sprite.viewport.z = self.viewport.z + 1
  168.     @_damage_sprite.z = 3000
  169.     @_damage_duration = 40
  170.   end
  171.   #--------------------------------------------------------------------------
  172.   # ● 伤害解除
  173.   #--------------------------------------------------------------------------
  174.   def dispose_damage
  175.     if @_damage_sprite != nil
  176.       @_damage_sprite.viewport.dispose
  177.     end
  178.     super
  179.   end
  180. end
  181. class Game_Temp
  182.   #--------------------------------------------------------------------------
  183.   # ● 公开实例变量
  184.   #--------------------------------------------------------------------------
  185.   attr_accessor :enemy_hpsp_refresh
  186.   #--------------------------------------------------------------------------
  187.   # ● 对象初始化
  188.   #--------------------------------------------------------------------------
  189.   alias plan_enemy_hpsp_draw_initialize initialize
  190.   def initialize
  191.     # 恢复原来的方法
  192.     plan_enemy_hpsp_draw_initialize
  193.     @enemy_hpsp_refresh = false
  194.   end
  195. end
  196. class Scene_Battle
  197.   #--------------------------------------------------------------------------
  198.   # ● 预战斗阶段开始(用于艾涅米名字+字母)
  199.   #--------------------------------------------------------------------------
  200.   alias plan_enemy_hpsp_draw_start_phase1 start_phase1
  201.   def start_phase1
  202.     $game_temp.enemy_hpsp_refresh = true
  203.     # 恢复原来的方法
  204.     plan_enemy_hpsp_draw_start_phase1
  205.   end
  206.   #--------------------------------------------------------------------------
  207.   # ● 开始方命令阶段(用于枚举名称+字母)
  208.   #--------------------------------------------------------------------------
  209.   alias plan_enemy_hpsp_draw_start_phase2 start_phase2
  210.   def start_phase2
  211.     $game_temp.enemy_hpsp_refresh = false
  212.     # 恢复原来的方法
  213.     plan_enemy_hpsp_draw_start_phase2
  214.   end
  215.   #--------------------------------------------------------------------------
  216.   # ● 框架更新(主阶段步骤5:伤害表示)
  217.   #--------------------------------------------------------------------------
  218.   alias plan_enemy_hpsp_draw_update_phase4_step5 update_phase4_step5
  219.   def update_phase4_step5
  220.     # 恢复原来的方法
  221.     plan_enemy_hpsp_draw_update_phase4_step5
  222.     $game_temp.enemy_hpsp_refresh = true
  223.   end
  224.   #--------------------------------------------------------------------------
  225.   # ● 框架更新(主阶段步骤6:刷新)
  226.   #--------------------------------------------------------------------------
  227.   alias plan_enemy_hpsp_draw_update_phase4_step6 update_phase4_step6
  228.   def update_phase4_step6
  229.     # 恢复原来的方法
  230.     plan_enemy_hpsp_draw_update_phase4_step6
  231.     $game_temp.enemy_hpsp_refresh = false
  232.   end
  233. end
  234. class Window_Base < Window
  235.   #--------------------------------------------------------------------------
  236.   # ● 描绘名字
  237.   #--------------------------------------------------------------------------
  238.   def draw_actor_name(actor, x, y, width = 300)
  239.     self.contents.font.color = Color.new(60, 255, 80) # 敌人名字的颜色
  240.     self.contents.font.bold = true # false
  241.     self.contents.draw_text(x, y, 200, 32, actor.name,1)
  242.   end
  243. end
  244. class Window_Base < Window
  245.   def initialize(x, y, width, height, viewport = nil)
  246.     super(viewport)
  247.     @windowskin_name = $game_system.windowskin_name
  248.     self.windowskin = RPG::Cache.windowskin(@windowskin_name)
  249.     self.x = x
  250.     self.y = y
  251.     self.width = width
  252.     self.height = height
  253.   end
  254. end

Lv2.观梦者

梦石
0
星屑
841
在线时间
85 小时
注册时间
2005-11-21
帖子
85
2
发表于 2022-4-8 09:39:46 | 只看该作者
你想显示角色的血条魔条?简单说就是画2个矩形。
这里有教程:https://v.youku.com/v_show/id_XNDI5NjcwODI0.html
本人自开仙境传说RO怀旧1.0服务器,QQ群552321558,人不多,娱乐用。
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
3186
在线时间
1863 小时
注册时间
2010-6-19
帖子
1205
3
 楼主| 发表于 2022-4-8 19:41:16 | 只看该作者
黑夜守望者 发表于 2022-4-8 09:39
你想显示角色的血条魔条?简单说就是画2个矩形。
这里有教程:https://v.youku.com/v_show/id_XNDI5NjcwODI ...

我想做的是每个人都有独立窗口,里面有独立的血条魔法条~
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
841
在线时间
85 小时
注册时间
2005-11-21
帖子
85
4
发表于 2022-4-8 21:39:32 | 只看该作者
黑米馒头 发表于 2022-4-8 19:41
我想做的是每个人都有独立窗口,里面有独立的血条魔法条~

那不是一样的嘛,你在类里添加了血魔条,所有实例就都有了。
本人自开仙境传说RO怀旧1.0服务器,QQ群552321558,人不多,娱乐用。
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
841
在线时间
85 小时
注册时间
2005-11-21
帖子
85
5
发表于 2022-4-8 23:55:11 | 只看该作者
本帖最后由 黑夜守望者 于 2022-4-9 00:04 编辑

Window_Base里面追加2个定义:
  1.   def draw_actor_hp_bar(actor, x , y)
  2.     self.contents.fill_rect(x, y, 120,10, Color.new(0, 0, 0, 255))
  3.     self.contents.fill_rect(x, y, actor.hp.to_f/actor.maxhp.to_f*120,10, Color.new(200, 100, 100, 255))
  4.   end
  5.   def draw_actor_sp_bar(actor, x , y)
  6.     self.contents.fill_rect(x, y, 120,10, Color.new(0, 0, 0, 255))
  7.     self.contents.fill_rect(x, y, actor.sp.to_f/actor.maxsp.to_f*120,10, Color.new(100, 100, 200, 255))
  8.   end
复制代码

然后在Window_BattleStatus的刷新函数里加上
  1. draw_actor_hp_bar(actor, i*160+4, 60)
  2. draw_actor_sp_bar(actor, i*160+4, 92)
复制代码

效果:
本人自开仙境传说RO怀旧1.0服务器,QQ群552321558,人不多,娱乐用。
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
3186
在线时间
1863 小时
注册时间
2010-6-19
帖子
1205
6
 楼主| 发表于 2022-4-9 08:54:39 | 只看该作者
黑夜守望者 发表于 2022-4-8 23:55
Window_Base里面追加2个定义:

然后在Window_BattleStatus的刷新函数里加上

这个方法我会了,就是不知道如何把每个人的血条都放到独立的框里面,你这样是全员的血条蓝条都在一个窗口显示
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
841
在线时间
85 小时
注册时间
2005-11-21
帖子
85
7
发表于 2022-4-9 10:59:31 | 只看该作者
黑米馒头 发表于 2022-4-9 08:54
这个方法我会了,就是不知道如何把每个人的血条都放到独立的框里面,你这样是全员的血条蓝条都在一个窗口 ...


那就创建个窗口显示啊。和创建矩形的方法类似。
本人自开仙境传说RO怀旧1.0服务器,QQ群552321558,人不多,娱乐用。
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
3186
在线时间
1863 小时
注册时间
2010-6-19
帖子
1205
8
 楼主| 发表于 2022-4-9 11:52:47 | 只看该作者
黑夜守望者 发表于 2022-4-9 10:59
那就创建个窗口显示啊。和创建矩形的方法类似。

可以的话帮忙弄个范例,我可以学着弄…
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
841
在线时间
85 小时
注册时间
2005-11-21
帖子
85
9
发表于 2022-4-9 12:38:11 | 只看该作者
本帖最后由 黑夜守望者 于 2022-4-9 13:52 编辑

你可以新建一个专门显示血条魔条的窗口类:
RUBY 代码复制
  1. class Window_actorhpspbar < Window_Base
  2.   #--------------------------------------------------------------------------
  3.   # ● 初始化对像
  4.   #--------------------------------------------------------------------------
  5.   def initialize(num)
  6.     super(num*160,260,160,64)
  7.     @num = num
  8.     self.contents = Bitmap.new(120 , 30 )
  9.     refresh
  10.   end
  11.   def refresh
  12.     self.contents.clear
  13.       actor = $game_party.actors[@num]
  14.       draw_actor_hp_bar(actor, 0, 0)
  15.       draw_actor_sp_bar(actor, 0, 20)
  16.     end
  17. end

然后再战斗场景Scene_Battle中调用,刷新,释放。
RUBY 代码复制
  1. @hpspbar_window1 = Window_actorhpspbar.new(0)
  2.     if $game_party.actors[1] != nil
  3.      @hpspbar_window2 = Window_actorhpspbar.new(1)
  4.     end
  5.     if $game_party.actors[2] != nil
  6.      @hpspbar_window3 = Window_actorhpspbar.new(2)
  7.      end
  8.     if $game_party.actors[3] != nil
  9.      @hpspbar_window4 = Window_actorhpspbar.new(3)
  10.     end

RUBY 代码复制
  1. @hpspbar_window1.dispose
  2.     if @hpspbar_window2 != nil
  3.      @hpspbar_window2.dispose
  4.     end
  5.     if @hpspbar_window3 != nil
  6.      @hpspbar_window3.dispose
  7.     end
  8.     if @hpspbar_window4 != nil
  9.      @hpspbar_window4.dispose
  10.     end

RUBY 代码复制
  1. @hpspbar_window1.refresh
  2.     if @hpspbar_window2 != nil
  3.      @hpspbar_window2.refresh
  4.     end
  5.     if @hpspbar_window3 != nil
  6.      @hpspbar_window3.refresh
  7.     end
  8.     if @hpspbar_window4 != nil
  9.      @hpspbar_window4.refresh
  10.     end

你效果是不是要这样的?

评分

参与人数 1星屑 +200 +1 收起 理由
RyanBern + 200 + 1 认可答案

查看全部评分

本人自开仙境传说RO怀旧1.0服务器,QQ群552321558,人不多,娱乐用。
回复 支持 1 反对 0

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
3186
在线时间
1863 小时
注册时间
2010-6-19
帖子
1205
10
 楼主| 发表于 2022-4-9 14:45:15 | 只看该作者
黑夜守望者 发表于 2022-4-9 12:38
你可以新建一个专门显示血条魔条的窗口类:
class Window_actorhpspbar < Window_Base
  #---------------- ...

就是这个效果,3Q
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-30 02:11

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表