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

Project1

 找回密码
 注册会员
搜索
查看: 1396|回复: 3
打印 上一主题 下一主题

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

[复制链接]

Lv1.梦旅人

梦石
0
星屑
80
在线时间
216 小时
注册时间
2011-9-17
帖子
151
跳转到指定楼层
1
发表于 2015-11-30 19:24:37 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

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

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

楼主自己解决这两个问题了,有同样需要的朋友可以拿去用哦。
脚本如下:
RUBY 代码复制
  1. #==============================================================================
  2. # ■ 本脚本源自[url]www.66rpg.com[/url],转载与使用请保留此信息
  3. #==============================================================================
  4.  
  5. #——以下是一些自定义的内容
  6. #呼出魔法商店$scene = Scene_MShop.new([1,2,3,4,5,6,7,8])
  7. #在技能说明末尾增加@100,则学习此技能需要扣掉9号变量100
  8.  
  9. $mShop_use_1 = "魔法水晶"    #——这项是购买魔法特技的货币的名称,如“灵魄”、“金钱”
  10.  
  11. $mShop_use_2 = "个"  #——这项是购买魔法特技的货币单位,如“点”、“¥”
  12.  
  13. $mShop_use_variable = 9  #——这项是购买魔法特技时消耗的变量编号,如果=0 则是消耗金钱
  14.  
  15. $mShop_Window_Opacity = 200  #——这项是窗口透明度
  16.  
  17. # 每个职业可以学的技能列表
  18. $class_canlearn_list = {  1 => [1,80],
  19.                           2 => [60,61],
  20.                           3 => []}
  21.  
  22. #==============================================================================
  23. # ■ Window_MGold
  24. #------------------------------------------------------------------------------
  25. #  显示金钱的窗口。
  26. #==============================================================================
  27. class Window_MGold < Window_Base
  28.   #--------------------------------------------------------------------------
  29.   # ● 初始化窗口
  30.   #--------------------------------------------------------------------------
  31.   def initialize
  32.     super(0, 0, 272, 64)
  33.     self.contents = Bitmap.new(width - 32, height - 32)
  34.     refresh
  35.   end
  36.   #--------------------------------------------------------------------------
  37.   # ● 刷新
  38.   #--------------------------------------------------------------------------
  39.   def refresh
  40.     self.contents.clear
  41.     self.contents.font.color = system_color
  42.     self.contents.draw_text(0, 0 , 240,32 ,$mShop_use_1)
  43.     self.contents.font.color = normal_color
  44.     self.contents.draw_text(0, 0, 240-contents.text_size($mShop_use_2).width-6, 32, $mShop_gold.to_s, 2)
  45.     self.contents.font.color = system_color
  46.     self.contents.draw_text(0, 0, 240, 32, $mShop_use_2, 2)
  47.   end
  48. end
  49. #==============================================================================
  50. # ■ Scene_MShop
  51. #------------------------------------------------------------------------------
  52. #  处理特技商店画面的类。
  53. #==============================================================================
  54. class Scene_MShop
  55.   #--------------------------------------------------------------------------
  56.   # ● 初始化
  57.   #--------------------------------------------------------------------------
  58.   def initialize(id)
  59.     @id = id
  60.   end  
  61.   #--------------------------------------------------------------------------
  62.   # ● 主处理
  63.   #--------------------------------------------------------------------------
  64.   def main
  65.     screen = Spriteset_Map.new
  66.     $game_variables[9] = $game_party.armor_number(951)
  67.     $game_party.remove_actor(997)#主角离开队伍
  68.     if $mShop_use_variable == 0
  69.       $mShop_gold = $game_party.gold
  70.     else
  71.       $mShop_gold = $game_variables[$mShop_use_variable]
  72.     end
  73.     # 生成帮助窗口
  74.     @help_window = Window_Help.new
  75.     @help_window.opacity = $mShop_Window_Opacity
  76.     # 生成金钱窗口
  77.     @gold_window = Window_MGold.new
  78.     @gold_window.x = 368
  79.     @gold_window.y = 416
  80.     @gold_window.opacity = $mShop_Window_Opacity
  81.     # 生成购买窗口
  82.     @buy_window = Window_MShopBuy.new(@id)
  83.     @buy_window.active = true
  84.     @buy_window.visible = true
  85.     @buy_window.help_window = @help_window
  86.     @buy_window.opacity = $mShop_Window_Opacity
  87.     # 生成状态窗口
  88.     @status_window = Window_MShopStatus.new
  89.     @status_window.visible = true
  90.     @status_window.active = false
  91.     @status_window.opacity = $mShop_Window_Opacity
  92.     # 执行过渡
  93.     Graphics.transition
  94.     # 主循环
  95.     loop do
  96.       # 刷新游戏画面
  97.       Graphics.update
  98.       # 刷新输入信息
  99.       Input.update
  100.       # 刷新画面
  101.       update
  102.       # 如果画面切换的话就中断循环
  103.       if $scene != self
  104.         break
  105.       end
  106.     end
  107.     # 准备过渡
  108.     Graphics.freeze
  109.     # 释放窗口
  110.     @help_window.dispose
  111.     #@mhelp_window.dispose
  112.     @gold_window.dispose
  113.     @buy_window.dispose
  114.     @status_window.dispose
  115.     screen.dispose
  116.   end
  117.   #--------------------------------------------------------------------------
  118.   # ● 刷新画面
  119.   #--------------------------------------------------------------------------
  120.   def update
  121.     # 刷新窗口
  122.     @help_window.update
  123.     #@mhelp_window.update
  124.     @gold_window.update
  125.     @buy_window.update
  126.     @status_window.update
  127.     # 购买窗口激活的情况下: 调用 update_buy
  128.     if @buy_window.active
  129.       update_buy
  130.       return
  131.     end
  132.     if @status_window.active
  133.       update_status
  134.       return
  135.     end
  136.   end
  137.   #--------------------------------------------------------------------------
  138.   # ● 刷新画面 (购买窗口激活的情况下)
  139.   #--------------------------------------------------------------------------
  140.   def update_buy
  141.     @status_window.skill = @buy_window.skill
  142.     if Input.trigger?(Input::B)
  143.       $game_system.se_play($data_system.cancel_se)
  144.       $game_variables[25] = $game_party.armor_number(951)
  145.       $game_variables[24] = $game_variables[25] - $game_variables[9]
  146.       $game_party.gain_armor(951,-$game_variables[24])
  147.       $game_party.add_actor(997)#主角加入队伍
  148.       $scene = Scene_Map.new
  149.       return
  150.     end
  151.     if Input.trigger?(Input::C)
  152.       @skill = @buy_window.skill
  153.       if @skill == nil or @skill.price > $mShop_gold
  154.         $game_system.se_play($data_system.buzzer_se)
  155.         return
  156.       end
  157.       $game_system.se_play($data_system.decision_se)
  158.       @buy_window.active = false
  159.       @status_window.index = 0
  160.       @status_window.active = true
  161.     end
  162.   end
  163.   #--------------------------------------------------------------------------
  164.   # ● 刷新画面 (状态窗口激活的情况下)
  165.   #--------------------------------------------------------------------------
  166.   def update_status
  167.     if Input.trigger?(Input::B)
  168.       $game_system.se_play($data_system.cancel_se)
  169.       @status_window.active = false
  170.       @status_window.index = -1
  171.       @buy_window.active = true
  172.     end
  173.     actor = $game_party.actors[@status_window.index]
  174.     if Input.trigger?(Input::C)
  175.       can_learn=false
  176.       for j in $data_classes[actor.class_id].learnings
  177.         if j.skill_id == @skill.id
  178.           can_learn=true
  179.         end
  180.       end
  181.  
  182.       unless $class_canlearn_list[actor.class_id].nil?
  183.         can_learn = true if $class_canlearn_list[actor.class_id].include?(@skill.id)
  184.       end
  185.  
  186.       if can_learn==false
  187.         $game_system.se_play($data_system.cancel_se)
  188.         return
  189.       end
  190.       if $game_party.actors[@status_window.index].skill_learn?(@skill.id)
  191.         $game_system.se_play($data_system.cancel_se)
  192.         return
  193.       else
  194.         $game_system.se_play($data_system.decision_se)
  195.         if $mShop_use_variable == 0
  196.           $game_party.gain_gold([email]-@skill.price[/email])
  197.           $mShop_gold -= @skill.price
  198.         else
  199.           $game_variables[$mShop_use_variable] -= @skill.price
  200.           $mShop_gold -= @skill.price
  201.         end
  202.         $game_party.actors[@status_window.index].learn_skill(@skill.id)
  203.         @gold_window.refresh
  204.         @buy_window.refresh
  205.         @status_window.refresh
  206.         @status_window.active = false
  207.         @status_window.index = -1
  208.         @buy_window.active = true
  209.       end      
  210.     end   
  211.   end
  212. end
  213. #==============================================================================
  214. # ■ Window_MShopStatus
  215. #------------------------------------------------------------------------------
  216. #  特技商店画面、显示物品所持数与角色装备的窗口。
  217. #==============================================================================
  218. class Window_MShopStatus < Window_Selectable
  219.   #--------------------------------------------------------------------------
  220.   # ● 初始化对像
  221.   #--------------------------------------------------------------------------
  222.   def initialize
  223.     super(368, 64, 272, 352)
  224.     self.contents = Bitmap.new(width - 32, height - 32)
  225.     self.contents.font.size = 18
  226.     @skill = nil
  227.     refresh
  228.   end
  229.   #--------------------------------------------------------------------------
  230.   # ● 刷新
  231.   #--------------------------------------------------------------------------
  232.   def refresh
  233.     self.contents.clear
  234.     for i in 0...$game_party.actors.size
  235.       actor = $game_party.actors[i]
  236. #      draw_actor_graphic(actor,12,80*i+64)
  237.       self.contents.font.color = system_color
  238.       self.contents.draw_text(44, 80*i, 240, 32, actor.name)
  239.       self.contents.draw_text(0, 80*i , 240-20,32,"等级",2)
  240.       self.contents.font.color = normal_color
  241.       self.contents.draw_text(0, 80*i, 240, 32, actor.level.to_s , 2)
  242.       self.contents.font.color = system_color
  243.       self.contents.draw_text(44, 80*i+22, 45, 32, $data_system.words.hp)
  244.       self.contents.font.color = normal_color
  245.       self.contents.draw_text(44, 80*i+22, 90, 32, actor.maxhp.to_s,2)
  246.       self.contents.font.color = system_color
  247.       self.contents.draw_text(150, 80*i+22, 45, 32, $data_system.words.sp)
  248.       self.contents.font.color = normal_color
  249.       self.contents.draw_text(150, 80*i+22, 90, 32, actor.maxsp.to_s,2)   
  250.       can_learn=false
  251.       for j in $data_classes[actor.class_id].learnings
  252.         if j.skill_id == @skill.id
  253.           can_learn=true
  254.         end
  255.       end
  256.       unless $class_canlearn_list[actor.class_id].nil?
  257.         can_learn = true if $class_canlearn_list[actor.class_id].include?(@skill.id)
  258.       end
  259.  
  260.       if can_learn == true
  261.         if actor.skill_learn?(@skill.id)
  262.           self.contents.font.color = Color.new(255,255,255,128)
  263.           self.contents.draw_text(44, 80*i+44, 196, 32, "已经学会改技能 ",2)        
  264.         else
  265.           self.contents.font.color = Color.new(255,255,0,255)
  266.           self.contents.draw_text(44, 80*i+44, 196, 32, "可以学会该技能 ",2)
  267.         end
  268.       else
  269.         self.contents.font.color = Color.new(255,255,255,128)
  270.         self.contents.draw_text(44, 80*i+44, 196, 32, "不适合学该技能 ",2)        
  271.       end
  272.     end
  273.     @item_max = $game_party.actors.size
  274.   end
  275.   #--------------------------------------------------------------------------
  276.   # ● 设置物品
  277.   #     item : 新的物品
  278.   #--------------------------------------------------------------------------
  279.   def skill=(skill)
  280.     if @skill != skill
  281.       @skill = skill
  282.       refresh
  283.     end
  284.   end
  285.   #--------------------------------------------------------------------------
  286.   # ● 刷新光标矩形
  287.   #--------------------------------------------------------------------------
  288.   def update_cursor_rect
  289.     if @index < 0
  290.       self.cursor_rect.empty
  291.     else
  292.       self.cursor_rect.set(0, @index * 80, self.width - 32, 80)
  293.     end
  294.   end
  295. end
  296. #==============================================================================
  297. # ■ Window_MShopBuy
  298. #------------------------------------------------------------------------------
  299. #  特技商店画面、浏览显示可以购买的商品的窗口。
  300. #==============================================================================
  301. class Window_MShopBuy < Window_Selectable
  302.   #--------------------------------------------------------------------------
  303.   # ● 初始化对像
  304.   #     shop_goods : 商品
  305.   #--------------------------------------------------------------------------
  306.   def initialize(id)
  307.     super(0, 64, 368, 416)
  308.     @id = id
  309.     refresh
  310.     self.index = 0
  311.   end
  312.   #--------------------------------------------------------------------------
  313.   # ● 获取物品
  314.   #--------------------------------------------------------------------------
  315.   def skill
  316.     return @data[self.index]
  317.   end
  318.   #--------------------------------------------------------------------------
  319.   # ● 刷新
  320.   #--------------------------------------------------------------------------
  321.   def refresh
  322.     if self.contents != nil
  323.       self.contents.dispose
  324.       self.contents = nil
  325.     end
  326.     @data = []
  327.     for skill_id in @id
  328.       skill = $data_skills[skill_id]
  329.       if skill != nil
  330.         @data.push(skill)
  331.       end
  332.     end
  333.     @item_max = @data.size
  334.     if @item_max > 0
  335.       self.contents = Bitmap.new(width - 32, row_max * 32)
  336.       for i in 0...@item_max
  337.         draw_item(i)
  338.       end
  339.     end
  340.   end
  341.   #--------------------------------------------------------------------------
  342.   # ● 描绘羡慕
  343.   #     index : 项目编号
  344.   #--------------------------------------------------------------------------
  345.   def draw_item(index)
  346.     skill = @data[index]
  347.     # 除此之外的情况设置为无效文字色
  348.     if skill.price <= $mShop_gold
  349.       self.contents.font.color = normal_color
  350.     else
  351.       self.contents.font.color = disabled_color
  352.     end
  353.     x = 4
  354.     y = index * 32
  355.     rect = Rect.new(x, y, self.width - 32, 32)
  356.     self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  357.     bitmap = RPG::Cache.icon(skill.icon_name)
  358.     opacity = self.contents.font.color == normal_color ? 255 : 128
  359.     self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  360.     self.contents.draw_text(x + 28, y, 212, 32, skill.name, 0)
  361.     self.contents.draw_text(x + 240, y, 88, 32, skill.price.to_s, 2)
  362.   end
  363.   #--------------------------------------------------------------------------
  364.   # ● 刷新帮助文本
  365.   #--------------------------------------------------------------------------
  366.   def update_help
  367.     @help_window.set_text(self.skill == nil ? "" : self.skill.description)
  368.   end
  369. end
  370. #==============================================================================
  371. # ■ RPG原装定义
  372. #==============================================================================
  373. module RPG
  374.   class Skill
  375.     def description
  376.       description = @description.split(/@/)[0]
  377.       return description != nil ? description : ''
  378.     end
  379.     def price
  380.       price = @description.split(/@/)[1]
  381.       return price != nil ? price.to_i : 0
  382.     end
  383.   end
  384. end

评分

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

查看全部评分

Lv1.梦旅人

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

点评

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

使用道具 举报

Lv1.梦旅人

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

点评

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

使用道具 举报

Lv1.梦旅人

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

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-9-22 21:17

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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