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

Project1

 找回密码
 注册会员
搜索
查看: 1379|回复: 6

[已经解决] 关于某选项功能扩展脚本的使用【已解决】

[复制链接]

Lv3.寻梦者

梦石
0
星屑
2323
在线时间
274 小时
注册时间
2017-7-25
帖子
163
发表于 2018-9-21 19:08:37 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 骷髅岛遗老 于 2018-9-22 17:13 编辑
  1. =begin

  2. ▼ 選択肢拡張 ver. 3.2

  3. RPGツクールVXAce用スクリプト

  4. 制作 : 木星ペンギン
  5. URL  : [url]http://woodpenguin.blog.fc2.com/[/url]

  6. 选择支里填写 if($game_party.members[0].level > 10)  
  7. 就是这个选项需要 队伍第一位角色的等级大于10 才会显示出来(并且才可以选择)
  8. 而填写 en(v[1] > 5 && s[1])
  9. 就是当 1号变量大于5且一号开关开启 时,才可以选择,否则是半透明不可选(如果选择会有警告音,且无效)




  10. ------------------------------------------------------------------------------
  11. 概要

  12. □ 選択肢を連続して設定した場合、つなげて一つの選択肢にする機能の追加。
  13. □ 条件を設定することで、その項目を表示しない機能の追加。
  14. □ 選択肢のカーソル初期位置を指定する機能と
  15.     現在のカーソル位置を変数に入れる機能の追加。

  16. □ 選択肢ウィンドウの位置を一時的に変更する機能の追加。
  17. □ 条件を設定することで、その項目を半透明にして選択不可にする機能の追加。
  18. □ 選択肢毎にヘルプメッセージを表示できる機能の追加。

  19. ------------------------------------------------------------------------------
  20. 使い方

  21. □ 選択肢の表示を続けて配置すると、一つの選択肢にまとめられます。
  22.   ・「キャンセルの場合」の処理は、無効以外を設定したものが適用され、
  23.      複数ある場合は後の選択肢のものが適用されます。
  24.   
  25. □ 選択肢の文章中に if(条件) と入れ、その条件が偽になると項目が表示されなくなります。
  26.   ・条件は eval によって評価されます。(詳細は【組み込み関数】を参照)
  27.   ・s でスイッチ、v で変数を参照できます。
  28.   ・「キャンセルの場合」の項目が表示されない場合、無効と同じ処理をします。

  29. □ 注釈に以下の文字列を入れることで、指定された変数の値が
  30.     カーソルの初期位置になります。
  31.   
  32.     カーソル記憶(n)
  33.    
  34.       n : カーソル初期位置の入った変数番号
  35.   
  36.   ・選択肢のカーソルの位置が変更されるたびに、
  37.     この変数に選択肢の番号が入れられるようになります。
  38.   
  39. □ 注釈に以下の文字列を入れることで、選択肢ウィンドウの表示位置を
  40.    一時的に変更することが出来ます。
  41.   
  42.     選択肢位置(x, y[, row])
  43.    
  44.       x   : ウィンドウを表示する X 座標。
  45.       y   : ウィンドウを表示する Y 座標。
  46.       row : 選択肢を表示する最大行数。
  47.             指定しない場合は、通常の最大行数を無視して
  48.             すべての選択肢が表示されます。
  49.   
  50. □ 注釈に以下の文字列を入れることで、選択肢ウィンドウの背景が非表示になります。
  51.   
  52.     背景OFF
  53.    
  54. □ 選択肢の文章中に en(条件) と入れ、その条件が偽になると項目が半透明で表示されます。
  55.   ・条件は eval によって評価されます。(詳細は【組み込み関数】を参照)
  56.   ・s でスイッチ、v で変数を参照できます。
  57.   ・「キャンセルの場合」の項目が半透明の場合、ブザーが鳴ります。
  58.   
  59. □ 各項目の下に、注釈で以下の文字列を入れると、続きの注釈を
  60.     項目のヘルプメッセージとしてカーソルを合わせたときに標示することができます。
  61.   
  62.     選択肢ヘルプ
  63.    
  64. □ 詳細は下記のサイトを参照してください。

  65.   [url]http://woodpenguin.web.fc2.com/rgss3/choice_ex.html[/url]
  66.   
  67. =end
  68. module WdTk
  69. module ChoiceEX
  70. #//////////////////////////////////////////////////////////////////////////////
  71. #
  72. # 設定項目
  73. #
  74. #//////////////////////////////////////////////////////////////////////////////
  75.   #--------------------------------------------------------------------------
  76.   # ● 選択肢の最大行数
  77.   #     選択肢を表示するウィンドウの行数の最大数です。
  78.   #     選択肢がこの数より小さければ、選択肢の数に合わせます。
  79.   #--------------------------------------------------------------------------
  80.   RowMax = 10

  81.   #--------------------------------------------------------------------------
  82.   # ● 選択肢ヘルプを読み取る文字列
  83.   #--------------------------------------------------------------------------
  84.   Help = "選択肢ヘルプ"

  85. end

  86. #//////////////////////////////////////////////////////////////////////////////
  87. #
  88. # 以降、変更する必要なし
  89. #
  90. #//////////////////////////////////////////////////////////////////////////////

  91.   @material ||= []
  92.   @material << :ChoiceEX
  93.   def self.include?(sym)
  94.     @material.include?(sym)
  95.   end

  96. end

  97. #==============================================================================
  98. # ■ Game_Message
  99. #==============================================================================
  100. class Game_Message
  101.   #--------------------------------------------------------------------------
  102.   # ● 公開インスタンス変数
  103.   #--------------------------------------------------------------------------
  104.   attr_accessor :choice_x                 # 選択肢ウィンドウの表示 X 座標
  105.   attr_accessor :choice_y                 # 選択肢ウィンドウの表示 Y 座標
  106.   attr_accessor :choice_row_max           # 選択肢ウィンドウの表示行数
  107.   attr_accessor :choice_help              # 選択肢のヘルプ
  108.   attr_accessor :choice_var_id            # 選択肢のカーソル位置を入れる変数ID
  109.   attr_accessor :choice_background        # 選択肢ウィンドウ背景の表示状態
  110.   #--------------------------------------------------------------------------
  111.   # ○ クリア
  112.   #--------------------------------------------------------------------------
  113.   alias _wdtk_choice_clear clear
  114.   def clear
  115.     _wdtk_choice_clear
  116.     @choice_x = @choice_y = nil
  117.     @choice_row_max = WdTk::ChoiceEX::RowMax
  118.     @choice_help = {}
  119.     @choice_var_id = 0
  120.     @choice_background = 0
  121.   end
  122. end

  123. #==============================================================================
  124. # ■ Game_Interpreter
  125. #==============================================================================
  126. class Game_Interpreter
  127.   #--------------------------------------------------------------------------
  128.   # ☆ 選択肢のセットアップ
  129.   #--------------------------------------------------------------------------
  130.   def setup_choices(params)
  131.     add_choices(params, @index)
  132.     $game_message.choice_proc = Proc.new {|n| @branch[@indent] = n }
  133.   end
  134.   #--------------------------------------------------------------------------
  135.   # ● 選択肢の追加
  136.   #--------------------------------------------------------------------------
  137.   def add_choices(params, i, d = 0)
  138.     params[0].each_with_index {|s, n| $game_message.choices[n + d] = s }
  139.     $game_message.choice_cancel_type = params[1] + d if params[1] > 0
  140.     indent = @list[i].indent
  141.     loop do
  142.       i += 1
  143.       if @list[i].indent == indent
  144.         case @list[i].code
  145.         when 402 # [**] の場合
  146.           get_help_texts(@list[i].parameters[0] + d, i + 1)
  147.         when 404 # 分岐終了
  148.           break
  149.         end
  150.       end
  151.     end
  152.     i += 1
  153.     add_choices(@list[i].parameters, i, d + 5) if @list[i].code == 102
  154.   end
  155.   #--------------------------------------------------------------------------
  156.   # ● ヘルプ用テキストの取得
  157.   #--------------------------------------------------------------------------
  158.   def get_help_texts(b, i)
  159.     if @list[i].code == 108 && @list[i].parameters[0] == WdTk::ChoiceEX::Help
  160.       $game_message.choice_help[b] = []
  161.       while @list[i + 1].code == 408
  162.         i += 1
  163.         $game_message.choice_help[b] << @list[i].parameters[0]
  164.       end
  165.     end
  166.   end
  167.   #--------------------------------------------------------------------------
  168.   # ◯ 注釈
  169.   #--------------------------------------------------------------------------
  170.   alias _wdtk_choice_command_108 command_108
  171.   def command_108
  172.     _wdtk_choice_command_108
  173.     @comments.each do |comment|
  174.       case comment
  175.       when /選択肢位置\((\d+),\s*(\d+),?\s*(\d*)\)/
  176.         $game_message.choice_x = $1.to_i
  177.         $game_message.choice_y = $2.to_i
  178.         $game_message.choice_row_max = ($3.empty? ? 99 : $3.to_i)
  179.       when /カーソル記憶\((\d+)\)/
  180.         $game_message.choice_var_id = $1.to_i
  181.       when /背景(ON|OFF)/
  182.         $game_message.choice_background = ($1 == "ON" ? 0 : 1)
  183.       end
  184.     end
  185.   end
  186.   #--------------------------------------------------------------------------
  187.   # ☆ 分岐終了の場合
  188.   #--------------------------------------------------------------------------
  189.   def command_404
  190.     if next_event_code == 102
  191.       @branch[@indent] -= 5 if @branch.include?(@indent)
  192.       @index += 1
  193.       command_skip
  194.     end
  195.   end
  196. end

  197. #==============================================================================
  198. # ■ Window_ChoiceList
  199. #==============================================================================
  200. class Window_ChoiceList
  201.   #--------------------------------------------------------------------------
  202.   # ☆ 入力処理の開始
  203.   #--------------------------------------------------------------------------
  204.   def start
  205.     return unless close?
  206.     clear_command_list
  207.     make_command_list
  208.     if @list.empty?
  209.       $game_message.choice_proc.call(-1)
  210.       return
  211.     end
  212.     update_placement
  213.     refresh
  214.     select(0)
  215.     if ($game_message.choice_var_id)
  216.       select_ext($game_variables[$game_message.choice_var_id])
  217.     end
  218.     open
  219.     activate
  220.   end
  221.   #--------------------------------------------------------------------------
  222.   # ☆ ウィンドウ位置の更新
  223.   #--------------------------------------------------------------------------
  224.   def update_placement
  225.     self.width = [max_choice_width + 12, 96].max + padding * 2
  226.     self.width = [width, Graphics.width].min
  227.     n = [@list.size, $game_message.choice_row_max].min
  228.     self.height = fitting_height(n)
  229.     self.x = Graphics.width - width
  230.     if @message_window.y >= Graphics.height / 2
  231.       self.y = @message_window.y - height
  232.     else
  233.       self.y = @message_window.y + @message_window.height
  234.     end
  235.     self.x = $game_message.choice_x if $game_message.choice_x
  236.     self.y = $game_message.choice_y if $game_message.choice_y
  237.   end
  238.   #--------------------------------------------------------------------------
  239.   # ☆ 選択肢の最大幅を取得
  240.   #--------------------------------------------------------------------------
  241.   def max_choice_width
  242.     @list.collect {|com| text_size(com[:name]).width }.max || 0
  243.   end
  244.   #--------------------------------------------------------------------------
  245.   # ☆ コマンドリストの作成
  246.   #--------------------------------------------------------------------------
  247.   def make_command_list
  248.     $game_message.choices.each_with_index do |choice, i|
  249.       next unless choice
  250.       str = choice.dup
  251.       next if str.slice!(/\s*if\(([^\)]+)\)/i) && !choice_eval($1)
  252.       enable = !str.slice!(/\s*en\(([^\)]+)\)/i) || choice_eval($1)
  253.       add_command(str, :choice, enable, i)
  254.     end
  255.   end
  256.   #--------------------------------------------------------------------------
  257.   # ○ 項目の描画
  258.   #--------------------------------------------------------------------------
  259.   alias _wdtk_choice_draw_item draw_item
  260.   def draw_item(index)
  261.     @choice_enabled = command_enabled?(index)
  262.     _wdtk_choice_draw_item(index)
  263.   end
  264.   #--------------------------------------------------------------------------
  265.   # ● テキスト描画色の変更
  266.   #--------------------------------------------------------------------------
  267.   def change_color(color, enabled = true)
  268.     super(color, enabled && @choice_enabled)
  269.   end
  270.   #--------------------------------------------------------------------------
  271.   # ☆ 決定ハンドラの呼び出し
  272.   #--------------------------------------------------------------------------
  273.   def call_ok_handler
  274.     $game_message.choice_proc.call(current_ext)
  275.     close
  276.   end
  277.   #--------------------------------------------------------------------------
  278.   # ● キャンセルボタンが押されたときの処理
  279.   #--------------------------------------------------------------------------
  280.   def process_cancel
  281.     return super if $game_message.choice_cancel_type % 5 == 0
  282.     index = @list.index {|c| c[:ext] == $game_message.choice_cancel_type - 1 }
  283.     return unless index
  284.     return super if command_enabled?(index)
  285.     Sound.play_buzzer
  286.   end
  287.   #--------------------------------------------------------------------------
  288.   # ● ウィンドウを閉じる
  289.   #--------------------------------------------------------------------------
  290.   def close
  291.     @message_window.on_show_fast unless $game_message.choice_help.empty?
  292.     super
  293.   end
  294.   #--------------------------------------------------------------------------
  295.   # ● ヘルプウィンドウ更新メソッドの呼び出し
  296.   #--------------------------------------------------------------------------
  297.   def call_update_help
  298.     update_help if active && !$game_message.choice_help.empty?
  299.   end
  300.   #--------------------------------------------------------------------------
  301.   # ● ヘルプウィンドウの更新
  302.   #--------------------------------------------------------------------------
  303.   def update_help
  304.     @message_window.force_clear
  305.     if $game_message.choice_help.include?(current_ext)
  306.       $game_message.texts.replace($game_message.choice_help[current_ext])
  307.     else
  308.       $game_message.texts.clear
  309.     end
  310.   end
  311.   #--------------------------------------------------------------------------
  312.   # ● 分岐用
  313.   #--------------------------------------------------------------------------
  314.   def choice_eval(formula)
  315.     s, v = $game_switches, $game_variables
  316.     begin
  317.       Kernel.eval(formula)
  318.     rescue
  319.       msgbox "以下の条件判定でエラーが出ました。\n\n", formula
  320.       true
  321.     end
  322.   end
  323.   #--------------------------------------------------------------------------
  324.   # ● フレーム更新
  325.   #--------------------------------------------------------------------------
  326.   def update
  327.     last_index = @index
  328.     super
  329.     if last_index != @index && $game_message.choice_var_id > 0
  330.       $game_variables[$game_message.choice_var_id] = current_ext
  331.     end
  332.   end
  333. end

  334. #==============================================================================
  335. # ■ Window_Message
  336. #==============================================================================
  337. class Window_Message
  338.   #--------------------------------------------------------------------------
  339.   # ○ ウィンドウ背景の更新
  340.   #--------------------------------------------------------------------------
  341.   alias _wdtk_choice_update_background update_background
  342.   def update_background
  343.     _wdtk_choice_update_background
  344.     @choice_window.opacity = $game_message.choice_background == 0 ? 255 : 0
  345.   end
  346.   #--------------------------------------------------------------------------
  347.   # ● 文章の標示を強制クリア
  348.   #--------------------------------------------------------------------------
  349.   def force_clear
  350.     @gold_window.close
  351.     @fiber = nil
  352.     close
  353.     if WdTk.include?(:MesEff)
  354.       @character_sprites.each do |sprite, params|
  355.         next if params.empty?
  356.         sprite.bitmap.clear
  357.         sprite.visible = false
  358.         params.clear
  359.       end
  360.     end
  361.   end
  362.   #--------------------------------------------------------------------------
  363.   # ● 文章を最後まで表示する
  364.   #--------------------------------------------------------------------------
  365.   def on_show_fast
  366.     @show_fast = true
  367.   end
  368. end
