查看: 2875|回复: 3

[已经解决] 角色或事件显示变量条脚本

[复制链接]
梦石
0
星屑
50
在线时间
130 小时
注册时间
2011-3-10
回帖
50
发表于 2016-1-13 05:08:45 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 s20810 于 2016-1-13 05:10 编辑

请问这脚本如果要让事件显示变量条该如何设置?
原范本已失连不知道该如何使用,烦请大大们帮忙@@
@无限の剣制

[pre lang="ruby"]#==============================================================================
# ■ Sprite
#==============================================================================
class Sprite
  #--------------------------------------------------------------------------
  # ● 血条配色
  #--------------------------------------------------------------------------
  ALPHA      = 192                              # 不透明度
  FONT_COLOR = Color.new(64,  64, 240, ALPHA)  # hp 数值
  B_COLOR    = Color.new(255, 255, 255, ALPHA)  # 血条外框
  BG_COLOR   = Color.new(  0,   0,   0, ALPHA)  # 血条底
  HP_COLOR_1 = Color.new(255, 128,  64, ALPHA)  # 血条渐变色 1
  HP_COLOR_2 = Color.new(240, 192,  64, ALPHA)  # 血条渐变色 2
  #--------------------------------------------------------------------------
  # ● 画血条
  #--------------------------------------------------------------------------
  def draw_character_hp(character, x, y, width)
    draw_character_hp_gauge(character, x, y, width)
    self.bitmap.font.color = FONT_COLOR
    self.bitmap.font.size = 12
    self.bitmap.draw_text(0,0,32,20,character.hp,2)
  end
  #--------------------------------------------------------------------------
  # ● 画血条的背景条
  #--------------------------------------------------------------------------
  def draw_character_hp_gauge(character, x, y, width)
    gw = width * character.hp / character.maxhp
    self.bitmap.fill_rect(x, y+16, width+2, 5, B_COLOR)
    self.bitmap.fill_rect(x+1, y+17, width, 3, BG_COLOR)
    self.bitmap.gradient_fill_rect(x+1, y+17, gw, 3, HP_COLOR_1, HP_COLOR_2)
  end
end

#==============================================================================
# ■ Sprite_Character
#==============================================================================
class Sprite_Character < Sprite_Base
  #--------------------------------------------------------------------------
  # ● 定义实例变量
  #--------------------------------------------------------------------------
  attr_accessor :character
  #--------------------------------------------------------------------------
  # ● 释放
  #--------------------------------------------------------------------------
  def dispose
    dispose_balloon
    super
    if @hp_sprite != nil
      @hp_sprite.bitmap.dispose
      @hp_sprite.dispose
      @hp_sprite = nil
    end
  end
  #--------------------------------------------------------------------------
  # ● 更新画面
  #--------------------------------------------------------------------------
  alias old_update update
  def update
    old_update
    if @hp_sprite == nil
      unless @character.is_a?(Game_Vehicle) or @character.maxhp <= 0
        hp_sprite_set(@character)
      end
    end
    unless @character.is_a?(Game_Vehicle)
      hp_update if @character.update_hp
    end
    hp_follow
  end
  #--------------------------------------------------------------------------
  # ● 显示 hp
  #--------------------------------------------------------------------------
  def hp_sprite_set(character)
    @hp_sprite = Sprite.new
    @hp_sprite.bitmap = Bitmap.new(32, 24)
    @hp_sprite.draw_character_hp(character, 0, 0, width = 30)
    @hp_sprite.x = self.x - @hp_sprite.width/2
    @hp_sprite.y = self.y - self.height - 21
    @hp_sprite.z = self.z + 1
  end
  #--------------------------------------------------------------------------
  # ● 让 hp 跟随事件或角色
  #--------------------------------------------------------------------------
  def hp_follow
    return if @hp_sprite == nil
    return if @character.is_a?(Game_Vehicle)
    @hp_sprite.x = self.x - @hp_sprite.width/2
    @hp_sprite.y = self.y - self.height - 21
    @hp_sprite.z = self.z + 1
  end
  #--------------------------------------------------------------------------
  # ● 刷新 hp
  #--------------------------------------------------------------------------
  def hp_update
    return if @hp_sprite == nil
    return if @character.is_a?(Game_Vehicle)
    @character.update_hp = false
    @hp_sprite.bitmap.clear
    @hp_sprite.draw_character_hp(@character, 0, 0, width = 30)
  end
