查看: 4378|回复: 2

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

[复制链接]
梦石
0
星屑
52
在线时间
509 小时
注册时间
2012-6-18
回帖
519

短篇七萝莉正太组亚军

发表于 2013-3-2 14:05:42 | 显示全部楼层 |阅读模式

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

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

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

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

脚本:[pre lang="ruby" line="1"]#==============================================================================
# ■ 背包系统 —— by 水镜风生
#------------------------------------------------------------------------------
LOSE_ITEM_SE_NAME = "Evasion"         # 丢弃物品时播放的SE
LOW_SPEED = 1                         # 背包塞满时的移动速度
USUAL_SPEED = 4                       # 平时的移动速度
WARING_STRING = "背包里东西太多了!"  # 超重时的提示
IM = 41                                # IM号系统变量决定物品种类的最大值
#==============================================================================
# ■ Scene_Item
#------------------------------------------------------------------------------
#  处理物品画面的类。
#==============================================================================
class Scene_Item < Scene_Base
  #--------------------------------------------------------------------------
  # ● 开始处理
  #--------------------------------------------------------------------------
  def start
    super
    create_menu_background
    @viewport = Viewport.new(0, 0, 544, 416)
    @help_window = Window_Help.new
    @help_window.viewport = @viewport
    @item_window = Window_Item.new(0, 67, 544, 280)
    @item_window.viewport = @viewport
    @item_window.help_window = @help_window
    @item_window.active = false
    @target_window = Window_MenuStatus.new(0, 0)
    @max_window = Window_Item_Max.new
    @max_window.viewport = @viewport
    @number_window = Window_LoseNumber.new(142, 156)
    @number_window.viewport = @viewport
    @command_window = Window_Command.new(145, ["   使用","   丢弃"], 1, 2)
    @command_window.x = 200
    @command_window.y = 160
    hide_command_window
    hide_number_window
    hide_target_window
  end
  #--------------------------------------------------------------------------
  # ● 结束处理
  #--------------------------------------------------------------------------
  alias terminate2 terminate
  def terminate
    terminate2
    @max_window.dispose
    @command_window.dispose
    @number_window.dispose
  end
  #--------------------------------------------------------------------------
  # ● 回到原画面
  #--------------------------------------------------------------------------
  def return_scene
    $scene = Scene_Menu.new(0)
  end
  #--------------------------------------------------------------------------
  # ● 更新画面
  #--------------------------------------------------------------------------
  def update
    super
    update_menu_background
    @help_window.update
    @item_window.update
    @target_window.update
    @max_window.update
    @command_window.update
    @number_window.update
    if @item_window.active
      update_item_selection
    elsif @target_window.active
      update_target_selection
    elsif @command_window.active
      update_command_selection
    elsif @number_window.active
      update_number_selection
    end
  end
  #--------------------------------------------------------------------------
  # ● 更新物品选择
  #--------------------------------------------------------------------------
  def update_item_selection
    if Input.trigger?(Input::B)
      if  $game_party.items.size <= $game_variables[IM]# 如果物品种类没超过限制
        $game_player.change_move_speed(USUAL_SPEED)
      end
        Sound.play_cancel
        return_scene
    elsif Input.trigger?(Input::C)
      @item = @item_window.item
      if @item != nil
        $game_party.last_item_id = @item.id
        Sound.play_decision
          if $game_party.item_can_use?(@item)     # 物品是否可用
            @command_window.draw_item(0,true)      
          else  @command_window.draw_item(0,false) # 不可用的话【使用】选项颜色无效
          end
          if @item.price == 0                     # 物品价格是否为0   
             @command_window.draw_item(1,false)    # 是的话【丢弃】选项无效
          else  
             @command_window.draw_item(1,true)
          end
             show_command_window
       else
         Sound.play_buzzer
       end
    end
  end
  #--------------------------------------------------------------------------
  # ● 更新目标选择
  #--------------------------------------------------------------------------
  def update_target_selection
    if Input.trigger?(Input::B)
      Sound.play_cancel
      if $game_party.item_number(@item) == 0    # 判断物品是否耗尽
        @item_window.refresh                    # 刷新窗口内容      
        @max_window.refresh                     # 刷新物品种类窗口
      end
      hide_target_window
    elsif Input.trigger?(Input::C)
      if not $game_party.item_can_use?(@item)
        Sound.play_buzzer
      else
        determine_target
      end
    end
  end
  #--------------------------------------------------------------------------
  # ★ 更新指令选择
  #--------------------------------------------------------------------------
  def update_command_selection
    if Input.trigger?(Input::B)
      Sound.play_cancel
      hide_command_window
    elsif Input.trigger?(Input::C)
      if @command_window.index == 0
        if $game_party.item_can_use?(@item)
          Sound.play_decision
          @command_window.active = false
          @command_window.visible =false
          determine_item
        else
          Sound.play_buzzer
        end
      elsif  @item == nil or @item.price == 0
        Sound.play_buzzer
      else
        Sound.play_decision
        @command_window.active = false
        @command_window.visible =false        
        max = $game_party.item_number(@item)
        @number_window.set(@item, max)
        show_number_window
      end
    end
  end
  #--------------------------------------------------------------------------
  # ★ 更新数量输入
  #--------------------------------------------------------------------------
  def update_number_selection   
    if Input.trigger?(Input::B)
      Sound.play_cancel
      hide_number_window
    elsif Input.trigger?(Input::C)
      Audio.se_play("Audio/SE/#{LOSE_ITEM_SE_NAME}", 80, 100)
      $game_party.lose_item(@item, @number_window.number)
      @item_window.refresh
      @max_window.refresh  
      hide_number_window
    end  
  end
  #--------------------------------------------------------------------------
  # ★ 显示指令选择窗口
  #--------------------------------------------------------------------------
  def show_command_window
    @command_window.index = 0
    @item_window.active = false
    @command_window.visible = true
    @command_window.active = true
  end
  #--------------------------------------------------------------------------
  # ★ 显示数量窗口
  #--------------------------------------------------------------------------
  def show_number_window
    @command_window.active = false
    @number_window.visible = true
    @number_window.active = true
  end
  #--------------------------------------------------------------------------
  # ★ 隐藏指令选择窗口
  #--------------------------------------------------------------------------
  def hide_command_window
    @item_window.active = true
    @command_window.visible = false
    @command_window.active = false
    @viewport.rect.set(0, 0, 544, 416)
    @viewport.ox = 0
  end
  #--------------------------------------------------------------------------
  # ★ 隐藏数量窗口
  #--------------------------------------------------------------------------
  def hide_number_window
    @item_window.active = true
    @number_window.visible = false
    @number_window.active = false
    @viewport.rect.set(0, 0, 544, 416)
    @viewport.ox = 0
  end  
