Project1

标题: 脚本出现错误,以前一直都是正常的! [打印本页]

作者: 六道神话    时间: 2015-8-10 17:47
标题: 脚本出现错误,以前一直都是正常的!
用了一个物品颜色描绘的脚本后,测试进入商店选买入的时候就出现如图的情况 :脚本错误,选卖出什么都没问题,就是买入就会出现这个情况,怎么办?
脚本
RUBY 代码复制
  1. #encoding:utf-8
  2. #==============================================================================
  3. # ■ 装备说明增强 By wyongcan
  4. #==============================================================================
  5. module Equipplus
  6.   CODE ={
  7.     11 => "属性抗性",
  8.     12 => "弱化抗性",
  9.     13 => "状态抗性",
  10.     14 => "状态免疫",
  11.     21 => "普通能力",
  12.     22 => "添加能力",
  13.     23 => "特殊能力",
  14.     31 => "攻击附带属性",
  15.     32 => "攻击附带状态",
  16.     33 => "修正攻击速度",
  17.     34 => "添加攻击次数",
  18.     41 => "添加技能类型",
  19.     42 => "禁用技能类型",
  20.     43 => "添加技能",
  21.     44 => "禁用技能",
  22.     51 => "可装备武器类型",
  23.     52 => "可装备护甲类型",
  24.     53 => "固定装备",
  25.     54 => "禁用装备",
  26.     55 => "装备风格",
  27.     61 => "添加行动次数",
  28.     62 => "特殊标志",
  29.     63 => "消失效果",
  30.     64 => "队伍能力"}
  31.   #特殊标志
  32.   FLAG ={
  33.                 0 => "自动战斗",
  34.                 1 => "擅长防御",
  35.                 2 => "保护弱者",
  36.                 3 => "特技专注"}
  37.   #普通能力
  38.         PARAM ={
  39.                 0 => "最大HP",
  40.                 1 => "最大MP",
  41.                 2 => "物理攻击",
  42.                 3 => "物理防御",
  43.                 4 => "魔法攻击",
  44.                 5 => "魔法防御",
  45.                 6 => "敏 捷 值",
  46.                 7 => "幸 运 值"}
  47.   #添加能力
  48.         XPARAM ={
  49.                 0 => "物理命中几率:",
  50.                 1 => "物理闪避几率:",
  51.                 2 => "必杀几率:",
  52.                 3 => "必杀闪避几率:",
  53.                 4 => "魔法闪避几率:",
  54.                 5 => "魔法反射几率:",
  55.                 6 => "物理反击几率:",
  56.                 7 => "体力值再生速度:",
  57.                 8 => "魔力值再生速度:",
  58.                 9 => "特技值再生速度:"}
  59.   #特殊能力
  60.         SPARAM ={
  61.                 0 => "受到攻击的几率",
  62.                 1 => "防御效果比率",
  63.                 2 => "恢复效果比率",
  64.                 3 => "药理知识",
  65.                 4 => "MP消费率",
  66.                 5 => "TP消耗率",
  67.                 6 => "物理伤害加成",
  68.                 7 => "魔法伤害加成",
  69.                 8 => "地形伤害加成",
  70.                 9 => "经验获得加成"}
  71.         @队伍能力 ={
  72.                 0 => "遇敌几率减半",
  73.                 1 => "随机遇敌无效",
  74.                 2 => "敌人偷袭无效",
  75.                 3 => "先制攻击几率上升",
  76.                 4 => "获得金钱数量双倍",
  77.                 5 => "物品掉落几率双倍"}
  78.   def self.equiphelpready
  79.     @状态 = {}
  80.     @武器类型 = {}
  81.     @防具类型 = {}
  82.     @属性 = {}
  83.     $data_states.each{|x| @状态[x.id] = x.name if x != nil}
  84.     elements = $data_system.elements
  85.     weapon_types = $data_system.weapon_types
  86.     armor_types = $data_system.armor_types
  87.     elements.each_with_index{|x,y| @属性[y] = x if x != ""}
  88.     weapon_types.each_with_index{|x,y| @武器类型[y] = x if x != ""}
  89.     armor_types.each_with_index{|x,y| @防具类型[y] = x if x != ""}
  90.   end
  91.   def self.getequiphelp(equip)
  92.     help = ""
  93.     param = []
  94.     equip.params.each_with_index{|x,y| param.push([PARAM[y],x])}
  95.     param = param.select{|x| x[1] != 0}
  96.     param.each{|x| help += x[0] + ":" + x[1].to_int.to_s + "\n"}
  97.     features = equip.features
  98.     features.select{|x| x.code == 55}.each{|x| help += CODE[x.code] + ":双持武器" + "\n"}
  99.     features.select{|x| x.code == 11}.each{|x| help += CODE[x.code] + ":" + @属性[x.data_id] + "*" + x.value.to_s + "\n"}
  100.     features.select{|x| x.code == 12}.each{|x| help += CODE[x.code] + ":" + PARAM[x.data_id] + "*" + x.value.to_s + "\n"}
  101.     features.select{|x| x.code == 13}.each{|x| help += CODE[x.code] + ":" + @状态[x.data_id] + "*" + x.value.to_s + "\n"}
  102.     features.select{|x| x.code == 14}.each{|x| help += CODE[x.code] + ":" + @状态[x.data_id] + "\n"}
  103.     features.select{|x| x.code == 31}.each{|x| help += CODE[x.code] + ":" + @属性[x.data_id] + "\n"}
  104.     features.select{|x| x.code == 32}.each{|x| help += CODE[x.code] + ":" + @状态[x.data_id] + "+" + x.value.to_s + "\n"}
  105.     features.select{|x| x.code == 33}.each{|x| help += CODE[x.code] + ":" + x.value.to_s + "\n"}
  106.     features.select{|x| x.code == 34}.each{|x| help += CODE[x.code] + ":" + x.value.to_s + "\n"}
  107.     features.select{|x| x.code == 41}.each{|x| help += CODE[x.code] + ":" + (x.data_id == 1 ? "特技" : "魔法")  + "\n"}
  108.     features.select{|x| x.code == 42}.each{|x| help += CODE[x.code] + ":" + (x.data_id == 1 ? "特技" : "魔法")  + "\n"}
  109.     features.select{|x| x.code == 43}.each{|x| help += CODE[x.code] + ":" + $data_skills[x.data_id].name  + "\n"}
  110.     features.select{|x| x.code == 44}.each{|x| help += CODE[x.code] + ":" + $data_skills[x.data_id].name  + "\n"}
  111.     features.select{|x| x.code == 51}.each{|x| help += CODE[x.code] + ":" + @武器类型[x.data_id]  + "\n"}
  112.     features.select{|x| x.code == 52}.each{|x| help += CODE[x.code] + ":" + @防具类型[x.data_id]  + "\n"}
  113.     features.select{|x| x.code == 61}.each{|x| help += CODE[x.code] + ":" + x.value.to_s  + "\n"}
  114.     features.select{|x| x.code == 62}.each{|x| help += CODE[x.code] + ":" + FLAG[x.data_id]  + "\n"}
  115.     features.select{|x| x.code == 64}.each{|x| help += CODE[x.code] + ":" + @队伍能力[x.data_id]  + "\n"}
  116.     featuresparam = []
  117.     featuresparam.push features.select{|x| x.code == 21}
  118.     featuresparam.push features.select{|x| x.code == 22}
  119.     featuresparam.push features.select{|x| x.code == 23}
  120.     featuresparam[0].each{|x| help += PARAM[x.data_id] + "*" + x.value.to_s + "\n"}
  121.     featuresparam[1].each{|x| help += XPARAM[x.data_id] + x.value.to_s + "\n"}
  122.     featuresparam[2].each{|x| help += SPARAM[x.data_id] + "*" + x.value.to_s + "\n"}
  123.     help
  124.   end
  125.   def self.getline(text,maxtext)
  126.     xtext = []
  127.     line = 0
  128.     text.each_line{|x| xtext.push x.sub(/\n/){}}
  129.     xtext.each{|x| x.size % maxtext != 0 ? line += x.size / maxtext + 1 : line += x.size / maxtext}
  130.     line
  131.   end
  132. end
  133. #==============================================================================
  134. # ■ Window_Help
  135. #------------------------------------------------------------------------------
  136. #  显示特技和物品等的说明、以及角色状态的窗口
  137. #==============================================================================
  138.  
  139. class Window_Help2 < Window_Base
  140.   #--------------------------------------------------------------------------
  141.   # ● 初始化对象
  142.   #--------------------------------------------------------------------------
  143.   def initialize(line_number = 0)
  144.     super(0, 0, 210, 0)
  145.     self.z = 150
  146.     contents.font.size = 14
  147.     hide
  148.   end
  149.   #--------------------------------------------------------------------------
  150.   # ● 设置内容
  151.   #--------------------------------------------------------------------------
  152.   def set_text(text)
  153.       @text = text
  154.       refresh
  155.   end
  156.   #--------------------------------------------------------------------------
  157.   # ● 清除
  158.   #--------------------------------------------------------------------------
  159.   def clear
  160.     set_text("")
  161.   end
  162.   #--------------------------------------------------------------------------
  163.   # ● 更新帮助位置
  164.   #--------------------------------------------------------------------------
  165.   def uppos(index,rect,window)
  166.     self.height = fitting_height2(Equipplus.getline(@xtext,13))
  167.     create_contents
  168.     contents.font.size = 14
  169.     rect.x -= window.ox
  170.     rect.y -= window.oy
  171.     ax = rect.x + rect.width + 10
  172.     ax = rect.x - self.width + 10 if ax + self.width > window.width + 10
  173.     ax += window.x
  174.     ax = 0 if ax < 0
  175.     ay = rect.y + rect.height
  176.     ay = rect.y - self.height if ay + self.height > window.height
  177.     ay += window.y
  178.     ay = 0 if ay < 0
  179.     self.x = ax
  180.     self.y = ay
  181.     set_text(@xtext)
  182.     show
  183.   end
  184.   #--------------------------------------------------------------------------
  185.   # ● 设置物品
  186.   #     item : 技能、物品等
  187.   #--------------------------------------------------------------------------
  188.   def set_item(item)
  189.     if item == nil
  190.       set_text("")
  191.       return
  192.     end
  193.     @xtext = ""
  194.     @xtext = "名称:" + item.name + "\n"
  195.     @xtext += "介绍:" + item.description + "\n"
  196.     @xtext += "价格:" + item.price.to_s + "\n" if item.is_a?(RPG::EquipItem) || item.is_a?(RPG::Item)
  197.     @xtext += Equipplus.getequiphelp(item) if item.is_a?(RPG::EquipItem)
  198.     @xtext = @xtext[0,@text.size - 2] if @xtext[@xtext.size - 2,2] == "\n"
  199.   end
  200.   #--------------------------------------------------------------------------
  201.   # ● 刷新
  202.   #--------------------------------------------------------------------------
  203.   def refresh
  204.     contents.clear
  205.     hide if @text == ""
  206.     draw_text_ex(4, 0, @text,width,40,false)
  207.   end
  208. end
  209. class Window_Base < Window
  210.   #--------------------------------------------------------------------------
  211.   # ● 计算窗口显示指定行数时的应用高度2*************************
  212.   #--------------------------------------------------------------------------
  213.   def fitting_height2(line_number)
  214.     line_number * contents.font.size + standard_padding * 2
  215.   end
  216. #~ draw_text_ex的增强,使其可以自动换行  原作者:叶子 修改:wyongcan
  217.   #--------------------------------------------------------------------------
  218.   # ● 绘制带有控制符的文本内容
  219.   #   如果传递了width参数的话,会自动换行
  220.   #--------------------------------------------------------------------------
  221.   def draw_text_ex(x, y, text, width = nil,textwidth = nil,normalfont = true)
  222.     reset_font_settings if normalfont == true
  223.     text = convert_escape_characters(text)
  224.     pos = {:x => x, :y => y, :new_x => x, :height => calc_line_height(text)}
  225.     if width != nil
  226.       pos[:height] = contents.font.size
  227.       pos[:width] = width
  228.       pos[:textwidth] = textwidth
  229.     end
  230.     process_character(text.slice!(0, 1), text, pos) until text.empty?
  231.   end
  232.   #--------------------------------------------------------------------------
  233.   # ● 文字的处理
  234.   #     c    : 文字
  235.   #     text : 绘制处理中的字符串缓存(字符串可能会被修改)
  236.   #     pos  : 绘制位置 {:x, :y, :new_x, :height}
  237.   #--------------------------------------------------------------------------
  238.   def process_character(c, text, pos)
  239.     case c
  240.     when "\r"   # 回车
  241.       return
  242.     when "\n"   # 换行
  243.       process_new_line(text, pos)
  244.     when "\f"   # 翻页
  245.       process_new_page(text, pos)
  246.     when "\e"   # 控制符
  247.       process_escape_character(obtain_escape_code(text), text, pos)
  248.     else        # 普通文字
  249.       pos[:textwidth] == nil ? text_width = text_size(c).width : text_width = pos[:textwidth]
  250.       if pos[:width] != nil && pos[:x] - pos[:new_x] + text_width > pos[:width]
  251.         process_new_line(text, pos)
  252.       end
  253.       process_normal_character(c, pos)
  254.     end
  255.   end
  256. end
  257.  
  258. class Window_ItemList < Window_Selectable
  259.   #--------------------------------------------------------------------------
  260.   # ● 更新帮助内容
  261.   #--------------------------------------------------------------------------
  262.   def update_help
  263.     @help_window.set_item(item)
  264.     @help_window.uppos(index,item_rect(index),self) if index != -1 && item != nil
  265.   end
  266. end
  267.  
  268. class Window_SkillList < Window_Selectable
  269.   #--------------------------------------------------------------------------
  270.   # ● 更新帮助内容
  271.   #--------------------------------------------------------------------------
  272.   def update_help
  273.     @help_window.set_item(item)
  274.     @help_window.uppos(index,item_rect(index),self) if index != -1 && item != nil
  275.   end
  276. end
  277.  
  278. class Window_ShopBuy < Window_Selectable
  279.   #--------------------------------------------------------------------------
  280.   # ● 更新帮助内容
  281.   #--------------------------------------------------------------------------
  282.   def update_help
  283.     @help_window.set_item(item) if @help_window
  284.     @help_window.uppos(index,item_rect(index),self) if index != -1 && item != nil && @help_window
  285.     @status_window.item = item if @status_window
  286.   end
  287. end
  288.  
  289. class Window_EquipSlot < Window_Selectable
  290.   #--------------------------------------------------------------------------
  291.   # ● 更新帮助内容
  292.   #--------------------------------------------------------------------------
  293.   def update_help
  294.     super
  295.     @help_window.set_item(item) if @help_window
  296.     @help_window.uppos(index,item_rect(index),self) if index != -1 && item != nil && @help_window
  297.     @status_window.set_temp_actor(nil) if @status_window
  298.   end
  299. end
  300.  
  301. class Scene_Shop < Scene_MenuBase
  302.         alias on_sell_ok_old on_sell_ok
  303.         def on_sell_ok
  304.                 on_sell_ok_old
  305.                 @help_window.hide
  306.         end
  307.         alias on_buy_ok_old on_buy_ok
  308.         def on_buy_ok
  309.                 on_buy_ok_old
  310.                 @help_window.hide
  311.         end
  312.         alias on_number_ok_old on_number_ok
  313.         def on_number_ok
  314.                 on_number_ok_old
  315.     @help_window.refresh
  316.                 @help_window.show
  317.         end
  318.         alias on_number_cancel_old on_number_cancel
  319.         def on_number_cancel
  320.                 on_number_cancel_old
  321.     @help_window.refresh
  322.                 @help_window.show
  323.         end
  324. end
  325.  
  326. class Scene_Title < Scene_Base
  327.   alias start_old start
  328.   def start
  329.     start_old
  330.     Equipplus.equiphelpready
  331.   end
  332. end
  333.  
  334. class Scene_ItemBase < Scene_MenuBase
  335.         alias old_on_actor_cancel on_actor_cancel
  336.   def on_actor_cancel
  337.     old_on_actor_cancel
  338.         @help_window.refresh
  339.   end
  340.         alias old_on_actor_ok on_actor_ok
  341.   def on_actor_ok
  342.     old_on_actor_ok
  343.         @help_window.refresh
  344.   end
  345. end
  346.  
  347. class Window_Base < Window
  348.         alias old_process_new_line process_new_line
  349.         def process_new_line(text, pos)
  350.     old_process_new_line(text, pos)
  351.                 pos[:height] = contents.font.size if pos[:width] != nil
  352.         end
  353. end
  354.  
  355. class Scene_MenuBase < Scene_Base
  356.   def create_help_window
  357.     @help_window = Window_Help2.new
  358.     @help_window.viewport = @viewport
  359.   end
  360. end
  361. class Scene_Battle < Scene_Base
  362.   def create_help_window
  363.     @help_window = Window_Help2.new
  364.     @help_window.visible = false
  365.   end
  366. end

QQ截图20150810174300.jpg (46.18 KB, 下载次数: 24)

脚本错误

脚本错误

作者: 六道神话    时间: 2015-8-10 17:54
脚本“装备帮助增强”第103行:发生 NomethodError。undefined method ,[ ], for nil:NilClass
作者: VIPArcher    时间: 2015-8-10 18:35
我摔 https://rpg.blue/thread-372464-1-1.html




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1