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

Project1

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

[已经解决] 请教关于背包容量脚本的一个缺陷问题。

[复制链接]

Lv1.梦旅人

梦石
0
星屑
52
在线时间
509 小时
注册时间
2012-6-18
帖子
535

短篇七萝莉正太组亚军

跳转到指定楼层
1
 楼主| 发表于 2013-3-2 14:05:42 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 小强无敌 于 2013-3-3 09:06 编辑

最近在论坛上找到了一个修改背包容量的脚本,用了一会就发现有问题。
就是原本脚本的设计是如果背包内的物品种类超过背包的容量,人物在地图上就会走的很慢并且提示背包容量已满,只能打开背包丢弃一些没用的东西,才能恢复正常行走。
但是我尝试当超过背包容量时,把一些物品到商店卖掉,退出商店虽然提示背包已满的窗口没了,物品也没有超过背包的容量,但是行走速度却没有恢复,还是和背包满了时行走速度一样。 想要恢复必须打开菜单的物品栏一下,然后退出来才能恢复。
要是这样岂不是太不别扭了。我自本身就是个脚本盲,捣鼓了半天也没弄好。 只好求助论坛的各位大大。

脚本:
RUBY 代码复制
  1. #==============================================================================
  2. # ■ 背包系统 —— by 水镜风生
  3. #------------------------------------------------------------------------------
  4. LOSE_ITEM_SE_NAME = "Evasion"         # 丢弃物品时播放的SE
  5. LOW_SPEED = 1                         # 背包塞满时的移动速度
  6. USUAL_SPEED = 4                       # 平时的移动速度
  7. WARING_STRING = "背包里东西太多了!"  # 超重时的提示
  8. IM = 41                                # IM号系统变量决定物品种类的最大值
  9. #==============================================================================
  10. # ■ Scene_Item
  11. #------------------------------------------------------------------------------
  12. #  处理物品画面的类。
  13. #==============================================================================
  14. class Scene_Item < Scene_Base
  15.   #--------------------------------------------------------------------------
  16.   # ● 开始处理
  17.   #--------------------------------------------------------------------------
  18.   def start
  19.     super
  20.     create_menu_background
  21.     @viewport = Viewport.new(0, 0, 544, 416)
  22.     @help_window = Window_Help.new
  23.     @help_window.viewport = @viewport
  24.     @item_window = Window_Item.new(0, 67, 544, 280)
  25.     @item_window.viewport = @viewport
  26.     @item_window.help_window = @help_window
  27.     @item_window.active = false
  28.     @target_window = Window_MenuStatus.new(0, 0)
  29.     @max_window = Window_Item_Max.new
  30.     @max_window.viewport = @viewport
  31.     @number_window = Window_LoseNumber.new(142, 156)
  32.     @number_window.viewport = @viewport
  33.     @command_window = Window_Command.new(145, ["   使用","   丢弃"], 1, 2)
  34.     @command_window.x = 200
  35.     @command_window.y = 160
  36.     hide_command_window
  37.     hide_number_window
  38.     hide_target_window
  39.   end
  40.   #--------------------------------------------------------------------------
  41.   # ● 结束处理
  42.   #--------------------------------------------------------------------------
  43.   alias terminate2 terminate
  44.   def terminate
  45.     terminate2
  46.     @max_window.dispose
  47.     @command_window.dispose
  48.     @number_window.dispose
  49.   end
  50.   #--------------------------------------------------------------------------
  51.   # ● 回到原画面
  52.   #--------------------------------------------------------------------------
  53.   def return_scene
  54.     $scene = Scene_Menu.new(0)
  55.   end
  56.   #--------------------------------------------------------------------------
  57.   # ● 更新画面
  58.   #--------------------------------------------------------------------------
  59.   def update
  60.     super
  61.     update_menu_background
  62.     @help_window.update
  63.     @item_window.update
  64.     @target_window.update
  65.     @max_window.update
  66.     @command_window.update
  67.     @number_window.update
  68.     if @item_window.active
  69.       update_item_selection
  70.     elsif @target_window.active
  71.       update_target_selection
  72.     elsif @command_window.active
  73.       update_command_selection
  74.     elsif @number_window.active
  75.       update_number_selection
  76.     end
  77.   end
  78.   #--------------------------------------------------------------------------
  79.   # ● 更新物品选择
  80.   #--------------------------------------------------------------------------
  81.   def update_item_selection
  82.     if Input.trigger?(Input::B)
  83.       if  $game_party.items.size <= $game_variables[IM]# 如果物品种类没超过限制
  84.         $game_player.change_move_speed(USUAL_SPEED)
  85.       end
  86.         Sound.play_cancel
  87.         return_scene
  88.     elsif Input.trigger?(Input::C)
  89.       @item = @item_window.item
  90.       if @item != nil
  91.         $game_party.last_item_id = @item.id
  92.         Sound.play_decision
  93.           if $game_party.item_can_use?(@item)     # 物品是否可用
  94.             @command_window.draw_item(0,true)      
  95.           else  @command_window.draw_item(0,false) # 不可用的话【使用】选项颜色无效
  96.           end
  97.           if @item.price == 0                     # 物品价格是否为0   
  98.              @command_window.draw_item(1,false)    # 是的话【丢弃】选项无效
  99.           else  
  100.              @command_window.draw_item(1,true)
  101.           end
  102.              show_command_window
  103.        else
  104.          Sound.play_buzzer
  105.        end
  106.     end
  107.   end
  108.   #--------------------------------------------------------------------------
  109.   # ● 更新目标选择
  110.   #--------------------------------------------------------------------------
  111.   def update_target_selection
  112.     if Input.trigger?(Input::B)
  113.       Sound.play_cancel
  114.       if $game_party.item_number(@item) == 0    # 判断物品是否耗尽
  115.         @item_window.refresh                    # 刷新窗口内容      
  116.         @max_window.refresh                     # 刷新物品种类窗口
  117.       end
  118.       hide_target_window
  119.     elsif Input.trigger?(Input::C)
  120.       if not $game_party.item_can_use?(@item)
  121.         Sound.play_buzzer
  122.       else
  123.         determine_target
  124.       end
  125.     end
  126.   end
  127.   #--------------------------------------------------------------------------
  128.   # ★ 更新指令选择
  129.   #--------------------------------------------------------------------------
  130.   def update_command_selection
  131.     if Input.trigger?(Input::B)
  132.       Sound.play_cancel
  133.       hide_command_window
  134.     elsif Input.trigger?(Input::C)
  135.       if @command_window.index == 0
  136.         if $game_party.item_can_use?(@item)
  137.           Sound.play_decision
  138.           @command_window.active = false
  139.           @command_window.visible =false
  140.           determine_item
  141.         else
  142.           Sound.play_buzzer
  143.         end
  144.       elsif  @item == nil or @item.price == 0
  145.         Sound.play_buzzer
  146.       else
  147.         Sound.play_decision
  148.         @command_window.active = false
  149.         @command_window.visible =false        
  150.         max = $game_party.item_number(@item)
  151.         @number_window.set(@item, max)
  152.         show_number_window
  153.       end
  154.     end
  155.   end
  156.   #--------------------------------------------------------------------------
  157.   # ★ 更新数量输入
  158.   #--------------------------------------------------------------------------
  159.   def update_number_selection   
  160.     if Input.trigger?(Input::B)
  161.       Sound.play_cancel
  162.       hide_number_window
  163.     elsif Input.trigger?(Input::C)
  164.       Audio.se_play("Audio/SE/#{LOSE_ITEM_SE_NAME}", 80, 100)
  165.       $game_party.lose_item(@item, @number_window.number)
  166.       @item_window.refresh
  167.       @max_window.refresh  
  168.       hide_number_window
  169.     end  
  170.   end
  171.   #--------------------------------------------------------------------------
  172.   # ★ 显示指令选择窗口
  173.   #--------------------------------------------------------------------------
  174.   def show_command_window
  175.     @command_window.index = 0
  176.     @item_window.active = false
  177.     @command_window.visible = true
  178.     @command_window.active = true
  179.   end
  180.   #--------------------------------------------------------------------------
  181.   # ★ 显示数量窗口
  182.   #--------------------------------------------------------------------------
  183.   def show_number_window
  184.     @command_window.active = false
  185.     @number_window.visible = true
  186.     @number_window.active = true
  187.   end
  188.   #--------------------------------------------------------------------------
  189.   # ★ 隐藏指令选择窗口
  190.   #--------------------------------------------------------------------------
  191.   def hide_command_window
  192.     @item_window.active = true
  193.     @command_window.visible = false
  194.     @command_window.active = false
  195.     @viewport.rect.set(0, 0, 544, 416)
  196.     @viewport.ox = 0
  197.   end
  198.   #--------------------------------------------------------------------------
  199.   # ★ 隐藏数量窗口
  200.   #--------------------------------------------------------------------------
  201.   def hide_number_window
  202.     @item_window.active = true
  203.     @number_window.visible = false
  204.     @number_window.active = false
  205.     @viewport.rect.set(0, 0, 544, 416)
  206.     @viewport.ox = 0
  207.   end  
  208. end
  209. #==============================================================================
  210. # ■ Window_lost_item  
  211. #------------------------------------------------------------------------------
  212. #  显示物品丢弃数量的窗口,仿 Window_ShopNumber。
  213. #==============================================================================
  214. class Window_LoseNumber < Window_Base
  215.   #--------------------------------------------------------------------------
  216.   # ★ 初始化对像
  217.   #     x      : 窗口 X 座标
  218.   #     y      : 窗口 Y 座标
  219.   #--------------------------------------------------------------------------
  220.   def initialize(x, y)
  221.     super(x, y, 260, 104)
  222.     @item = nil
  223.     [url=home.php?mod=space&uid=25307]@Max[/url] = 1
  224.     [url=home.php?mod=space&uid=27178]@Number[/url] = 1
  225.   end
  226.   #--------------------------------------------------------------------------
  227.   # ★ 设置物品、最大数量
  228.   #--------------------------------------------------------------------------
  229.   def set(item, max)
  230.     @item = item
  231.     [url=home.php?mod=space&uid=25307]@Max[/url] = max
  232.     [url=home.php?mod=space&uid=27178]@Number[/url] = 1
  233.     refresh
  234.   end
  235.   #--------------------------------------------------------------------------
  236.   # ★ 设置数量输入
  237.   #--------------------------------------------------------------------------
  238.   def number
  239.     return @number
  240.   end
  241.   #--------------------------------------------------------------------------
  242.   # ★ 刷新
  243.   #--------------------------------------------------------------------------
  244.   def refresh
  245.     y = 24
  246.     self.contents.clear
  247.     draw_item_name(@item, 0, y)
  248.     self.contents.font.color = normal_color
  249.     self.contents.draw_text(164, y, 20, WLH, "×")
  250.     self.contents.draw_text(190, y, 20, WLH, @number, 2)
  251.     self.cursor_rect.set(186, y, 28, WLH)
  252.   end
  253.   #--------------------------------------------------------------------------
  254.   # ★ 更新画面
  255.   #--------------------------------------------------------------------------
  256.   def update
  257.     super
  258.     if self.active
  259.       last_number = @number
  260.       if Input.repeat?(Input::RIGHT) and @number < @max
  261.         @number += 1
  262.       end
  263.       if Input.repeat?(Input::LEFT) and @number > 1
  264.         @number -= 1
  265.       end
  266.       if Input.repeat?(Input::UP) and @number < @max
  267.         @number = [@number + 10, @max].min
  268.       end
  269.       if Input.repeat?(Input::DOWN) and @number > 1
  270.         @number = [@number - 10, 1].max
  271.       end
  272.       if @number != last_number
  273.         Sound.play_cursor
  274.         refresh
  275.       end
  276.     end
  277.   end
  278. end
  279. #==============================================================================
  280. # ■ Window_Item_Max
  281. #-----------------------------------------------------------------------------
  282. #   显示背包容量和当前物品数的窗口
  283. #============================================================================
  284.  
  285. class Window_Item_Max < Window_Base
  286.   #--------------------------------------------------------------------------
  287.   # ★ 初始化对像
  288.   #--------------------------------------------------------------------------
  289.   def initialize
  290.     super(290, 360, 254, 56)
  291.     refresh
  292.   end
  293.  
  294.   #--------------------------------------------------------------------------
  295.   # ★ 刷新
  296.   #--------------------------------------------------------------------------  
  297.   def refresh
  298.     self.contents.clear
  299.     draw_icon(144, 0, 0)
  300.     self.contents.draw_text(36, 0, 100, 24, "背包容量:")
  301.     item = $game_party.items
  302.     string = item.size.to_s
  303.     self.contents.font.color = knockout_color if item.size > $game_variables[IM]
  304.     self.contents.draw_text(135, 0, 30, 24, string, 2)
  305.     self.contents.font.color = normal_color
  306.     string = "/ " + $game_variables[IM].to_s
  307.     self.contents.draw_text(173, 0, 100, 24, string )
  308.   end
  309. end
  310. #==============================================================================
  311. # ■ Window_Waring
  312. #-----------------------------------------------------------------------------
  313. #   显示超重警告的窗口
  314. #============================================================================
  315. class Window_Waring  < Window_Base
  316.   def initialize
  317.     width = WARING_STRING.size * 8
  318.     super(544 - width, 416 - 56, width, 56)
  319.     refresh
  320.   end
  321.  
  322.   def refresh
  323.     self.contents.clear
  324.     self.contents.draw_text(0, -4, width - 32, 32, WARING_STRING)
  325.   end
  326. end
  327. #==============================================================================
  328. # Game_Player 添加更改移动速度的方法
  329. #============================================================================
  330. class Game_Player   
  331.   def change_move_speed(n)
  332.     @move_speed = n
  333.   end
  334. end
  335. #==============================================================================
  336. # Scene_Map  添加在地图上显示警告窗口的处理
  337. #============================================================================
  338. class Scene_Map
  339.   #--------------------------------------------------------------------------
  340.   # ● 开始处理
  341.   #--------------------------------------------------------------------------
  342.   alias start2 start
  343.   def start
  344.     start2
  345.     @waring_window = Window_Waring.new
  346.     @waring_window.visible = false
  347.   end  
  348.   #--------------------------------------------------------------------------
  349.   # ● 结束处理
  350.   #--------------------------------------------------------------------------
  351.   alias terminate2 terminate
  352.   def terminate
  353.     @waring_window.dispose
  354.     terminate2
  355.   end
  356.   #--------------------------------------------------------------------------
  357.   # ● フレーム更新
  358.   #--------------------------------------------------------------------------
  359.   alias update2 update
  360.   def update
  361.     update2
  362.     update_over_item
  363.   end
  364.  
  365.   #--------------------------------------------------------------------------
  366.   # ● 更新物品超限判定
  367.   #--------------------------------------------------------------------------  
  368.   def update_over_item
  369.     if $game_party.items.size > $game_variables[IM]
  370.       @waring_window.visible = true
  371.       $game_player.change_move_speed(LOW_SPEED)
  372.     else
  373.       @waring_window.visible = false
  374.     end
  375.   end
  376. end
  
