查看: 1883|回复: 3

[已经解决] 求修改魔法商店脚本

[复制链接]
梦石
0
星屑
80
在线时间
216 小时
注册时间
2011-9-17
回帖
125
发表于 2015-11-30 19:24:37 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 工藤~新一じ 于 2015-12-1 18:44 编辑

这段脚本是我在66论坛里搜的,原来的脚本是任何角色都能学习此商店的技能,现在改成了限制职业学习技能。
我测试了一下这段脚本,发现有几个问题,我一一列举出来,希望论坛的大大能帮我改
1. 学技能不扣钱,扣除某个id的物品。所以商店上显示的金钱也相应得显示对应物品的个数。
2. 角色显示是4人,但楼主的游戏队伍里有5个人,第一个是带队的,不学习任何技能,所以在这个界面当中,只显示队伍里的第二位、第三位、第四位和第五位,队伍里第一位不显示!
楼主的游戏很希望能做到学习技能的效果,但楼主真的完全不懂脚本,很多效果我都是用事件来写,但有些效果是事件写不了的,所以很希望能有大大帮我,真的感谢!!!

楼主自己解决这两个问题了,有同样需要的朋友可以拿去用哦。
脚本如下:
  1. #==============================================================================
  2. # ■ 本脚本源自[url]www.66rpg.com[/url],转载与使用请保留此信息
  3. #==============================================================================

  4. #——以下是一些自定义的内容
  5. #呼出魔法商店$scene = Scene_MShop.new([1,2,3,4,5,6,7,8])
  6. #在技能说明末尾增加@100,则学习此技能需要扣掉9号变量100

  7. $mShop_use_1 = "魔法水晶"    #——这项是购买魔法特技的货币的名称,如“灵魄”、“金钱”

  8. $mShop_use_2 = "个"  #——这项是购买魔法特技的货币单位,如“点”、“¥”

  9. $mShop_use_variable = 9  #——这项是购买魔法特技时消耗的变量编号,如果=0 则是消耗金钱

  10. $mShop_Window_Opacity = 200  #——这项是窗口透明度

  11. # 每个职业可以学的技能列表
  12. $class_canlearn_list = {  1 => [1,80],
  13.                           2 => [60,61],
  14.                           3 => []}

  15. #==============================================================================
  16. # ■ Window_MGold
  17. #------------------------------------------------------------------------------
  18. #  显示金钱的窗口。
  19. #==============================================================================
  20. class Window_MGold < Window_Base
  21.   #--------------------------------------------------------------------------
  22.   # ● 初始化窗口
  23.   #--------------------------------------------------------------------------
  24.   def initialize
  25.     super(0, 0, 272, 64)
  26.     self.contents = Bitmap.new(width - 32, height - 32)
  27.     refresh
  28.   end
  29.   #--------------------------------------------------------------------------
  30.   # ● 刷新
  31.   #--------------------------------------------------------------------------
  32.   def refresh
  33.     self.contents.clear
  34.     self.contents.font.color = system_color
  35.     self.contents.draw_text(0, 0 , 240,32 ,$mShop_use_1)
  36.     self.contents.font.color = normal_color
  37.     self.contents.draw_text(0, 0, 240-contents.text_size($mShop_use_2).width-6, 32, $mShop_gold.to_s, 2)
  38.     self.contents.font.color = system_color
  39.     self.contents.draw_text(0, 0, 240, 32, $mShop_use_2, 2)
  40.   end
  41. end
  42. #==============================================================================
  43. # ■ Scene_MShop
  44. #------------------------------------------------------------------------------
  45. #  处理特技商店画面的类。
  46. #==============================================================================
  47. class Scene_MShop
  48.   #--------------------------------------------------------------------------
  49.   # ● 初始化
  50.   #--------------------------------------------------------------------------
  51.   def initialize(id)
  52.     @id = id
  53.   end  
  54.   #--------------------------------------------------------------------------
  55.   # ● 主处理
  56.   #--------------------------------------------------------------------------
  57.   def main
  58.     screen = Spriteset_Map.new
  59.     $game_variables[9] = $game_party.armor_number(951)
  60.     $game_party.remove_actor(997)#主角离开队伍
  61.     if $mShop_use_variable == 0
  62.       $mShop_gold = $game_party.gold
  63.     else
  64.       $mShop_gold = $game_variables[$mShop_use_variable]
  65.     end
  66.     # 生成帮助窗口
  67.     @help_window = Window_Help.new
  68.     @help_window.opacity = $mShop_Window_Opacity
  69.     # 生成金钱窗口
  70.     @gold_window = Window_MGold.new
  71.     @gold_window.x = 368
  72.     @gold_window.y = 416
  73.     @gold_window.opacity = $mShop_Window_Opacity
  74.     # 生成购买窗口
  75.     @buy_window = Window_MShopBuy.new(@id)
  76.     @buy_window.active = true
  77.     @buy_window.visible = true
  78.     @buy_window.help_window = @help_window
  79.     @buy_window.opacity = $mShop_Window_Opacity
  80.     # 生成状态窗口
  81.     @status_window = Window_MShopStatus.new
  82.     @status_window.visible = true
  83.     @status_window.active = false
  84.     @status_window.opacity = $mShop_Window_Opacity
  85.     # 执行过渡
  86.     Graphics.transition
  87.     # 主循环
  88.     loop do
  89.       # 刷新游戏画面
  90.       Graphics.update
  91.       # 刷新输入信息
  92.       Input.update
  93.       # 刷新画面
  94.       update
  95.       # 如果画面切换的话就中断循环
  96.       if $scene != self
  97.         break
  98.       end
  99.     end
  100.     # 准备过渡
  101.     Graphics.freeze
  102.     # 释放窗口
  103.     @help_window.dispose
  104.     #@mhelp_window.dispose
  105.     @gold_window.dispose
  106.     @buy_window.dispose
  107.     @status_window.dispose
  108.     screen.dispose
  109.   end
  110.   #--------------------------------------------------------------------------
  111.   # ● 刷新画面
  112.   #--------------------------------------------------------------------------
  113.   def update
  114.     # 刷新窗口
  115.     @help_window.update
  116.     #@mhelp_window.update
  117.     @gold_window.update
  118.     @buy_window.update
  119.     @status_window.update
  120.     # 购买窗口激活的情况下: 调用 update_buy
  121.     if @buy_window.active
  122.       update_buy
  123.       return
  124.     end
  125.     if @status_window.active
  126.       update_status
  127.       return
  128.     end
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   # ● 刷新画面 (购买窗口激活的情况下)
  132.   #--------------------------------------------------------------------------
  133.   def update_buy
  134.     @status_window.skill = @buy_window.skill
  135.     if Input.trigger?(Input::B)
  136.       $game_system.se_play($data_system.cancel_se)
  137.       $game_variables[25] = $game_party.armor_number(951)
  138.       $game_variables[24] = $game_variables[25] - $game_variables[9]
  139.       $game_party.gain_armor(951,-$game_variables[24])
  140.       $game_party.add_actor(997)#主角加入队伍
  141.       $scene = Scene_Map.new
  142.       return
  143.     end
  144.     if Input.trigger?(Input::C)
  145.       @skill = @buy_window.skill
  146.       if @skill == nil or @skill.price > $mShop_gold
  147.         $game_system.se_play($data_system.buzzer_se)
  148.         return
  149.       end
  150.       $game_system.se_play($data_system.decision_se)
  151.       @buy_window.active = false
  152.       @status_window.index = 0
  153.       @status_window.active = true
  154.     end
  155.   end
  156.   #--------------------------------------------------------------------------
  157.   # ● 刷新画面 (状态窗口激活的情况下)
  158.   #--------------------------------------------------------------------------
  159.   def update_status
  160.     if Input.trigger?(Input::B)
  161.       $game_system.se_play($data_system.cancel_se)
  162.       @status_window.active = false
  163.       @status_window.index = -1
  164.       @buy_window.active = true
  165.     end
  166.     actor = $game_party.actors[@status_window.index]
  167.     if Input.trigger?(Input::C)
  168.       can_learn=false
  169.       for j in $data_classes[actor.class_id].learnings
  170.         if j.skill_id == @skill.id
  171.           can_learn=true
  172.         end
  173.       end

  174.       unless $class_canlearn_list[actor.class_id].nil?
  175.         can_learn = true if $class_canlearn_list[actor.class_id].include?(@skill.id)
  176.       end

  177.       if can_learn==false
  178.         $game_system.se_play($data_system.cancel_se)
  179.         return
  180.       end
  181.       if $game_party.actors[@status_window.index].skill_learn?(@skill.id)
  182.         $game_system.se_play($data_system.cancel_se)
  183.         return
  184.       else
  185.         $game_system.se_play($data_system.decision_se)
  186.         if $mShop_use_variable == 0
  187.           $game_party.gain_gold([email]-@skill.price[/email])
  188.           $mShop_gold -= @skill.price
  189.         else
  190.           $game_variables[$mShop_use_variable] -= @skill.price
  191.           $mShop_gold -= @skill.price
  192.         end
  193.         $game_party.actors[@status_window.index].learn_skill(@skill.id)
  194.         @gold_window.refresh
  195.         @buy_window.refresh
  196.         @status_window.refresh
  197.         @status_window.active = false
  198.         @status_window.index = -1
  199.         @buy_window.active = true
  200.       end      
  201.     end   
  202.   end
  203. end
  204. #==============================================================================
  205. # ■ Window_MShopStatus
  206. #------------------------------------------------------------------------------
  207. #  特技商店画面、显示物品所持数与角色装备的窗口。
  208. #==============================================================================
  209. class Window_MShopStatus < Window_Selectable
  210.   #--------------------------------------------------------------------------
  211.   # ● 初始化对像
  212.   #--------------------------------------------------------------------------
  213.   def initialize
  214.     super(368, 64, 272, 352)
  215.     self.contents = Bitmap.new(width - 32, height - 32)
  216.     self.contents.font.size = 18
  217.     @skill = nil
  218.     refresh
  219.   end
  220.   #--------------------------------------------------------------------------
  221.   # ● 刷新
  222.   #--------------------------------------------------------------------------
  223.   def refresh
  224.     self.contents.clear
  225.     for i in 0...$game_party.actors.size
  226.       actor = $game_party.actors[i]
  227. #      draw_actor_graphic(actor,12,80*i+64)
  228.       self.contents.font.color = system_color
  229.       self.contents.draw_text(44, 80*i, 240, 32, actor.name)
  230.       self.contents.draw_text(0, 80*i , 240-20,32,"等级",2)
  231.       self.contents.font.color = normal_color
  232.       self.contents.draw_text(0, 80*i, 240, 32, actor.level.to_s , 2)
  233.       self.contents.font.color = system_color
  234.       self.contents.draw_text(44, 80*i+22, 45, 32, $data_system.words.hp)
  235.       self.contents.font.color = normal_color
  236.       self.contents.draw_text(44, 80*i+22, 90, 32, actor.maxhp.to_s,2)
  237.       self.contents.font.color = system_color
  238.       self.contents.draw_text(150, 80*i+22, 45, 32, $data_system.words.sp)
  239.       self.contents.font.color = normal_color
  240.       self.contents.draw_text(150, 80*i+22, 90, 32, actor.maxsp.to_s,2)   
  241.       can_learn=false
  242.       for j in $data_classes[actor.class_id].learnings
  243.         if j.skill_id == @skill.id
  244.           can_learn=true
  245.         end
  246.       end
  247.       unless $class_canlearn_list[actor.class_id].nil?
  248.         can_learn = true if $class_canlearn_list[actor.class_id].include?(@skill.id)
  249.       end

  250.       if can_learn == true
  251.         if actor.skill_learn?(@skill.id)
  252.           self.contents.font.color = Color.new(255,255,255,128)
  253.           self.contents.draw_text(44, 80*i+44, 196, 32, "已经学会改技能 ",2)        
  254.         else
  255.           self.contents.font.color = Color.new(255,255,0,255)
  256.           self.contents.draw_text(44, 80*i+44, 196, 32, "可以学会该技能 ",2)
  257.         end
  258.       else
  259.         self.contents.font.color = Color.new(255,255,255,128)
  260.         self.contents.draw_text(44, 80*i+44, 196, 32, "不适合学该技能 ",2)        
  261.       end
  262.     end
  263.     @item_max = $game_party.actors.size
  264.   end
  265.   #--------------------------------------------------------------------------
  266.   # ● 设置物品
  267.   #     item : 新的物品
  268.   #--------------------------------------------------------------------------
  269.   def skill=(skill)
  270.     if @skill != skill
  271.       @skill = skill
  272.       refresh
  273.     end
  274.   end
  275.   #--------------------------------------------------------------------------
  276.   # ● 刷新光标矩形
  277.   #--------------------------------------------------------------------------
  278.   def update_cursor_rect
  279.     if @index < 0
  280.       self.cursor_rect.empty
  281.     else
  282.       self.cursor_rect.set(0, @index * 80, self.width - 32, 80)
  283.     end
  284.   end
  285. end
  286. #==============================================================================
  287. # ■ Window_MShopBuy
  288. #------------------------------------------------------------------------------
  289. #  特技商店画面、浏览显示可以购买的商品的窗口。
  290. #==============================================================================
  291. class Window_MShopBuy < Window_Selectable
  292.   #--------------------------------------------------------------------------
  293.   # ● 初始化对像
  294.   #     shop_goods : 商品
  295.   #--------------------------------------------------------------------------
  296.   def initialize(id)
  297.     super(0, 64, 368, 416)
  298.     @id = id
  299.     refresh
  300.     self.index = 0
  301.   end
  302.   #--------------------------------------------------------------------------
  303.   # ● 获取物品
  304.   #--------------------------------------------------------------------------
  305.   def skill
  306.     return @data[self.index]
  307.   end
  308.   #--------------------------------------------------------------------------
  309.   # ● 刷新
  310.   #--------------------------------------------------------------------------
  311.   def refresh
  312.     if self.contents != nil
  313.       self.contents.dispose
  314.       self.contents = nil
  315.     end
  316.     @data = []
  317.     for skill_id in @id
  318.       skill = $data_skills[skill_id]
  319.       if skill != nil
  320.         @data.push(skill)
  321.       end
  322.     end
  323.     @item_max = @data.size
  324.     if @item_max > 0
  325.       self.contents = Bitmap.new(width - 32, row_max * 32)
  326.       for i in 0...@item_max
  327.         draw_item(i)
  328.       end
  329.     end
  330.   end
  331.   #--------------------------------------------------------------------------
  332.   # ● 描绘羡慕
  333.   #     index : 项目编号
  334.   #--------------------------------------------------------------------------
  335.   def draw_item(index)
  336.     skill = @data[index]
  337.     # 除此之外的情况设置为无效文字色
  338.     if skill.price <= $mShop_gold
  339.       self.contents.font.color = normal_color
  340.     else
  341.       self.contents.font.color = disabled_color
  342.     end
  343.     x = 4
  344.     y = index * 32
  345.     rect = Rect.new(x, y, self.width - 32, 32)
  346.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  347.     bitmap = RPG::Cache.icon(skill.icon_name)
  348.     opacity = self.contents.font.color == normal_color ? 255 : 128
  349.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  350.     self.contents.draw_text(x + 28, y, 212, 32, skill.name, 0)
  351.     self.contents.draw_text(x + 240, y, 88, 32, skill.price.to_s, 2)
  352.   end
  353.   #--------------------------------------------------------------------------
  354.   # ● 刷新帮助文本
  355.   #--------------------------------------------------------------------------
  356.   def update_help
  357.     @help_window.set_text(self.skill == nil ? "" : self.skill.description)
  358.   end
  359. end
  360. #==============================================================================
  361. # ■ RPG原装定义
  362. #==============================================================================
  363. module RPG
  364.   class Skill
  365.     def description
  366.       description = @description.split(/@/)[0]
  367.       return description != nil ? description : ''
  368.     end
  369.     def price
  370.       price = @description.split(/@/)[1]
  371.       return price != nil ? price.to_i : 0
  372.     end
  373.   end
  374. end