end
#==============================================================================
# ■ Window_lost_item  
#------------------------------------------------------------------------------
#  显示物品丢弃数量的窗口,仿 Window_ShopNumber。
#==============================================================================
class Window_LoseNumber < Window_Base
  #--------------------------------------------------------------------------
  # ★ 初始化对像
  #     x      : 窗口 X 座标
  #     y      : 窗口 Y 座标
  #--------------------------------------------------------------------------
  def initialize(x, y)
    super(x, y, 260, 104)
    @item = nil
    @Max = 1
    @Number = 1
  end
  #--------------------------------------------------------------------------
  # ★ 设置物品、最大数量
  #--------------------------------------------------------------------------
  def set(item, max)
    @item = item
    @Max = max
    @Number = 1
    refresh
  end
  #--------------------------------------------------------------------------
  # ★ 设置数量输入
  #--------------------------------------------------------------------------
  def number
    return @number
  end
  #--------------------------------------------------------------------------
  # ★ 刷新
  #--------------------------------------------------------------------------
  def refresh
    y = 24
    self.contents.clear
    draw_item_name(@item, 0, y)
    self.contents.font.color = normal_color
    self.contents.draw_text(164, y, 20, WLH, "×")
    self.contents.draw_text(190, y, 20, WLH, @number, 2)
    self.cursor_rect.set(186, y, 28, WLH)
  end
  #--------------------------------------------------------------------------
  # ★ 更新画面
  #--------------------------------------------------------------------------
  def update
    super
    if self.active
      last_number = @number
      if Input.repeat?(Input::RIGHT) and @number < @max
        @number += 1
      end
      if Input.repeat?(Input::LEFT) and @number > 1
        @number -= 1
      end
      if Input.repeat?(Input::UP) and @number < @max
        @number = [@number + 10, @max].min
      end
      if Input.repeat?(Input::DOWN) and @number > 1
        @number = [@number - 10, 1].max
      end
      if @number != last_number
        Sound.play_cursor
        refresh
      end
    end
  end