复制代码

这个脚本有类似【持有某物品才显示选项】的效果吗,注释里的变量、开关、角色等级(或者角色的其他属性)都可用,但是用事件脚本 if($game_party.item_number($data_items[23])>0)会报错,不知是我写法有问题还是脚本确实没这个功能(虽然知道可以把物品带入变量但要是同时有大量种类的物品选择(类似选择已有物品进行交易)就要占用大量变量位置所以希望直接写省点事

Lv5.捕梦者

梦石
0
星屑
33138
在线时间
10485 小时
注册时间
2009-3-15
帖子
4756
发表于 2018-9-21 19:46:20 | 显示全部楼层
本帖最后由 soulsaga 于 2018-9-22 14:22 编辑

之所以报错是因为选择分支用这脚本只能用一组括号..多一组也会出错的..
事件脚本里写
$i23=$game_party.item_number($data_items[23])

分支里写if($i23 > 0)即可

想知道数组用法的话
$game_variables[x] = []
i23 = $game_party.item_number($data_items[23])
i24 = $game_party.item_number($data_items[24])
$game_variables[x].push(i23)
$game_variables[x].push(i24)

然后选择分支:if(v[x][0] > 0)就是23号道具持有量if(v[x][1] > 0)就是24号道具持有量

点评

哦谢谢已经弄好了,感谢指点  发表于 2018-9-22 17:12
什么数组?我编辑过了啊  发表于 2018-9-22 14:13
脚本盲没怎么接触过数组,可以教下具体怎么使用吗  发表于 2018-9-22 13:41

评分

参与人数 1星屑 +30 收起 理由
VIPArcher + 30 塞糖

查看全部评分

回复 支持 反对

使用道具 举报

Lv4.逐梦者

梦石
0
星屑
7848
在线时间
1835 小时
注册时间
2017-10-23
帖子
352
发表于 2018-9-22 04:19:52 | 显示全部楼层
只要用1个变量作为“泛用变量”就行了, 因为你要用到这个变量的时候必然是新定义后马上判定。
选项这么短 用脚本判定也塞不进去。 用1个变量可以定义几乎所有的游戏内容

点评

主要变量要用在显示选项的脚本里……很多选项是同时显示的不可能用一个变量控制  发表于 2018-9-22 13:40
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-19 01:33

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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