赞 | 0 |
VIP | 0 |
好人卡 | 0 |
积分 | 1 |
经验 | 21598 |
最后登录 | 2017-9-25 |
在线时间 | 448 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 50
- 在线时间
- 448 小时
- 注册时间
- 2011-10-9
- 帖子
- 184
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 冷徹心扉 于 2012-12-18 14:14 编辑
其實不算什麼問題,只是希望能讓這個腳本更完美一點
以下是相當優秀且簡單的顯示NPC名稱腳本,只要在事件名稱輸入文字即可顯示,前綴EV開頭則不顯示,如EV001
有個小瑕疵是當畫面調用但入淡出、或顯示圖片時
該NPC名稱還是會顯示在最上層,有些不美觀
如果能夠修改其優先度就好了- #==============================================================================
- # 顯示NPC名
- #------------------------------------------------------------------------------
- # 跟原版一樣,EV開頭的不顯示,逗號後加顏色代碼
- # 修改某事件名的方法:
- # set_npc_name("新名", 事件ID, 地圖ID, 是否永久生效)
- # 事件ID 為空時表示當前事件
- # 地圖ID 為空時表示當前地圖
- # 是否永久生效 默認永久,否則只允許修改當前地圖
- #==============================================================================
- # 參數設定
- #==============================================================================
- module NPC
- NAME_FONT = "DFPHuaZongW5-B5"
- NAME_SIZE = 11
- NAME_SHADOW = true
- NAME_WIDTH = 200
- end
- #==============================================================================
- # 重定事件名
- #==============================================================================
- def set_npc_name(name, event_id = nil, map_id = nil, forever = true)
- # 處理事件 ID
- if event_id == nil
- event_id = $game_map.interpreter.event_id
- end
- # 處理地圖 ID
- if map_id == nil
- $game_map.events[event_id].name = name
- map_id = $game_map.map_id
- else
- map_id = map_id
- end
- return unless forever
- data = load_data(sprintf("Data/Map%03d.rvdata", map_id))
- # 更改名
- data.events[event_id].name = name
- save_data(data, sprintf("Data/Map%03d.rvdata", map_id))
- end
- #==============================================================================
- # ■ Game_Character
- #==============================================================================
- class Game_Character
- #--------------------------------------------------------------------------
- # ◎ 定義實例變量
- #--------------------------------------------------------------------------
- attr_accessor :name # 名稱
- #--------------------------------------------------------------------------
- # ◎ 初始化對象
- #--------------------------------------------------------------------------
- alias character_ini initialize
- def initialize
- character_ini
- @name = ""
- end
- end
- #==============================================================================
- # ■ Game_Event
- #==============================================================================
- class Game_Event < Game_Character
- #--------------------------------------------------------------------------
- # ◎ 定義實例變量
- #--------------------------------------------------------------------------
- attr_reader :erased
- #--------------------------------------------------------------------------
- # ◎ 初始化對像
- # map_id : 地圖 ID
- # event : 事件 (RPG::Event)
- #--------------------------------------------------------------------------
- alias event_ini initialize
- def initialize(map_id, event)
- event_ini(map_id, event)
- @name = @event.name
- end
- end
- #==============================================================================
- # ■ Game_Player
- #==============================================================================
- #class Game_Player < Game_Character
- #--------------------------------------------------------------------------
- # ◎ 顯示主角名字
- #--------------------------------------------------------------------------
- #def name
- #return $game_party.members[0].name
- #end
- #end
- #==============================================================================
- # ■ Game_Interpreter
- #==============================================================================
- class Game_Interpreter
- #--------------------------------------------------------------------------
- # ◎ 定義實例變量
- #--------------------------------------------------------------------------
- attr_reader :event_id
- end
- #==============================================================================
- # ■ Sprite_Character
- #==============================================================================
- class Sprite_Character < Sprite_Base
- #--------------------------------------------------------------------------
- # ◎ 初始化對象
- # viewport : 視區
- # character : 角色 (Game_Character)
- #--------------------------------------------------------------------------
- def initialize(viewport, character = nil)
- super(viewport)
- @character = character
- @balloon_duration = 0
- ## 名稱
- @name = @character.name
- set_name_sprite
- update
- end
- #--------------------------------------------------------------------------
- # ◎ 釋放
- #--------------------------------------------------------------------------
- def dispose
- dispose_balloon
- super
- ##
- return if @name_sprite == nil
- @name_sprite.bitmap.dispose
- @name_sprite.dispose
- end
- #--------------------------------------------------------------------------
- # ● 更新畫面
- #--------------------------------------------------------------------------
- def update
- super
- update_bitmap
- self.visible = (not @character.transparent)
- update_src_rect
- self.x = @character.screen_x
- self.y = @character.screen_y
- self.z = @character.screen_z
- self.opacity = @character.opacity
- self.blend_type = @character.blend_type
- self.bush_depth = @character.bush_depth
- update_balloon
- if @character.animation_id != 0
- animation = $data_animations[@character.animation_id]
- start_animation(animation)
- @character.animation_id = 0
- end
- if @character.balloon_id != 0
- @balloon_id = @character.balloon_id
- start_balloon
- @character.balloon_id = 0
- end
- ## 名稱可視和跟隨
- unless @name_sprite == nil or @name_sprite.disposed?
- if @character.is_a?(Game_Event) and @character.erased
- @name_sprite.visible = false
- return
- else
- @name_sprite.visible = true
- end
- if @character.is_a?(Game_Player) and @character.in_vehicle?
- @name_sprite.visible = false
- return
- else
- @name_sprite.visible = true
- end
- if @name != @character.name
- @name = @character.name
- refresh_name_sprite
- end
- @name_sprite.x = self.x - 80
- @name_sprite.y = self.y - self.height - NPC::NAME_SIZE+2
- @name_sprite.z = self.z+1
- end
- end
- #--------------------------------------------------------------------------
- # ○ 設定 NPC 名稱
- #--------------------------------------------------------------------------
- def set_name_sprite
- return if @character.name[0, 2] == "EV"
- return if @character.name == ""
- return if @character.character_name == ""
- return if @character.is_a?(Game_Event) and @character.erased
- @color_board = Window_Base.new(0,0,33,33)
- @color_board.visible = false
- @name_sprite = Sprite.new
- @name_sprite.bitmap = Bitmap.new(NPC::NAME_WIDTH, NPC::NAME_SIZE+2)
- @name_sprite.bitmap.font.name = NPC::NAME_FONT
- @name_sprite.bitmap.font.size = NPC::NAME_SIZE
- @name_sprite.bitmap.font.shadow = NPC::NAME_SHADOW
- refresh_name_sprite
- end
- #--------------------------------------------------------------------------
- # ○ 更新 NPC 名稱
- #--------------------------------------------------------------------------
- def refresh_name_sprite
- name,color_index = @name.split(/,/)
- color_index = 0 if color_index == ""
- @name_sprite.bitmap.font.color = @color_board.text_color(color_index.to_i)
- @name_sprite.bitmap.clear
- @name_sprite.bitmap.draw_text(0,0,160,NPC::NAME_SIZE+2,name,1)
- end
- end
复制代码 感謝a364774426大,這個問題糾結我好久了{:2_249:} |
|