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

Project1

 找回密码
 注册会员
搜索
查看: 1002|回复: 4

[已经解决] 选择肢扩张脚本,能否判断角色有某技能才显示【已解决】

[复制链接]

Lv3.寻梦者

梦石
0
星屑
2323
在线时间
274 小时
注册时间
2017-7-25
帖子
163
发表于 2019-9-18 20:16:15 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 骷髅岛遗老 于 2019-9-19 12:23 编辑

RUBY 代码复制
  1. =begin
  2.  
  3.  ▼ 選択肢拡張 ver. 3.2
  4.  
  5.  RPGツクールVXAce用スクリプト
  6.  
  7.  制作 : 木星ペンギン
  8.  URL  : [url]http://woodpenguin.blog.fc2.com/[/url]
  9.  
  10. 选择支里填写 if($game_party.members[0].level > 10)  
  11. 就是这个选项需要 队伍第一位角色的等级大于10 才会显示出来(并且才可以选择)
  12. 而填写 en(v[1] > 5 && s[1])
  13. 就是当 1号变量大于5且一号开关开启 时,才可以选择,否则是半透明不可选(如果选择会有警告音,且无效)
  14.  
  15.  
  16.  
  17.  
  18. ------------------------------------------------------------------------------
  19.  概要
  20.  
  21.  □ 選択肢を連続して設定した場合、つなげて一つの選択肢にする機能の追加。
  22.  □ 条件を設定することで、その項目を表示しない機能の追加。
  23.  □ 選択肢のカーソル初期位置を指定する機能と
  24.     現在のカーソル位置を変数に入れる機能の追加。
  25.  
  26.  □ 選択肢ウィンドウの位置を一時的に変更する機能の追加。
  27.  □ 条件を設定することで、その項目を半透明にして選択不可にする機能の追加。
  28.  □ 選択肢毎にヘルプメッセージを表示できる機能の追加。
  29.  
  30. ------------------------------------------------------------------------------
  31.  使い方
  32.  
  33.  □ 選択肢の表示を続けて配置すると、一つの選択肢にまとめられます。
  34.   ・「キャンセルの場合」の処理は、無効以外を設定したものが適用され、
  35.      複数ある場合は後の選択肢のものが適用されます。
  36.  
  37.  □ 選択肢の文章中に if(条件) と入れ、その条件が偽になると項目が表示されなくなります。
  38.   ・条件は eval によって評価されます。(詳細は【組み込み関数】を参照)
  39.   ・s でスイッチ、v で変数を参照できます。
  40.   ・「キャンセルの場合」の項目が表示されない場合、無効と同じ処理をします。
  41.  
  42.  □ 注釈に以下の文字列を入れることで、指定された変数の値が
  43.     カーソルの初期位置になります。
  44.  
  45.     カーソル記憶(n)
  46.     
  47.       n : カーソル初期位置の入った変数番号
  48.  
  49.   ・選択肢のカーソルの位置が変更されるたびに、
  50.     この変数に選択肢の番号が入れられるようになります。
  51.  
  52.  □ 注釈に以下の文字列を入れることで、選択肢ウィンドウの表示位置を
  53.    一時的に変更することが出来ます。
  54.  
  55.     選択肢位置(x, y[, row])
  56.     
  57.       x   : ウィンドウを表示する X 座標。
  58.       y   : ウィンドウを表示する Y 座標。
  59.       row : 選択肢を表示する最大行数。
  60.             指定しない場合は、通常の最大行数を無視して
  61.             すべての選択肢が表示されます。
  62.  
  63.  □ 注釈に以下の文字列を入れることで、選択肢ウィンドウの背景が非表示になります。
  64.  
  65.     背景OFF
  66.     
  67.  □ 選択肢の文章中に en(条件) と入れ、その条件が偽になると項目が半透明で表示されます。
  68.   ・条件は eval によって評価されます。(詳細は【組み込み関数】を参照)
  69.   ・s でスイッチ、v で変数を参照できます。
  70.   ・「キャンセルの場合」の項目が半透明の場合、ブザーが鳴ります。
  71.  
  72.  □ 各項目の下に、注釈で以下の文字列を入れると、続きの注釈を
  73.     項目のヘルプメッセージとしてカーソルを合わせたときに標示することができます。
  74.  
  75.     選択肢ヘルプ
  76.     
  77.  □ 詳細は下記のサイトを参照してください。
  78.  
  79.   [url]http://woodpenguin.web.fc2.com/rgss3/choice_ex.html[/url]
  80.  
  81. =end
  82. module WdTk
  83. module ChoiceEX
  84. #//////////////////////////////////////////////////////////////////////////////
  85. #
  86. # 設定項目
  87. #
  88. #//////////////////////////////////////////////////////////////////////////////
  89.   #--------------------------------------------------------------------------
  90.   # ● 選択肢の最大行数
  91.   #     選択肢を表示するウィンドウの行数の最大数です。
  92.   #     選択肢がこの数より小さければ、選択肢の数に合わせます。
  93.   #--------------------------------------------------------------------------
  94.   RowMax = 10
  95.  
  96.   #--------------------------------------------------------------------------
  97.   # ● 選択肢ヘルプを読み取る文字列
  98.   #--------------------------------------------------------------------------
  99.   Help = "選択肢ヘルプ"
  100.  
  101. end
  102.  
  103. #//////////////////////////////////////////////////////////////////////////////
  104. #
  105. # 以降、変更する必要なし
  106. #
  107. #//////////////////////////////////////////////////////////////////////////////
  108.  
  109.   @material ||= []
  110.   @material << :ChoiceEX
  111.   def self.include?(sym)
  112.     @material.include?(sym)
  113.   end
  114.  
  115. end
  116.  
  117. #==============================================================================
  118. # ■ Game_Message
  119. #==============================================================================
  120. class Game_Message
  121.   #--------------------------------------------------------------------------
  122.   # ● 公開インスタンス変数
  123.   #--------------------------------------------------------------------------
  124.   attr_accessor :choice_x                 # 選択肢ウィンドウの表示 X 座標
  125.   attr_accessor :choice_y                 # 選択肢ウィンドウの表示 Y 座標
  126.   attr_accessor :choice_row_max           # 選択肢ウィンドウの表示行数
  127.   attr_accessor :choice_help              # 選択肢のヘルプ
  128.   attr_accessor :choice_var_id            # 選択肢のカーソル位置を入れる変数ID
  129.   attr_accessor :choice_background        # 選択肢ウィンドウ背景の表示状態
  130.   #--------------------------------------------------------------------------
  131.   # ○ クリア
  132.   #--------------------------------------------------------------------------
  133.   alias _wdtk_choice_clear clear
  134.   def clear
  135.     _wdtk_choice_clear
  136.     @choice_x = @choice_y = nil
  137.     @choice_row_max = WdTk::ChoiceEX::RowMax
  138.     @choice_help = {}
  139.     @choice_var_id = 0
  140.     @choice_background = 0
  141.   end
  142. end
  143.  
  144. #==============================================================================
  145. # ■ Game_Interpreter
  146. #==============================================================================
  147. class Game_Interpreter
  148.   #--------------------------------------------------------------------------
  149.   # ☆ 選択肢のセットアップ
  150.   #--------------------------------------------------------------------------
  151.   def setup_choices(params)
  152.     add_choices(params, @index)
  153.     $game_message.choice_proc = Proc.new {|n| @branch[@indent] = n }
  154.   end
  155.   #--------------------------------------------------------------------------
  156.   # ● 選択肢の追加
  157.   #--------------------------------------------------------------------------
  158.   def add_choices(params, i, d = 0)
  159.     params[0].each_with_index {|s, n| $game_message.choices[n + d] = s }
  160.     $game_message.choice_cancel_type = params[1] + d if params[1] > 0
  161.     indent = @list[i].indent
  162.     loop do
  163.       i += 1
  164.       if @list[i].indent == indent
  165.         case @list[i].code
  166.         when 402 # [**] の場合
  167.           get_help_texts(@list[i].parameters[0] + d, i + 1)
  168.         when 404 # 分岐終了
  169.           break
  170.         end
  171.       end
  172.     end
  173.     i += 1
  174.     add_choices(@list[i].parameters, i, d + 5) if @list[i].code == 102
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # ● ヘルプ用テキストの取得
  178.   #--------------------------------------------------------------------------
  179.   def get_help_texts(b, i)
  180.     if @list[i].code == 108 && @list[i].parameters[0] == WdTk::ChoiceEX::Help
  181.       $game_message.choice_help[b] = []
  182.       while @list[i + 1].code == 408
  183.         i += 1
  184.         $game_message.choice_help[b] << @list[i].parameters[0]
  185.       end
  186.     end
  187.   end
  188.   #--------------------------------------------------------------------------
  189.   # ◯ 注釈
  190.   #--------------------------------------------------------------------------
  191.   alias _wdtk_choice_command_108 command_108
  192.   def command_108
  193.     _wdtk_choice_command_108
  194.     @comments.each do |comment|
  195.       case comment
  196.       when /選択肢位置\((\d+),\s*(\d+),?\s*(\d*)\)/
  197.         $game_message.choice_x = $1.to_i
  198.         $game_message.choice_y = $2.to_i
  199.         $game_message.choice_row_max = ($3.empty? ? 99 : $3.to_i)
  200.       when /カーソル記憶\((\d+)\)/
  201.         $game_message.choice_var_id = $1.to_i
  202.       when /背景(ON|OFF)/
  203.         $game_message.choice_background = ($1 == "ON" ? 0 : 1)
  204.       end
  205.     end
  206.   end
  207.   #--------------------------------------------------------------------------
  208.   # ☆ 分岐終了の場合
  209.   #--------------------------------------------------------------------------
  210.   def command_404
  211.     if next_event_code == 102
  212.       @branch[@indent] -= 5 if @branch.include?(@indent)
  213.       @index += 1
  214.       command_skip
  215.     end
  216.   end
  217. end
  218.  
  219. #==============================================================================
  220. # ■ Window_ChoiceList
  221. #==============================================================================
  222. class Window_ChoiceList
  223.   #--------------------------------------------------------------------------
  224.   # ☆ 入力処理の開始
  225.   #--------------------------------------------------------------------------
  226.   def start
  227.     return unless close?
  228.     clear_command_list
  229.     make_command_list
  230.     if @list.empty?
  231.       $game_message.choice_proc.call(-1)
  232.       return
  233.     end
  234.     update_placement
  235.     refresh
  236.     select(0)
  237.     if ($game_message.choice_var_id)
  238.       select_ext($game_variables[$game_message.choice_var_id])
  239.     end
  240.     open
  241.     activate
  242.   end
  243.   #--------------------------------------------------------------------------
  244.   # ☆ ウィンドウ位置の更新
  245.   #--------------------------------------------------------------------------
  246.   def update_placement
  247.     self.width = [max_choice_width + 12, 96].max + padding * 2
  248.     self.width = [width, Graphics.width].min
  249.     n = [@list.size, $game_message.choice_row_max].min
  250.     self.height = fitting_height(n)
  251.     self.x = Graphics.width - width
  252.     if @message_window.y >= Graphics.height / 2
  253.       self.y = @message_window.y - height
  254.     else
  255.       self.y = @message_window.y + @message_window.height
  256.     end
  257.     self.x = $game_message.choice_x if $game_message.choice_x
  258.     self.y = $game_message.choice_y if $game_message.choice_y
  259.   end
  260.   #--------------------------------------------------------------------------
  261.   # ☆ 選択肢の最大幅を取得
  262.   #--------------------------------------------------------------------------
  263.   def max_choice_width
  264.     @list.collect {|com| text_size(com[:name]).width }.max || 0
  265.   end
  266.   #--------------------------------------------------------------------------
  267.   # ☆ コマンドリストの作成
  268.   #--------------------------------------------------------------------------
  269.   def make_command_list
  270.     $game_message.choices.each_with_index do |choice, i|
  271.       next unless choice
  272.       str = choice.dup
  273.       next if str.slice!(/\s*if\(([^\)]+)\)/i) && !choice_eval($1)
  274.       enable = !str.slice!(/\s*en\(([^\)]+)\)/i) || choice_eval($1)
  275.       add_command(str, :choice, enable, i)
  276.     end
  277.   end
  278.   #--------------------------------------------------------------------------
  279.   # ○ 項目の描画
  280.   #--------------------------------------------------------------------------
  281.   alias _wdtk_choice_draw_item draw_item
  282.   def draw_item(index)
  283.     @choice_enabled = command_enabled?(index)
  284.     _wdtk_choice_draw_item(index)
  285.   end
  286.   #--------------------------------------------------------------------------
  287.   # ● テキスト描画色の変更
  288.   #--------------------------------------------------------------------------
  289.   def change_color(color, enabled = true)
  290.     super(color, enabled && @choice_enabled)
  291.   end
  292.   #--------------------------------------------------------------------------
  293.   # ☆ 決定ハンドラの呼び出し
  294.   #--------------------------------------------------------------------------
  295.   def call_ok_handler
  296.     $game_message.choice_proc.call(current_ext)
  297.     close
  298.   end
  299.   #--------------------------------------------------------------------------
  300.   # ● キャンセルボタンが押されたときの処理
  301.   #--------------------------------------------------------------------------
  302.   def process_cancel
  303.     return super if $game_message.choice_cancel_type % 5 == 0
  304.     index = @list.index {|c| c[:ext] == $game_message.choice_cancel_type - 1 }
  305.     return unless index
  306.     return super if command_enabled?(index)
  307.     Sound.play_buzzer
  308.   end
  309.   #--------------------------------------------------------------------------
  310.   # ● ウィンドウを閉じる
  311.   #--------------------------------------------------------------------------
  312.   def close
  313.     @message_window.on_show_fast unless $game_message.choice_help.empty?
  314.     super
  315.   end
  316.   #--------------------------------------------------------------------------
  317.   # ● ヘルプウィンドウ更新メソッドの呼び出し
  318.   #--------------------------------------------------------------------------
  319.   def call_update_help
  320.     update_help if active && !$game_message.choice_help.empty?
  321.   end
  322.   #--------------------------------------------------------------------------
  323.   # ● ヘルプウィンドウの更新
  324.   #--------------------------------------------------------------------------
  325.   def update_help
  326.     @message_window.force_clear
  327.     if $game_message.choice_help.include?(current_ext)
  328.       $game_message.texts.replace($game_message.choice_help[current_ext])
  329.     else
  330.       $game_message.texts.clear
  331.     end
  332.   end
  333.   #--------------------------------------------------------------------------
  334.   # ● 分岐用
  335.   #--------------------------------------------------------------------------
  336.   def choice_eval(formula)
  337.     s, v = $game_switches, $game_variables
  338.     begin
  339.       Kernel.eval(formula)
  340.     rescue
  341.       msgbox "以下の条件判定でエラーが出ました。\n\n", formula
  342.       true
  343.     end
  344.   end
  345.   #--------------------------------------------------------------------------
  346.   # ● フレーム更新
  347.   #--------------------------------------------------------------------------
  348.   def update
  349.     last_index = @index
  350.     super
  351.     if last_index != @index && $game_message.choice_var_id > 0
  352.       $game_variables[$game_message.choice_var_id] = current_ext
  353.     end
  354.   end
  355. end
  356.  
  357. #==============================================================================
  358. # ■ Window_Message
  359. #==============================================================================
  360. class Window_Message
  361.   #--------------------------------------------------------------------------
  362.   # ○ ウィンドウ背景の更新
  363.   #--------------------------------------------------------------------------
  364.   alias _wdtk_choice_update_background update_background
  365.   def update_background
  366.     _wdtk_choice_update_background
  367.     @choice_window.opacity = $game_message.choice_background == 0 ? 255 : 0
  368.   end
  369.   #--------------------------------------------------------------------------
  370.   # ● 文章の標示を強制クリア
  371.   #--------------------------------------------------------------------------
  372.   def force_clear
  373.     @gold_window.close
  374.     @fiber = nil
  375.     close
  376.     if WdTk.include?(:MesEff)
  377.       @character_sprites.each do |sprite, params|
  378.         next if params.empty?
  379.         sprite.bitmap.clear
  380.         sprite.visible = false
  381.         params.clear
  382.       end
  383.     end
  384.   end
  385.   #--------------------------------------------------------------------------
  386.   # ● 文章を最後まで表示する
  387.   #--------------------------------------------------------------------------
  388.   def on_show_fast
  389.     @show_fast = true
  390.   end
  391. end


