查看: 2414|回复: 4

[已经过期] 关于几个事件里指令的脚本写法,求解

[复制链接]
梦石
0
星屑
60
在线时间
45 小时
注册时间
2006-8-23
回帖
256
发表于 2016-8-29 09:20:17 | 显示全部楼层 |阅读模式

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

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

×
1.显示选择项

2.场所移动

3.标签与标签跳转
在脚本编辑器里编写脚本,这个类似标签跳转的功能怎么写?

4.更改事件的行走图形
更改角色行走图形倒是知道,但是要更改事件的行走图则要在设置移动路线里改,直接用脚本怎么写?

其他的事件指令我基本上能找到,就差这几个了,往大神解答
梦石
0
星屑
125
在线时间
171 小时
注册时间
2014-4-14
回帖
135
发表于 2016-8-29 11:06:55 | 显示全部楼层
最麻烦的就是显示选择项,建议用这个脚本。可以随时调用的是或否选择窗口

教程作者:洛克人SZ
首发网址:点此进入本教学的原始帖
适宜用户:喜欢用的都可以用吧^^
技术通用度:★★★★★
技术应用复杂度:20 (满分150分)
学习的理解难度:35 (满分150分)



--------------------------------------------------------------------------------

作者的话:

在需要向玩家询问 是/否 的时候可以用到的东西。
要显示选项窗口在地图画面或战斗画面中可以用显示对话的选项功能实现,在其他画面中就需要建立一个命令窗口,还要写相关的代码,比较麻烦。这个脚本在只需询问 是/否 两个选项的情况下只用一个简单的判断语句就可以完成,应该比较方便吧。

如果已经有类似的东西就请无视吧……

v 1.3: 在 enghao_lim 大人的提醒下继续精简代码
v 1.2: 除掉了一个BUG
v 1.1: 精简代码