end
#==============================================================================
# ■ Window_Item_Max
#-----------------------------------------------------------------------------
#   显示背包容量和当前物品数的窗口
#============================================================================

class Window_Item_Max < Window_Base
  #--------------------------------------------------------------------------
  # ★ 初始化对像
  #--------------------------------------------------------------------------
  def initialize
    super(290, 360, 254, 56)
    refresh
  end
  
  #--------------------------------------------------------------------------
  # ★ 刷新
  #--------------------------------------------------------------------------  
  def refresh
    self.contents.clear
    draw_icon(144, 0, 0)
    self.contents.draw_text(36, 0, 100, 24, "背包容量:")
    item = $game_party.items
    string = item.size.to_s
    self.contents.font.color = knockout_color if item.size > $game_variables[IM]
    self.contents.draw_text(135, 0, 30, 24, string, 2)
    self.contents.font.color = normal_color
    string = "/ " + $game_variables[IM].to_s
    self.contents.draw_text(173, 0, 100, 24, string )
  end
end
#==============================================================================
# ■ Window_Waring
#-----------------------------------------------------------------------------
#   显示超重警告的窗口
#============================================================================
class Window_Waring  < Window_Base
  def initialize
    width = WARING_STRING.size * 8
    super(544 - width, 416 - 56, width, 56)
    refresh
  end
  
  def refresh
    self.contents.clear
    self.contents.draw_text(0, -4, width - 32, 32, WARING_STRING)
  end
end
#==============================================================================
# Game_Player 添加更改移动速度的方法
#============================================================================
class Game_Player   
  def change_move_speed(n)
    @move_speed = n
  end
end
#==============================================================================
# Scene_Map  添加在地图上显示警告窗口的处理
#============================================================================
class Scene_Map
  #--------------------------------------------------------------------------
  # ● 开始处理
  #--------------------------------------------------------------------------
  alias start2 start
  def start
    start2
    @waring_window = Window_Waring.new
    @waring_window.visible = false
  end  
  #--------------------------------------------------------------------------
  # ● 结束处理
  #--------------------------------------------------------------------------
  alias terminate2 terminate
  def terminate
    @waring_window.dispose
    terminate2
  end
  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  alias update2 update
  def update
    update2
    update_over_item
  end

  #--------------------------------------------------------------------------
  # ● 更新物品超限判定
  #--------------------------------------------------------------------------  
  def update_over_item
    if $game_party.items.size > $game_variables[IM]
      @waring_window.visible = true
      $game_player.change_move_speed(LOW_SPEED)
    else
      @waring_window.visible = false
    end
  end
end[/pre]  
找工作中。。。。。。
个人的最新画作:
照片头像写生,抖森一枚

匿·蹤

梦石
0
星屑
65
在线时间
99 小时
注册时间
2006-3-19
回帖
404
发表于 2013-3-2 22:53:19 | 显示全部楼层
需要注意:IM指定的是物品的种类

另外可以尝试在第373行上插入一行:
[pre lang="ruby" line="1"]$game_player.change_move_speed(USUAL_SPEED)[/pre]
如此试试看是否解决了问题。
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 谢谢回答

查看全部评分

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

使用道具 举报

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

短篇七萝莉正太组亚军

 楼主| 发表于 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
找工作中。。。。。。
个人的最新画作:
照片头像写生,抖森一枚
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部