复制代码

评分

参与人数 2星屑 +135 收起 理由
RyanBern + 100 精品文章
myownroc + 35 手动认可

查看全部评分

梦石
0
星屑
80
在线时间
216 小时
注册时间
2011-9-17
回帖
125
 楼主| 发表于 2015-11-30 19:30:17 | 显示全部楼层
另外还有一个bug,如果角色已经学会了此商店出售的技能。
还可以在这个商店里继续学习~
这个bug也希望大大能修复!

点评

这个bug是我诊断错误。  发表于 2015-11-30 23:35
回复

使用道具 举报

梦石
0
星屑
80
在线时间
216 小时
注册时间
2011-9-17
回帖
125
 楼主| 发表于 2015-12-1 00:21:14 | 显示全部楼层
我自己把帖子里第二个问题解决了。楼顶的脚本也更新了
还要解决第一个问题,真心希望大大帮忙
还发现了一个bug,如果主角没钱,变量也为0,那还是可以学习技能
还有学习和遗忘的效果我也想尝试。

点评

又误诊bug了-。-~  发表于 2015-12-1 01:10
回复

使用道具 举报

梦石
0
星屑
80
在线时间
216 小时
注册时间
2011-9-17
回帖
125
 楼主| 发表于 2015-12-1 18:42:30 | 显示全部楼层
虽然没有大大帮忙修改这个脚本,但楼主自己把这两个效果修改成功啦。
已经更新了顶楼的脚本,有同样需要的朋友可以拿去用哦。
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部