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

Project1

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

[已经过期] 求改良关键词系统的脚本使其能在公共事件使用..

[复制链接]

Lv2.观梦者

梦石
0
星屑
478
在线时间
750 小时
注册时间
2012-11-10
帖子
924
跳转到指定楼层
1
发表于 2013-4-23 18:36:06 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 结城照美 于 2013-4-23 22:55 编辑

添加的脚本如下(出处)
010609w6p31rra1iiydi6p.rar (245.32 KB, 下载次数: 62)
  1. class Sprite_FF2Cursor < Sprite_Base
  2.   def initialize(*args)
  3.     super(*args)
  4.     self.bitmap = Cache.system("Hand_cursor")
  5.     @frame = 0
  6.     self.src_rect.set(@frame / 2 * 24,0,24,24)
  7.     self.z = 205
  8.     self.visible = false
  9.   end
  10.   
  11.   def update
  12.     super
  13.     self.src_rect.set(@frame / 2 * 24,0,24,24)
  14.     @frame += 1
  15.     @frame %= 8
  16.   end
  17. end
复制代码
追加关键词库↓
  1. class Game_Player
  2.   attr_reader :keywords
  3.   alias :odd_key_ini :initialize
  4.   def initialize(*args)
  5.     odd_key_ini(*args)
  6.     @keywords = []
  7.   end
  8. end
复制代码
  1. class Game_Event
  2.   WordFF2 = "系统"
  3.   alias :ff2_start :start
  4.   def start
  5.     if list[0].code == 108 and list[0].parameters[0].index(WordFF2)
  6.       ff2_keyword_system
  7.       return
  8.     end
  9.     ff2_start
  10.   end
  11.   
  12.   def ff2_keyword_system
  13.     $scene = Scene_FF2Key.new(list,@event.id)
  14.   end
  15.   
  16. end