教学正文:


  1. #================================================================
  2. #   可以随时调用的 是/否 选择窗口      by 洛克人SZ
  3. #   用法:                               v 1.3
  4. #     if yes_no("提示信息")
  5. #       选择 是 的情况下
  6. #     else
  7. #       选择 否 的情况下
  8. #     end
  9. #
  10. #   也可以用在事件中的条件分歧里。
  11. #================================================================


  12. def yes_no(info = "请选择:")
  13.   dummy_bitmap = Bitmap.new(608, 32)
  14.   dummy_bitmap.font.size = 22
  15.   strwidth = dummy_bitmap.text_size(info).width
  16.   dummy_bitmap.dispose
  17.   dummy_bitmap = nil
  18.   strwidth = 88 if strwidth < 88
  19.   strwidth = strwidth / 2 + strwidth + 32
  20.   strwidth = 640 if strwidth > 640
  21.   yes_no_window = Window_YesNoCommand.new(info, strwidth)
  22.   yes_no_window.visible = true
  23.   yes_no_window.active = true
  24.   loop do
  25.     Graphics.update
  26.     Input.update
  27.     yes_no_window.update
  28.     if yes_no_window.active != true
  29.       break
  30.     end
  31.   end
  32.   fhxx = yes_no_window.fhxx
  33.   yes_no_window.dispose
  34.   yes_no_window = nil
  35.   return fhxx
  36. end


  37. #==============================================================================
  38. # ■ Window_HorizSelectable
  39. #------------------------------------------------------------------------------
  40. #  拥有光标的移动以及滚动功能的窗口类。 (水平命令窗口专用)
  41. #==============================================================================

  42. class Window_HorizSelectable < Window_Base
  43.   #--------------------------------------------------------------------------
  44.   # ● 定义实例变量
  45.   #--------------------------------------------------------------------------
  46.   attr_reader   :index                    # 光标位置
  47.   attr_reader   :help_window              # 帮助窗口
  48.   attr_reader   :help_windowa             # 帮助窗口a
  49.   #--------------------------------------------------------------------------
  50.   # ● 初始化对像
  51.   #     x      : 窗口的 X 坐标
  52.   #     y      : 窗口的 Y 坐标
  53.   #     width  : 窗口的宽
  54.   #     height : 窗口的高
  55.   #--------------------------------------------------------------------------
  56.   def initialize(x, y, width, height)
  57.     super(x, y, width, height)
  58.     @index = -1
  59.   end
  60.   #--------------------------------------------------------------------------
  61.   # ● 设置光标的位置
  62.   #     index : 新的光标位置
  63.   #--------------------------------------------------------------------------
  64.   def index=(index)
  65.     @index = index
  66.     # 刷新帮助文本 (update_help 定义了继承目标)
  67.     if self.active and @help_window != nil
  68.       update_help
  69.     end
  70.     if self.active and @help_windowa != nil
  71.       update_helpa
  72.     end
  73.     # 刷新光标矩形
  74.     update_cursor_rect
  75.   end
  76.   #--------------------------------------------------------------------------
  77.   # ● 帮助窗口的设置
  78.   #     help_window : 新的帮助窗口
  79.   #--------------------------------------------------------------------------
  80.   def help_window=(help_window)
  81.     @help_window = help_window
  82.     # 刷新帮助文本 (update_help 定义了继承目标)
  83.     if self.active and @help_window != nil
  84.       update_help
  85.     end
  86.   end

  87.   def help_windowa=(help_windowa)
  88.     @help_windowa = help_windowa
  89.     # 刷新帮助文本 (update_help 定义了继承目标)
  90.     if self.active and @help_windowa != nil
  91.       update_helpa
  92.     end
  93.   end
  94.   #--------------------------------------------------------------------------
  95.   # ● 更新光标矩形
  96.   #--------------------------------------------------------------------------
  97.   def update_cursor_rect
  98.     # 光标位置不满 0 的情况下
  99.     if @index < 0
  100.       self.cursor_rect.empty
  101.       return
  102.     end
  103.     # 计算光标的宽度
  104.     cursor_width = self.width / @item_max - 32
  105.     # 计算光标坐标
  106.     x = @index % @item_max * (cursor_width + 32)
  107.     y = @index / @item_max * 32 - self.oy
  108.     # 更新光标矩形
  109.     self.cursor_rect.set(x, y, cursor_width, 32)
  110.   end
  111.   #--------------------------------------------------------------------------
  112.   # ● 刷新画面
  113.   #--------------------------------------------------------------------------
  114.   def update
  115.     super
  116.     # 可以移动光标的情况下
  117.     if self.active and @item_max > 0 and @index >= 0
  118.       # 方向键右被按下的情况下
  119.       if Input.repeat?(Input::RIGHT)
  120.         # 列数为 2 以上并且、光标位置在最后一个项目上的情况下
  121.         if @item_max >= 2 and @index == @item_max - 1 and
  122.           Input.trigger?(Input::RIGHT)
  123.           # 光标返回第一个项目
  124.           $game_system.se_play($data_system.cursor_se)
  125.           @index = 0
  126.         # 列数为 2 以上并且、光标位置在(项目数 - 1)之前的情况下
  127.         elsif @item_max >= 2 and @index < @item_max - 1
  128.           # 光标向右移动
  129.           $game_system.se_play($data_system.cursor_se)
  130.           @index += 1
  131.         end
  132.       end
  133.       # 方向键左被按下的情况下
  134.       if Input.repeat?(Input::LEFT)
  135.         # 列数为 2 以上并且、光标位置在 0 的情况下
  136.         if @item_max >= 2 and @index == 0 and
  137.           Input.trigger?(Input::LEFT)
  138.           # 光标移动到最后一个项目
  139.           $game_system.se_play($data_system.cursor_se)
  140.           @index = @item_max - 1
  141.         # 列数为 2 以上并且、光标位置在 0 之后的情况下
  142.         elsif @item_max >= 2 and @index > 0
  143.           # 光标向左移动
  144.           $game_system.se_play($data_system.cursor_se)
  145.           @index -= 1
  146.         end
  147.       end
  148.     end
  149.     # 刷新帮助文本 (update_help 定义了继承目标)
  150.     if self.active and @help_window != nil
  151.       update_help
  152.     end
  153.     # 刷新帮助文本 (update_help 定义了继承目标)
  154.     if self.active and @help_windowa != nil
  155.       update_helpa
  156.     end
  157.     # 刷新光标矩形
  158.     update_cursor_rect
  159.   end
  160. end



  161. #==============================================================================
  162. # ■ Window_YesNoCommand
  163. #------------------------------------------------------------------------------
  164. #  选择是或否的命令选择行窗口。
  165. #==============================================================================

  166. class Window_YesNoCommand < Window_HorizSelectable
  167.   #--------------------------------------------------------------------------
  168.   # ● 定义实例变量
  169.   #--------------------------------------------------------------------------
  170.   attr_reader   :fhxx
  171.   #--------------------------------------------------------------------------
  172.   # ● 初始化对像
  173.   #     info     : 窗口的提示信息
  174.   #     width    : 窗口的宽度
  175.   #     height   : 窗口的高度
  176.   #--------------------------------------------------------------------------
  177.   def initialize(info = "欢迎", width = 480, height = 96)
  178.     x = 320 - width / 2
  179.     y = 240 - height / 2
  180.     super(x, y, width, height)
  181.     self.visible = false
  182.     self.active = false
  183.     self.opacity = 200
  184.     self.contents = Bitmap.new(width - 32, height - 32)
  185.     @commands = ["是", "否"]
  186.     @item_max = @commands.size
  187.     @woff = (self.width - 32) / 4 - 19
  188.     @fhxx = false
  189.     refresh(info)
  190.     self.index = 0
  191.     self.z = 10000
  192.   end
  193.   #--------------------------------------------------------------------------
  194.   # ● 刷新
  195.   #--------------------------------------------------------------------------
  196.   def refresh(info)
  197.     self.contents.clear
  198.     self.contents.font.size = 22
  199.     self.contents.font.color = system_color
  200.     self.contents.draw_text(0, 0, self.width - 32, 32, info, 1)
  201.     for i in 0...@item_max
  202.       draw_item(i, normal_color)
  203.     end
  204.   end
  205.   #--------------------------------------------------------------------------
  206.   # ● 描绘项目
  207.   #     index : 项目编号
  208.   #--------------------------------------------------------------------------
  209.   def draw_item(index, color)
  210.     self.contents.font.color = color
  211.     x = self.width / @item_max * index + @woff
  212.     off = self.width / @item_max - 32
  213.     self.contents.draw_text(x, 32, 32, 32, @commands[index])
  214.   end
  215.   #--------------------------------------------------------------------------
  216.   # ● 项目无效化
  217.   #     index : 项目编号
  218.   #--------------------------------------------------------------------------
  219.   def disable_item(index)
  220.     draw_item(index, disabled_color)
  221.   end
  222.   #--------------------------------------------------------------------------
  223.   # ● 更新光标矩形
  224.   #--------------------------------------------------------------------------
  225.   def update_cursor_rect
  226.     # 光标位置不满 0 的情况下
  227.     if @index < 0
  228.       self.cursor_rect.empty
  229.       return
  230.     end
  231.     # 计算光标的宽度
  232.     cursor_width = self.width / @item_max - 32
  233.     # 计算光标坐标
  234.     x = @index % @item_max * (cursor_width + 32)
  235.     y = 32
  236.     # 更新光标矩形
  237.     self.cursor_rect.set(x, y, cursor_width, 32)
  238.   end
  239.   #--------------------------------------------------------------------------
  240.   # ● 刷新画面
  241.   #--------------------------------------------------------------------------
  242.   def update
  243.     super
  244.     # 按下取消键的情况下
  245.     if Input.trigger?(Input::B)
  246.       # 演奏确定 SE
  247.       $game_system.se_play($data_system.decision_se)
  248.       @fhxx = false
  249.       self.visible = false
  250.       self.active = false
  251.       return
  252.     end
  253.     # 按下确定键的情况下
  254.     if Input.trigger?(Input::C)
  255.       # 演奏确定 SE
  256.       $game_system.se_play($data_system.decision_se)
  257.       # 命令窗口的光标位置分支
  258.       case self.index
  259.       when 0  # 是
  260.         @fhxx = true
  261.         self.visible = false
  262.         self.active = false
  263.       when 1  # 否
  264.         @fhxx = false
  265.         self.visible = false
  266.         self.active = false
  267.       end
  268.       return
  269.     end
  270.   end
  271. end