又是这个脚本,请问它能判断类似【数据库3号的角色学习了40号技能】或者【队伍中存在数据库3号角色】才显示选项吗 据说这玩意只能判断一个括号,那应该怎么写或者怎么修改这个脚本才能实现这个效果?
先判断角色技能代入变量的就算了,一次很多选项代不过来的

Lv6.析梦学徒

老鹰

梦石
39
星屑
33308
在线时间
6542 小时
注册时间
2012-5-26
帖子
3176

极短23参与极短22参与极短21评委老司机慢点开短篇十吟唱者组别冠军开拓者剧作品鉴家

发表于 2019-9-18 21:34:10 | 显示全部楼层
我觉得在选择框里可能写不下……
数据库3号角色学习了40号技能 $game_actors[3].skill_learn?($data_skills[40])
数据库3号角色是否在队伍中  $game_party.members.any? {|a| a.id == 3}
并且 就用 && 符号连接
或者 就用 || 符号连接

点评

可以了,谢谢大佬_(:з」∠)_  发表于 2019-9-19 12:22
那就 $game_actors[3].skills.any?{|s|s.id == 40} 吧  发表于 2019-9-18 22:45
判断角色可以了,技能好像真不行……这个脚本使用要求自带一个if(),括号里面有其他()就会报错  发表于 2019-9-18 21:47

评分

参与人数 1星屑 +50 收起 理由
VIPArcher + 50 认可答案

查看全部评分

回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-3-28 19:26

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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