复制代码
  1. class Scene_FF2Key < Scene_Base
  2.   def initialize(list,id)
  3.     super()
  4.     @ff2_event = Event_FF2.new(list,id)
  5.     @ff2_cursor = Sprite_FF2Cursor.new
  6.     @ff2_cursor.visible = false
  7.   end
  8.   
  9.   def start
  10.     @showing = true
  11.     @message_window = Window_Base.new(0,0,544,128)
  12.     @message_window.z = 200
  13.     if $game_message.face_name.empty?
  14.       @contents_x = 0
  15.     else
  16.       _name = $game_message.face_name
  17.       _index = $game_message.face_index
  18.       @message_window.draw_face(_name, _index, 0, 0)
  19.       @contents_x = 112
  20.     end
  21.     @contents_y = 0
  22.     @action_window = Window_Command.new(144,["  问","  记","  道具"])
  23.     @action_window.y = 312
  24.     @action_window.z = 200
  25.     @items_window = Window_FFItem.new(144,312,400,104)
  26.     @items_window.z = 202
  27.     @items_window.active = false
  28.     @items_window.visible = false
  29.     @keywords_window = Window_KeyWords.new(144,312,400,104)
  30.     @keywords_window.z = 200
  31.     @keywords_window.active = false
  32.     @keywords_window.visible = false
  33.     @spriteset = Spriteset_Map.new
  34.     #create_cursor
  35.   end
  36.   
  37.   def post_start
  38.     show_message
  39.   end
  40.   
  41.   def terminate
  42.     @message_window.dispose
  43.     @action_window.dispose
  44.     @items_window.dispose
  45.     @keywords_window.dispose
  46.     @spriteset.dispose
  47.   end
  48.   
  49.   def update
  50.     if @action_window.active
  51.       update_action
  52.       return
  53.     elsif @items_window.active
  54.       update_item
  55.       return
  56.     elsif @keywords_window.active
  57.       update_keyword
  58.       return
  59.     else
  60.       update_message
  61.       return
  62.     end
  63.   end
  64.   
  65.   def update_action
  66.     @action_window.update
  67.     if Input.trigger?(Input::B)
  68.       Sound.play_cancel
  69.       $scene = Scene_Map.new
  70.       return
  71.     end
  72.     if Input.trigger?(Input::C)
  73.       Sound.play_decision
  74.       @action_window.active =false
  75.       case @action_window.index
  76.       when 0
  77.         @keywords_window.active = true
  78.         @keywords_window.visible = true
  79.         return
  80.       when 1
  81.         @newkey_index = 0
  82.         if @keywords.empty?
  83.           @action_window.active = true
  84.         else
  85.           @ff2_cursor.visible = true
  86.           update_message_cursor
  87.         end
  88.         return
  89.       when 2
  90.         @items_window.active = true
  91.         @items_window.visible = true
  92.         @keywords_window.visible = false
  93.         return
  94.       end
  95.     end
  96.   end
  97.   
  98.   def update_item
  99.     @items_window.update
  100.     if Input.trigger?(Input::B)
  101.       Sound.play_cancel
  102.       @items_window.index = 0
  103.       @items_window.visible = false
  104.       @items_window.active = false
  105.       @action_window.active = true
  106.       return
  107.     end
  108.     if Input.trigger?(Input::C)
  109.       Sound.play_decision
  110.       use_item
  111.       return
  112.     end
  113.   end
  114.   
  115.   def update_keyword
  116.     @keywords_window.update
  117.     if Input.trigger?(Input::B)
  118.       Sound.play_decision
  119.       @keywords_window.index = 0 if $game_player.keywords.size > 0
  120.       @keywords_window.active = false
  121.       @keywords_window.visible = false
  122.       @action_window.active = true
  123.       return
  124.     end
  125.     if Input.trigger?(Input::C)
  126.       Sound.play_decision
  127.       use_keyword
  128.       return
  129.     end
  130.   end
  131.   
  132.   def update_message
  133.     @message_window.update
  134.     @ff2_cursor.update
  135.     if Input.trigger?(Input::LEFT)
  136.       Sound.play_cursor
  137.       @newkey_index -= 1
  138.       @newkey_index %= @keywords.size
  139.       update_message_cursor
  140.       return
  141.     end
  142.     if Input.trigger?(Input::RIGHT)
  143.       Sound.play_cursor
  144.       @newkey_index += 1
  145.       @newkey_index %= @keywords.size
  146.       update_message_cursor
  147.       return
  148.     end
  149.     if Input.trigger?(Input::B)
  150.       Sound.play_cancel
  151.       @action_window.active = true
  152.       @ff2_cursor.visible = false
  153.       return
  154.     end
  155.     if Input.trigger?(Input::C)
  156.       Sound.play_decision
  157.       remember_keyword
  158.       @action_window.active = true
  159.       @keywords_window.visible = true
  160.       @ff2_cursor.visible = false
  161.       @keywords_window.refresh
  162.       return
  163.     end
  164.   end
  165.   
  166.   def use_item
  167.     return if item.nil?
  168.     if list = @ff2_event.item_events[item]
  169.       $scene = Scene_Map.new
  170.       $game_map.interpreter.setup(list,event_id)
  171.       return
  172.     end
  173.   end
  174.   
  175.   def use_keyword
  176.     if list = @ff2_event.keyword_events[key_word]
  177.       $scene = Scene_Map.new
  178.       $game_map.interpreter.setup(list,event_id)
  179.       return
  180.     else
  181.       @keywords_window.active = false
  182.       @keywords_window.visible = false
  183.       @action_window.active = true
  184.     end
  185.   end
  186.   
  187.   def remember_keyword
  188.     Sound.play_decision
  189.     ($game_player.keywords << @keywords[@newkey_index]).uniq!
  190.     $game_player.keywords.sort!
  191.   end
  192.   
  193.   def show_message
  194.     message = @ff2_event.message
  195.     @keywords = []
  196.     @positions = []
  197.     _key_word = ""
  198.     _in_keyword = false
  199.     loop do
  200.       c = message.slice!(/./m)            # 获取一个文字
  201.       case c
  202.       when nil                          # 无法获取文字时
  203.         break
  204.       when "\x00"                       # 新行
  205.         new_line
  206.       else                              # 一般文字
  207.         if c == "【"
  208.           @message_window.contents.font.color = @message_window.crisis_color
  209.           _in_keyword = true
  210.           @word_position = [@contents_x + 12,@contents_y]
  211.           draw_char(c)
  212.         elsif c == "】"
  213.           draw_char(c)
  214.           @message_window.contents.font.color = @message_window.normal_color
  215.           _in_keyword = false
  216.           @keywords << _key_word
  217.           _key_word = ""
  218.           @positions << @word_position
  219.         else
  220.           _key_word += c if _in_keyword
  221.           draw_char(c)
  222.         end
  223.       end
  224.       Graphics.update
  225.       @message_window.update
  226.     end
  227.   end
  228.   
  229.   def draw_char(c)
  230.     @message_window.contents.draw_text(@contents_x, @contents_y, 40, 24, c)
  231.     c_width = @message_window.contents.text_size(c).width
  232.     @contents_x += c_width
  233.     if @contents_x > 496
  234.       @contents_x = $game_message.face_name.empty? ? 0 : 112
  235.       @contents_y +=  24
  236.     end
  237.   end
  238.   
  239.   def update_message_cursor
  240.     return unless @ff2_cursor.visible
  241.     x,y = @positions[@newkey_index]
  242.     @ff2_cursor.x = x
  243.     @ff2_cursor.y = y + 16
  244.   end
  245.   
  246.   def item
  247.     @items_window.item.name unless @items_window.item.nil?
  248.   end
  249.   
  250.   def key_word
  251.     @keywords_window.item
  252.   end
  253.   
  254.   def event_id
  255.     @ff2_event.event_id
  256.   end
  257.   
  258. end
