Project1
标题:
求改良关键词系统的脚本使其能在公共事件使用..
[打印本页]
作者:
结城照美
时间:
2013-4-23 18:36
标题:
求改良关键词系统的脚本使其能在公共事件使用..
本帖最后由 结城照美 于 2013-4-23 22:55 编辑
添加的脚本如下
(出处)
:
010609w6p31rra1iiydi6p.rar
(245.32 KB, 下载次数: 62)
2013-4-23 18:35 上传
点击文件名下载附件
原作者的范例
class Sprite_FF2Cursor < Sprite_Base
def initialize(*args)
super(*args)
self.bitmap = Cache.system("Hand_cursor")
@frame = 0
self.src_rect.set(@frame / 2 * 24,0,24,24)
self.z = 205
self.visible = false
end
def update
super
self.src_rect.set(@frame / 2 * 24,0,24,24)
@frame += 1
@frame %= 8
end
end
复制代码
追加关键词库↓
class Game_Player
attr_reader :keywords
alias :odd_key_ini :initialize
def initialize(*args)
odd_key_ini(*args)
@keywords = []
end
end
复制代码
class Game_Event
WordFF2 = "系统"
alias :ff2_start :start
def start
if list[0].code == 108 and list[0].parameters[0].index(WordFF2)
ff2_keyword_system
return
end
ff2_start
end
def ff2_keyword_system
$scene = Scene_FF2Key.new(list,@event.id)
end
end
复制代码
class Scene_FF2Key < Scene_Base
def initialize(list,id)
super()
@ff2_event = Event_FF2.new(list,id)
@ff2_cursor = Sprite_FF2Cursor.new
@ff2_cursor.visible = false
end
def start
@showing = true
@message_window = Window_Base.new(0,0,544,128)
@message_window.z = 200
if $game_message.face_name.empty?
@contents_x = 0
else
_name = $game_message.face_name
_index = $game_message.face_index
@message_window.draw_face(_name, _index, 0, 0)
@contents_x = 112
end
@contents_y = 0
@action_window = Window_Command.new(144,[" 问"," 记"," 道具"])
@action_window.y = 312
@action_window.z = 200
@items_window = Window_FFItem.new(144,312,400,104)
@items_window.z = 202
@items_window.active = false
@items_window.visible = false
@keywords_window = Window_KeyWords.new(144,312,400,104)
@keywords_window.z = 200
@keywords_window.active = false
@keywords_window.visible = false
@spriteset = Spriteset_Map.new
#create_cursor
end
def post_start
show_message
end
def terminate
@message_window.dispose
@action_window.dispose
@items_window.dispose
@keywords_window.dispose
@spriteset.dispose
end
def update
if @action_window.active
update_action
return
elsif @items_window.active
update_item
return
elsif @keywords_window.active
update_keyword
return
else
update_message
return
end
end
def update_action
@action_window.update
if Input.trigger?(Input::B)
Sound.play_cancel
$scene = Scene_Map.new
return
end
if Input.trigger?(Input::C)
Sound.play_decision
@action_window.active =false
case @action_window.index
when 0
@keywords_window.active = true
@keywords_window.visible = true
return
when 1
@newkey_index = 0
if @keywords.empty?
@action_window.active = true
else
@ff2_cursor.visible = true
update_message_cursor
end
return
when 2
@items_window.active = true
@items_window.visible = true
@keywords_window.visible = false
return
end
end
end
def update_item
@items_window.update
if Input.trigger?(Input::B)
Sound.play_cancel
@items_window.index = 0
@items_window.visible = false
@items_window.active = false
@action_window.active = true
return
end
if Input.trigger?(Input::C)
Sound.play_decision
use_item
return
end
end
def update_keyword
@keywords_window.update
if Input.trigger?(Input::B)
Sound.play_decision
@keywords_window.index = 0 if $game_player.keywords.size > 0
@keywords_window.active = false
@keywords_window.visible = false
@action_window.active = true
return
end
if Input.trigger?(Input::C)
Sound.play_decision
use_keyword
return
end
end
def update_message
@message_window.update
@ff2_cursor.update
if Input.trigger?(Input::LEFT)
Sound.play_cursor
@newkey_index -= 1
@newkey_index %= @keywords.size
update_message_cursor
return
end
if Input.trigger?(Input::RIGHT)
Sound.play_cursor
@newkey_index += 1
@newkey_index %= @keywords.size
update_message_cursor
return
end
if Input.trigger?(Input::B)
Sound.play_cancel
@action_window.active = true
@ff2_cursor.visible = false
return
end
if Input.trigger?(Input::C)
Sound.play_decision
remember_keyword
@action_window.active = true
@keywords_window.visible = true
@ff2_cursor.visible = false
@keywords_window.refresh
return
end
end
def use_item
return if item.nil?
if list = @ff2_event.item_events[item]
$scene = Scene_Map.new
$game_map.interpreter.setup(list,event_id)
return
end
end
def use_keyword
if list = @ff2_event.keyword_events[key_word]
$scene = Scene_Map.new
$game_map.interpreter.setup(list,event_id)
return
else
@keywords_window.active = false
@keywords_window.visible = false
@action_window.active = true
end
end
def remember_keyword
Sound.play_decision
($game_player.keywords << @keywords[@newkey_index]).uniq!
$game_player.keywords.sort!
end
def show_message
message = @ff2_event.message
@keywords = []
@positions = []
_key_word = ""
_in_keyword = false
loop do
c = message.slice!(/./m) # 获取一个文字
case c
when nil # 无法获取文字时
break
when "\x00" # 新行
new_line
else # 一般文字
if c == "【"
@message_window.contents.font.color = @message_window.crisis_color
_in_keyword = true
@word_position = [@contents_x + 12,@contents_y]
draw_char(c)
elsif c == "】"
draw_char(c)
@message_window.contents.font.color = @message_window.normal_color
_in_keyword = false
@keywords << _key_word
_key_word = ""
@positions << @word_position
else
_key_word += c if _in_keyword
draw_char(c)
end
end
Graphics.update
@message_window.update
end
end
def draw_char(c)
@message_window.contents.draw_text(@contents_x, @contents_y, 40, 24, c)
c_width = @message_window.contents.text_size(c).width
@contents_x += c_width
if @contents_x > 496
@contents_x = $game_message.face_name.empty? ? 0 : 112
@contents_y += 24
end
end
def update_message_cursor
return unless @ff2_cursor.visible
x,y = @positions[@newkey_index]
@ff2_cursor.x = x
@ff2_cursor.y = y + 16
end
def item
@items_window.item.name unless @items_window.item.nil?
end
def key_word
@keywords_window.item
end
def event_id
@ff2_event.event_id
end
end
复制代码
class Event_FF2
attr_reader :message,
:keyword_events,
:item_events,
:event_id
def initialize(list,id)
@event_id = id
@item_events = {}
@keyword_events = {}
@message = ""
setup(list)
end
def setup(list)
_in_message = false
_in_event = false
_index = 0
_eventlist = []
until list[_index += 1].code == 118 do
if list[_index].code == 101
_in_message = true
$game_message.face_name = list[_index].parameters[0]
$game_message.face_index = list[_index].parameters[1]
end
if list[_index].code == 401 and _in_message
@message += list[_index].parameters[0]
end
end
while list[_index] do
if list[_index].code == 118
make_event(_eventlist) unless _eventlist.empty?
_eventlist = []
_in_event = true
end
if _in_event
_eventlist << list[_index]
end
_index += 1
end
make_event(_eventlist) unless _eventlist.empty?
end
def make_event(event_list)
first_line = event_list.shift
kind,name = first_line.parameters[0].split(":")
if kind == "item"
@item_events[name] = (event_list << first_line)
else
@keyword_events[name] = (event_list << first_line)
end
end
end
复制代码
class Window_FFItem < Window_Selectable
#--------------------------------------------------------------------------
# ● 初始化对像
# x : 窗口 X 座标
# y : 窗口 Y 座标
# width : 窗口宽度
# height : 窗口高度
#--------------------------------------------------------------------------
def initialize(x, y, width, height)
super(x, y, width, height)
@ff2_cursor = Sprite_FF2Cursor.new
@column_max = 2
self.index = 0
refresh
end
#--------------------------------------------------------------------------
# ● 获取项目
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
# ● 判断是否为物品
# item : 项目
#--------------------------------------------------------------------------
def include?(item)
return false if item == nil
if $game_temp.in_battle
return false unless item.is_a?(RPG::Item)
end
return true
end
#--------------------------------------------------------------------------
# ● 判断是否为有效状态
# item : 项目
#--------------------------------------------------------------------------
def enable?(item)
true
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
@data = []
for item in $game_party.items
next unless include?(item)
@data.push(item)
if item.is_a?(RPG::Item) and item.id == $game_party.last_item_id
self.index = @data.size - 1
end
end
@data.push(nil) if include?(nil)
@item_max = @data.size
create_contents
for i in 0...@item_max
draw_item(i)
end
end
#--------------------------------------------------------------------------
# ● 描绘项目
# index : 项目编号
#--------------------------------------------------------------------------
def draw_item(index)
rect = item_rect(index)
self.contents.clear_rect(rect)
item = @data[index]
if item != nil
number = $game_party.item_number(item)
enabled = enable?(item)
rect.width -= 4
draw_item_name(item, rect.x, rect.y, enabled)
self.contents.draw_text(rect, sprintf(":%2d", number), 2)
end
end
#--------------------------------------------------------------------------
# ● 更新帮助窗口文字
#--------------------------------------------------------------------------
def update_help
end
alias :odd_update :update
def update
@ff2_cursor.update
odd_update
end
def update_cursor
if @index < 0 # 当光标位置小于0
@ff2_cursor.visible = false # 隐藏光标
else # 当光标位置为0或大于
row = @index / @column_max # 获取当前行
if row < top_row # 若先于首行
self.top_row = row # 向上滚动
end
if row > bottom_row # 若後于末行
self.bottom_row = row # 向下滚动
end
rect = item_rect(@index) # 获取所选项目矩形
rect.y -= self.oy # 设矩形为滚动位置
@ff2_cursor.x = rect.x + self.x
@ff2_cursor.y = rect.y + self.y + 16
end
end
alias :odd_visible= :visible=
def visible=(boolean)
self.odd_visible = boolean
@ff2_cursor.visible = boolean
end
alias :odd_dispose :dispose
def dispose
odd_dispose
@ff2_cursor.dispose
end
end
复制代码
class Window_KeyWords < Window_Selectable
#--------------------------------------------------------------------------
# ● 初始化对像
# x : 窗口 X 座标
# y : 窗口 Y 座标
# width : 窗口宽度
# height : 窗口高度
#--------------------------------------------------------------------------
def initialize(x, y, width, height)
super(x, y, width, height)
@ff2_cursor = Sprite_FF2Cursor.new
@column_max = 2
self.index = 0
refresh
end
#--------------------------------------------------------------------------
# ● 获取项目
#--------------------------------------------------------------------------
def item
return @data[self.index]
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
@data = []
for item in $game_player.keywords
@data.push(item)
end
@item_max = @data.size
create_contents
contents.font.color = crisis_color
for i in 0...@item_max
draw_item(i)
end
end
#--------------------------------------------------------------------------
# ● 描绘项目
# index : 项目编号
#--------------------------------------------------------------------------
def draw_item(index)
rect = item_rect(index)
self.contents.clear_rect(rect)
item = @data[index]
if item != nil
item = " " + item
rect.width -= 4
self.contents.draw_text(rect.x,rect.y,rect.width,rect.height,item)
end
end
#--------------------------------------------------------------------------
# ● 更新帮助窗口文字
#--------------------------------------------------------------------------
def update_help
end
alias :odd_update :update
def update
@ff2_cursor.update
odd_update
end
def update_cursor
if @index < 0 # 当光标位置小于0
@ff2_cursor.visible = false # 隐藏光标
else # 当光标位置为0或大于
row = @index / @column_max # 获取当前行
if row < top_row # 若先于首行
self.top_row = row # 向上滚动
end
if row > bottom_row # 若後于末行
self.bottom_row = row # 向下滚动
end
rect = item_rect(@index) # 获取所选项目矩形
rect.y -= self.oy # 设矩形为滚动位置
@ff2_cursor.x = rect.x + self.x
@ff2_cursor.y = rect.y + self.y + 16
end
end
alias :odd_visible= :visible=
def visible=(boolean)
self.odd_visible = boolean
@ff2_cursor.visible = boolean
end
alias :odd_dispose :dispose
def dispose
odd_dispose
@ff2_cursor.dispose
end
end
复制代码
原作者就是将脚本分成一份一份的如果有什么不便抱歉
谢谢了..
@protosssonny
是这样的,该脚本的使用方法是在普通的事件的第一行加入 注释:“系统”。 这样普通的NPC就能进行关键词操作
我希望能有一个物品,使用触发公共事件,该公共事件也能有关键词操作。
但是这个脚本不能用在公共事件..
作者:
结城照美
时间:
2013-4-27 18:02
{:2_254:}...自顶,为什么这个问题没人理
作者:
结城照美
时间:
2013-4-29 22:43
发表于6天前{:2_270:}
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1