复制代码

编辑的话:

嗯,可以算新手脚本的范畴吧。
代码虽有些许的赘余,但是功能非常赞呢。
内容全部为自定义的,基本上没有冲突的可能。

评分

参与人数 1星屑 +66 收起 理由
hys111111 + 66 塞糖

查看全部评分

Vanyogin
回复

使用道具 举报

梦石
0
星屑
76
在线时间
1379 小时
注册时间
2012-7-5
回帖
1643

开拓者

发表于 2016-8-30 08:50:59 | 显示全部楼层
自己抄 Interpreter
1. command_102
2. command_201
3. command_118 _119
4. command_209 -> RPG::MoveRoute(F1 RGSS参考)

  -fk: -azogi:
回复

使用道具 举报

梦石
0
星屑
60
在线时间
45 小时
注册时间
2006-8-23
回帖
256
 楼主| 发表于 2016-9-1 21:50:53 | 显示全部楼层
kuerlulu 发表于 2016-8-30 08:50
自己抄 Interpreter
1. command_102
2. command_201

能不能具体点
回复

使用道具 举报

梦石
0
星屑
60
在线时间
45 小时
注册时间
2006-8-23
回帖
256
 楼主| 发表于 2016-9-1 23:43:37 | 显示全部楼层
2357691704 发表于 2016-8-29 11:06
最麻烦的就是显示选择项,建议用这个脚本。可以随时调用的是或否选择窗口

教程作者:洛克人SZ

感谢你的回答,不过对我来说还是有点难懂,
而且我需要的不仅仅是两种选项
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部