复制代码
  1. class Event_FF2
  2.   attr_reader :message,
  3.               :keyword_events,
  4.               :item_events,
  5.               :event_id
  6.   
  7.   def initialize(list,id)
  8.     @event_id = id
  9.     @item_events = {}
  10.     @keyword_events = {}
  11.     @message = ""
  12.     setup(list)
  13.   end
  14.   
  15.   def setup(list)
  16.     _in_message = false
  17.     _in_event = false
  18.     _index = 0
  19.     _eventlist = []
  20.     until list[_index += 1].code == 118 do
  21.       if list[_index].code == 101
  22.         _in_message = true
  23.         $game_message.face_name = list[_index].parameters[0]
  24.         $game_message.face_index = list[_index].parameters[1]
  25.       end
  26.       if list[_index].code == 401 and _in_message
  27.         @message += list[_index].parameters[0]
  28.       end
  29.     end
  30.     while list[_index] do
  31.       if list[_index].code == 118
  32.         make_event(_eventlist) unless _eventlist.empty?
  33.         _eventlist = []
  34.         _in_event = true
  35.       end
  36.       if _in_event
  37.         _eventlist << list[_index]
  38.       end
  39.       _index += 1
  40.     end
  41.     make_event(_eventlist) unless _eventlist.empty?
  42.   end
  43.   
  44.   def make_event(event_list)
  45.     first_line = event_list.shift
  46.     kind,name = first_line.parameters[0].split(":")
  47.     if kind == "item"
  48.       @item_events[name] = (event_list << first_line)
  49.     else
  50.       @keyword_events[name] = (event_list << first_line)
  51.     end
  52.   end
  53.   
  54. end
