Project1
标题:
显示NPC名字不正常。
[打印本页]
作者:
crow2006
时间:
2013-6-1 18:55
标题:
显示NPC名字不正常。
有没有人遇到过这种情况?
满足特定条件才会出现的某些NPC刚出现时候不显示名字,要刷新一下才有。
为什么?
作者:
黄濑凉太
时间:
2013-6-1 18:58
LZ是什么意思?不显示名字?是用了NPC在地图上显示名称的脚本吗?
作者:
crow2006
时间:
2013-6-1 19:01
#==============================================================================
# (新)显示NPC名和图标 v1.04 by 沉影不器
#------------------------------------------------------------------------------
# 功能: 在指定NPC头上显示名/图标,比如有任务的NPC头上多一个提示图标
# 使用方法:
# ① 在事件页里任意位置(默认第一行)加注释,格式为:
# npc=名称,名称颜色 例: npc = 无敌将军,3
# 大小写不限,名称颜色指text_color编号
#
# ② 需要显示图标的事件,在注释任意位置增加\i[图标序号],大小写不限
# ③ 参数设定在脚本第15-20行
# ④ 全局控制是否显示 NPC 名,当脚本第23行指定的开关打开时显示
# 默认第10号开关
#==============================================================================
# 参数设定
#==============================================================================
module NPC
ALL_LIST = true # 是否支持事件页任意位置读取NPC注释
NAME_FONT = "黑体" # 名称字体
NAME_SIZE = 14 # 名称字号
NAME_COLOR = 0 # 名称字色(text_color编号)
NAME_SHADOW = true # 名称字体阴影
NAME_WIDTH = 120 # 名称最大宽度
PLAYER_NAME = false # 是否显示主角名
NAME_SWITCH = 27 # 全局控制是否显示NPC名的开关序号
end
class String
#-------------------------------------------------------------------------
# ○ 读取注释
# section : 字段名
# ignore_caps : 忽略大小写(仅字段名)
#-------------------------------------------------------------------------
def read_note(section, ignore_caps = true)
result = ''
# 忽略大小写时,全部转大写
section.upcase! if ignore_caps
# 转symbol方便比较
s = section.to_sym
self.each_line{|line|
temp = line.split(/=/)
# 去掉干扰字符
temp.each {|i| i.strip!}
temp[0].upcase! if ignore_caps
if temp[0].to_sym == s
unless temp[1] == nil
result = temp[1]
end
# 如果希望同名字段值覆盖前面的字段,去掉下一行
break
end
}
return result
end
end
#==============================================================================
# ■ Game_Character
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# ◎ 定义实例变量
#--------------------------------------------------------------------------
attr_accessor :npcname # NPC名
attr_accessor :npcicon # NPC图标
#--------------------------------------------------------------------------
# ◎ 初始化对象
#--------------------------------------------------------------------------
alias character_ini initialize
def initialize
character_ini
@npcname = ""
@npcicon = -1
end
end
#==============================================================================
# ■ Game_Event
#==============================================================================
class Game_Event < Game_Character
#--------------------------------------------------------------------------
# ◎ 定义实例变量
#--------------------------------------------------------------------------
attr_reader :erased # 暂时消除标志
attr_reader :npcname # NPC 名
attr_reader :npcicon # NPC 图标
#--------------------------------------------------------------------------
# ◎ 刷新
#--------------------------------------------------------------------------
def refresh
new_page = nil
unless @erased # 无法暂时消失的情况下
for page in @event.pages.reverse # 按页面顺序
next unless conditions_met?(page) # 判断是否符合条件
new_page = page
break
end
end
if new_page != @page # 事件页是否被改变?
clear_starting # 清除启动中标志
setup(new_page) # 设置事件页
check_event_trigger_auto # 判断自动事件启动
### NPC名
get_npcinfo
### 地图刷新
$game_map.need_refresh = true
end
end
#--------------------------------------------------------------------------
# ○ 获取 NPC 信息
#--------------------------------------------------------------------------
def get_npcinfo
@npcname = ""
@npcicon = -1
return if @list == nil
for line in @list
if line.code == 108 or line.code == 408
unless line.parameters.empty?
npcinfo = line.parameters.to_s.read_note('npc')
@npcname = npcinfo.gsub(/\\I\[(\d+)\]/i) {}
@npcicon = $1 == nil ? -1 : $1.to_i
return
end
end
break unless NPC::ALL_LIST
end
end
end
#==============================================================================
# ■ Game_Player
#==============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# ○ NPC名
#--------------------------------------------------------------------------
def npcname
return NPC::PLAYER_NAME ? $game_party.members[0].name : ""
end
end
#==============================================================================
# ■ Sprite_Character
#==============================================================================
class Sprite_Character < Sprite_Base
#--------------------------------------------------------------------------
# ◎ 初始化对象
# viewport : 视区
# character : 角色 (Game_Character)
#--------------------------------------------------------------------------
def initialize(viewport, character = nil)
super(viewport)
@character = character
@balloon_duration = 0
### NPC 名
@npcname = @character.npcname
@npcicon = @character.npcicon
set_name_sprite
update
end
#--------------------------------------------------------------------------
# ◎ 释放
#--------------------------------------------------------------------------
def dispose
dispose_balloon
super
###
return if @name_sprite == nil
@name_sprite.bitmap.dispose
@name_sprite.dispose
end
#--------------------------------------------------------------------------
# ◎ 更新画面
#--------------------------------------------------------------------------
alias npc_update update
def update
npc_update
### NPC 名
if @name_sprite != nil and !@name_sprite.disposed?
### 可视性
if $game_switches[NPC::NAME_SWITCH]
@name_sprite.visible = true
else
@name_sprite.visible = false
return
end
if @character.is_a?(Game_Event) and
@character.erased || @character.character_name == ""
@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
return unless @name_sprite.visible
if @npcname != @character.npcname or @npcicon != @character.npcicon
@npcname = @character.npcname
@npcicon = @character.npcicon
refresh_name_sprite
end
### 坐标跟随
@name_sprite.x = self.x - NPC::NAME_WIDTH/2
@name_sprite.y = self.y - self.height-24-NPC::NAME_SIZE-2
@name_sprite.z = self.z+1
end
end
#--------------------------------------------------------------------------
# ○ 设定 NPC 名称
#--------------------------------------------------------------------------
def set_name_sprite
return if @character.is_a?(Game_Event) and @character.erased
return if @character.character_name == ""
@name_sprite = Sprite.new(self.viewport)
@name_sprite.bitmap = Bitmap.new(NPC::NAME_WIDTH, 24+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 = @npcname.split(/,/)
color_index = NPC::NAME_COLOR if color_index == ""
@name_sprite.bitmap.font.color = text_color(color_index.to_i)
@name_sprite.bitmap.clear
## 描绘图标
if @npcicon > 0
bitmap = Cache.system("Iconset")
rect = Rect.new(@npcicon % 16 * 24, @npcicon / 16 * 24, 24, 24)
@name_sprite.bitmap.blt(NPC::NAME_WIDTH/2-12, 0, bitmap, rect)
end
# 描绘名
@name_sprite.bitmap.draw_text(0,24,NPC::NAME_WIDTH,NPC::NAME_SIZE+2,name,1)
end
#--------------------------------------------------------------------------
# ○ 获取文字颜色色
# n : 文字颜色编号 (0~31)
#--------------------------------------------------------------------------
def text_color(n)
x = 64 + (n % 8) * 8
y = 96 + (n / 8) * 8
return Cache.system("Window").get_pixel(x, y)
end
end
复制代码
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1