找工作中。。。。。。
个人的最新画作:
照片头像写生,抖森一枚

Lv1.梦旅人

匿·蹤

梦石
0
星屑
65
在线时间
99 小时
注册时间
2006-3-19
帖子
456
来自 2楼
发表于 2013-3-2 22:53:19 | 只看该作者
需要注意:IM指定的是物品的种类

另外可以尝试在第373行上插入一行:
RUBY 代码复制
  1. $game_player.change_move_speed(USUAL_SPEED)

如此试试看是否解决了问题。
PS:再次提醒,IM指定的是物品的种类。

点评

捣鼓好了,是我放的地方不对了,谢谢喽  发表于 2013-3-3 09:12
不用不用,能帮助你,就是我最大的开心,希望看到你的作品辉煌问世,闪亮登场O(∩_∩)O~  发表于 2013-3-3 09:12
好的原来我看错了,已经捣鼓好了,十分感谢您的回答,经验不能再加了可恶。  发表于 2013-3-3 09:11
这里的类型,表示同ID物品。  发表于 2013-3-3 09:10
是的,IM表示你允许背包放置多少类型的物品,因为同类型物品是叠加的,O(∩_∩)O~  发表于 2013-3-3 09:08

评分

参与人数 2星屑 +10 梦石 +1 收起 理由
怪蜀黍 + 1 认可答案
小强无敌 + 10 谢谢回答

查看全部评分

卐忍 → 解忍 → 元忍 → 隐忍 → 卍忍 → 匿踪(最终)
完全退步到了卐忍阶段
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
52
在线时间
509 小时
注册时间
2012-6-18
帖子
535

短篇七萝莉正太组亚军

3
 楼主| 发表于 2013-3-3 09:01:39 | 只看该作者
OCTSJimmy 发表于 2013-3-2 22:53
需要注意:IM指定的是物品的种类

另外可以尝试在第373行上插入一行:

谢谢您提供的帮助。
加了那段,超重之后速度不改变了,还和没超重之前的速度一样了,我觉的是不是还得加上几句或者是那句放的位置不对啊。(脚本盲,看不太懂)

点评

是在第372行的else后面插入吗?  发表于 2013-3-3 09:11
是在372行的else后面插入吗?  发表于 2013-3-3 09:06
找工作中。。。。。。
个人的最新画作:
照片头像写生,抖森一枚
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-25 00:03

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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