复制代码
  1. class Window_FFItem < Window_Selectable
  2.   #--------------------------------------------------------------------------
  3.   # ● 初始化对像
  4.   #     x      : 窗口 X 座标
  5.   #     y      : 窗口 Y 座标
  6.   #     width  : 窗口宽度
  7.   #     height : 窗口高度
  8.   #--------------------------------------------------------------------------
  9.   def initialize(x, y, width, height)
  10.     super(x, y, width, height)
  11.     @ff2_cursor = Sprite_FF2Cursor.new
  12.     @column_max = 2
  13.     self.index = 0
  14.     refresh
  15.   end
  16.   #--------------------------------------------------------------------------
  17.   # ● 获取项目
  18.   #--------------------------------------------------------------------------
  19.   def item
  20.     return @data[self.index]
  21.   end
  22.   #--------------------------------------------------------------------------
  23.   # ● 判断是否为物品
  24.   #     item : 项目
  25.   #--------------------------------------------------------------------------
  26.   def include?(item)
  27.     return false if item == nil
  28.     if $game_temp.in_battle
  29.       return false unless item.is_a?(RPG::Item)
  30.     end
  31.     return true
  32.   end
  33.   #--------------------------------------------------------------------------
  34.   # ● 判断是否为有效状态
  35.   #     item : 项目
  36.   #--------------------------------------------------------------------------
  37.   def enable?(item)
  38.     true
  39.   end
  40.   #--------------------------------------------------------------------------
  41.   # ● 刷新
  42.   #--------------------------------------------------------------------------
  43.   def refresh
  44.     @data = []
  45.     for item in $game_party.items
  46.       next unless include?(item)
  47.       @data.push(item)
  48.       if item.is_a?(RPG::Item) and item.id == $game_party.last_item_id
  49.         self.index = @data.size - 1
  50.       end
  51.     end
  52.     @data.push(nil) if include?(nil)
  53.     @item_max = @data.size
  54.     create_contents
  55.     for i in 0...@item_max
  56.       draw_item(i)
  57.     end
  58.   end
  59.   #--------------------------------------------------------------------------
  60.   # ● 描绘项目
  61.   #     index : 项目编号
  62.   #--------------------------------------------------------------------------
  63.   def draw_item(index)
  64.     rect = item_rect(index)
  65.     self.contents.clear_rect(rect)
  66.     item = @data[index]
  67.     if item != nil
  68.       number = $game_party.item_number(item)
  69.       enabled = enable?(item)
  70.       rect.width -= 4
  71.       draw_item_name(item, rect.x, rect.y, enabled)
  72.       self.contents.draw_text(rect, sprintf(":%2d", number), 2)
  73.     end
  74.   end
  75.   #--------------------------------------------------------------------------
  76.   # ● 更新帮助窗口文字
  77.   #--------------------------------------------------------------------------
  78.   def update_help
  79.   end
  80.   
  81.   alias :odd_update :update
  82.   def update
  83.     @ff2_cursor.update
  84.     odd_update
  85.   end
  86.   
  87.   def update_cursor
  88.     if @index < 0                   # 当光标位置小于0
  89.       @ff2_cursor.visible = false   # 隐藏光标
  90.     else                            # 当光标位置为0或大于
  91.       row = @index / @column_max    # 获取当前行
  92.       if row < top_row              # 若先于首行
  93.         self.top_row = row          # 向上滚动
  94.       end
  95.       if row > bottom_row           # 若後于末行
  96.         self.bottom_row = row       # 向下滚动
  97.       end
  98.       rect = item_rect(@index)      # 获取所选项目矩形
  99.       rect.y -= self.oy             # 设矩形为滚动位置
  100.       @ff2_cursor.x = rect.x + self.x
  101.       @ff2_cursor.y = rect.y + self.y + 16
  102.     end
  103.   end
  104.   
  105.   alias :odd_visible= :visible=
  106.   def visible=(boolean)
  107.     self.odd_visible = boolean
  108.     @ff2_cursor.visible = boolean
  109.   end
  110.   
  111.   alias :odd_dispose :dispose
  112.   def dispose
  113.     odd_dispose
  114.     @ff2_cursor.dispose
  115.   end
  116.   
  117. end