end

#==============================================================================
# ■ Game_Event
#==============================================================================
class Game_Event < Game_Character
  #--------------------------------------------------------------------------
  # ● 定义实例变量
  #--------------------------------------------------------------------------
  attr_reader   :hp
  attr_reader   :maxhp
  attr_accessor  :update_hp
  #--------------------------------------------------------------------------
  # ● 初始化对像
  #     map_id : 地图 ID
  #     event  : 事件 (RPG::Event)
  #--------------------------------------------------------------------------
  alias ini initialize
  def initialize(map_id, event)
    @maxhp = @hp = 0
    @update_hp = false
    ini(map_id, event)
  end
  #--------------------------------------------------------------------------
  # ● 更改 hp
  #     hp : 事件自身的hp
  #--------------------------------------------------------------------------
  def hp=(hp)
    @hp = hp
    @hp = 0 if @hp < 0
    @update_hp = true
  end
  #--------------------------------------------------------------------------
  # ● 初始化 maxhp
  #     maxhp : 事件自身的最大 hp
  #--------------------------------------------------------------------------
  def maxhp=(maxhp)
    @maxhp = @hp = maxhp
  end
end

#==============================================================================
# ■ Game_Player
#==============================================================================
class Game_Player < Game_Character
  #--------------------------------------------------------------------------
  # ● 定义实例变量
  #--------------------------------------------------------------------------
  attr_reader    :hp
  attr_reader    :maxhp
  attr_accessor  :update_hp
  #--------------------------------------------------------------------------
  # ● 初始化对象
  #--------------------------------------------------------------------------
  alias ini initialize
  def initialize
    @maxhp = @hp = 0
    @update_hp = false
    ini
  end
  #--------------------------------------------------------------------------
  # ● 刷新
  #--------------------------------------------------------------------------
  def refresh
    if $game_party.members.size == 0
      @character_name = ""
      @character_index = 0
    else
      actor = $game_party.members[0]   # 获得首名角色
      @character_name = actor.character_name
      @character_index = actor.character_index
      #获取角色 hp 和 maxhp
      if @hp != actor.hp or @maxhp != actor.maxhp
        @hp = actor.hp
        @maxhp = actor.maxhp
        @update_hp = true
      end
    end
  end
end

#==============================================================================
# ■ Game_Interpreter
#==============================================================================
class Game_Interpreter
  #--------------------------------------------------------------------------
  # ● 设置正在启动的事件
  #--------------------------------------------------------------------------
  alias old_setup_starting_event setup_starting_event
  def setup_starting_event
    $game_player.refresh
    old_setup_starting_event
  end
end[/pre]

聪仔

梦石
0
星屑
6187
在线时间
3077 小时
注册时间
2013-12-26
回帖
3076
发表于 2016-1-13 08:28:20 | 显示全部楼层
事件脚本...
  1. $game_map.events[事件编号].maxhp = 300
  2. $game_map.events[事件编号].hp = 200
复制代码

评分

参与人数 1梦石 +1 收起 理由
丿梁丶小柒 + 1 认可答案

查看全部评分

聪聪全国第三帅...
他们都叫我【人赢聪】
我的RM能力雷达图:

回复

使用道具 举报

梦石
0
星屑
50
在线时间
130 小时
注册时间
2011-3-10
回帖
50
 楼主| 发表于 2016-1-14 02:48:03 | 显示全部楼层
本帖最后由 s20810 于 2016-1-14 03:03 编辑
正太君 发表于 2016-1-13 08:28
事件脚本...


感謝大大0.0

請問有開關的嗎@@?

還有如何釋放為0的變量條...
回复

使用道具 举报

聪仔

梦石
0
星屑
6187
在线时间
3077 小时
注册时间
2013-12-26
回帖
3076
发表于 2016-1-14 09:11:14 | 显示全部楼层
s20810 发表于 2016-1-14 02:48
感謝大大0.0

請問有開關的嗎@@?

66行下面插入一句
  1. @hp_sprite.bitmap.clear if @character.hp == 0 if @hp_sprite.bitmap if @hp_sprite
复制代码

点评

可以的...  发表于 2016-1-15 09:06
天阿!! 正太君大大人帥又有耐心回復,可以當我好朋友嗎><  发表于 2016-1-15 02:21
聪聪全国第三帅...
他们都叫我【人赢聪】
我的RM能力雷达图:

回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部