复制代码
  1. class Window_KeyWords < Window_Selectable
  2.   #--------------------------------------------------------------------------
  3.   # ● 初始化对像
  4.   #     x      : 窗口 X 座标
  5.   #     y      : 窗口 Y 座标
  6.   #     width  : 窗口宽度
  7.   #     height : 窗口高度
  8.   #--------------------------------------------------------------------------
  9.   def initialize(x, y, width, height)
  10.     super(x, y, width, height)
  11.     @ff2_cursor = Sprite_FF2Cursor.new
  12.     @column_max = 2
  13.     self.index = 0
  14.     refresh
  15.   end
  16.   #--------------------------------------------------------------------------
  17.   # ● 获取项目
  18.   #--------------------------------------------------------------------------
  19.   def item
  20.     return @data[self.index]
  21.   end

  22.   #--------------------------------------------------------------------------
  23.   # ● 刷新
  24.   #--------------------------------------------------------------------------
  25.   def refresh
  26.     @data = []
  27.     for item in $game_player.keywords
  28.       @data.push(item)
  29.     end
  30.     @item_max = @data.size
  31.     create_contents
  32.     contents.font.color = crisis_color
  33.     for i in 0...@item_max
  34.       draw_item(i)
  35.     end
  36.   end
  37.   #--------------------------------------------------------------------------
  38.   # ● 描绘项目
  39.   #     index : 项目编号
  40.   #--------------------------------------------------------------------------
  41.   def draw_item(index)
  42.     rect = item_rect(index)
  43.     self.contents.clear_rect(rect)
  44.     item = @data[index]
  45.     if item != nil
  46.       item = " " + item
  47.       rect.width -= 4
  48.       self.contents.draw_text(rect.x,rect.y,rect.width,rect.height,item)
  49.     end
  50.   end
  51.   #--------------------------------------------------------------------------
  52.   # ● 更新帮助窗口文字
  53.   #--------------------------------------------------------------------------
  54.   def update_help
  55.   end
  56.   
  57.   alias :odd_update :update
  58.   def update
  59.     @ff2_cursor.update
  60.     odd_update
  61.   end
  62.   
  63.   def update_cursor
  64.     if @index < 0                   # 当光标位置小于0
  65.       @ff2_cursor.visible = false   # 隐藏光标
  66.     else                            # 当光标位置为0或大于
  67.       row = @index / @column_max    # 获取当前行
  68.       if row < top_row              # 若先于首行
  69.         self.top_row = row          # 向上滚动
  70.       end
  71.       if row > bottom_row           # 若後于末行
  72.         self.bottom_row = row       # 向下滚动
  73.       end
  74.       rect = item_rect(@index)      # 获取所选项目矩形
  75.       rect.y -= self.oy             # 设矩形为滚动位置
  76.       @ff2_cursor.x = rect.x + self.x
  77.       @ff2_cursor.y = rect.y + self.y + 16
  78.     end
  79.   end
  80.   
  81.   alias :odd_visible= :visible=
  82.   def visible=(boolean)
  83.     self.odd_visible = boolean
  84.     @ff2_cursor.visible = boolean
  85.   end
  86.   
  87.   alias :odd_dispose :dispose
  88.   def dispose
  89.     odd_dispose
  90.     @ff2_cursor.dispose
  91.   end
  92. end
复制代码
原作者就是将脚本分成一份一份的如果有什么不便抱歉
谢谢了..

@protosssonny
是这样的,该脚本的使用方法是在普通的事件的第一行加入 注释:“系统”。 这样普通的NPC就能进行关键词操作
我希望能有一个物品,使用触发公共事件,该公共事件也能有关键词操作。
但是这个脚本不能用在公共事件..

点评

不明白你的问题。  发表于 2013-4-23 21:29
有本事就来阻止我啊,主体单元『天照』!

Lv2.观梦者

梦石
0
星屑
478
在线时间
750 小时
注册时间
2012-11-10
帖子
924
2
 楼主| 发表于 2013-4-27 18:02:25 | 只看该作者
{:2_254:}...自顶,为什么这个问题没人理
有本事就来阻止我啊,主体单元『天照』!
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
478
在线时间
750 小时
注册时间
2012-11-10
帖子
924
3
 楼主| 发表于 2013-4-29 22:43:07 | 只看该作者
发表于6天前{:2_270:}
有本事就来阻止我啊,主体单元『天照』!
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-25 12:17

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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