Project1

标题: 请问如何让物品可以自主丢弃? [打印本页]

作者: 爱羊真知己    时间: 2023-2-25 17:22
标题: 请问如何让物品可以自主丢弃?
本帖最后由 爱羊真知己 于 2023-5-21 15:52 编辑

是这样的,我希望可以让玩家在使用物品是弹出使用、丢弃、全部丢弃的弹窗。
当玩家点使用时,正常使用(不能使用的物品为灰色),丢弃就是像商店售卖一样选择数量丢弃,全部丢弃则是丢弃全部该物品。(有指定注释的物品不能丢弃)
我已经找到了类似的两个脚本(但第二个是VX的),综合两脚本的功能可以达到效果(保留脚本1除使用方式部分,脚本2的使用方式,弹窗及将物品全部丢弃功能,删去脚本1使用方式,脚本2物品种类数限制)
当然,如果已经有现成脚本(反正我没搜到)更好!
脚本1如下(第137行是加的,感谢@灯笼菜刀王 ):
RUBY 代码复制
  1. #==============================================================================
  2. # ■ VXAce-RGSS3-2 アイテム捨てる [Ver.1.0.0]         by Claimh
  3. #------------------------------------------------------------------------------
  4. #  アイテム画面上でXボタンを押すと、アイテムを捨てることができます。
  5. #==============================================================================
  6.  
  7.  
  8. #==============================================================================
  9. # ■ Window_ItemList
  10. #==============================================================================
  11. class Window_ItemList < Window_Selectable
  12.   #--------------------------------------------------------------------------
  13.   # ● 決定やキャンセルなどのハンドリング処理
  14.   #--------------------------------------------------------------------------
  15.   def process_handling
  16.     return unless open? && active
  17.     return call_handler(:append_x)   if handle?(:append_x) && Input.trigger?(:X)
  18.     super
  19.   end
  20. end
  21.  
  22. #==============================================================================
  23. # ■ Window_ItemNumber
  24. #==============================================================================
  25. class Window_ItemNumber < Window_ShopNumber
  26.   #--------------------------------------------------------------------------
  27.   # ● 公開インスタンス変数
  28.   #--------------------------------------------------------------------------
  29.   attr_reader   :number                   # 入力された個数
  30.   #--------------------------------------------------------------------------
  31.   # ● オブジェクト初期化
  32.   #--------------------------------------------------------------------------
  33.   def initialize
  34.     x = (Graphics.width - window_width) / 2
  35.     super(x, 200, line_height*2 + 32)
  36.     @item = nil
  37.     @max = 1
  38.     @number = 1
  39.   end
  40.   #--------------------------------------------------------------------------
  41.   # ● アイテム、最大個数の設定
  42.   #--------------------------------------------------------------------------
  43.   def set(item, max)
  44.     @item = item
  45.     @max = max
  46.     @number = 1
  47.     refresh
  48.   end
  49.   #--------------------------------------------------------------------------
  50.   # ● リフレッシュ
  51.   #--------------------------------------------------------------------------
  52.   def refresh
  53.     contents.clear
  54.     contents.draw_text(0, 0, 200, line_height, "捨てる数:")
  55.     draw_item_name(@item, 4, line_height)
  56.     draw_number
  57.   end
  58.   #--------------------------------------------------------------------------
  59.   # ● アイテム名表示行の Y 座標
  60.   #--------------------------------------------------------------------------
  61.   def item_y
  62.     line_height
  63.   end
  64. end
  65.  
  66.  
  67. #==============================================================================
  68. # ■ Scene_Item
  69. #==============================================================================
  70. class Scene_Item < Scene_ItemBase
  71.   #--------------------------------------------------------------------------
  72.   # ● 開始処理
  73.   #--------------------------------------------------------------------------
  74.   alias start_dump start
  75.   def start
  76.     start_dump
  77.     create_item_dump_window
  78.   end
  79.   #--------------------------------------------------------------------------
  80.   # ● アイテムウィンドウの作成
  81.   #--------------------------------------------------------------------------
  82.   alias create_item_window_dump create_item_window
  83.   def create_item_window
  84.     create_item_window_dump
  85.     @item_window.set_handler(:append_x, method(:on_item_dump))
  86.   end
  87.   #--------------------------------------------------------------------------
  88.   # ● アイテム数選択ウィンドウの作成
  89.   #--------------------------------------------------------------------------
  90.   def create_item_dump_window
  91.     @number_window = Window_ItemNumber.new
  92.     @number_window.viewport = @viewport
  93.     @number_window.hide
  94.     @number_window.set_handler(:ok,     method(:on_number_ok))
  95.     @number_window.set_handler(:cancel, method(:on_number_cancel))
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   # ● アイテム[捨てる]
  99.   #--------------------------------------------------------------------------
  100.   def on_item_dump
  101.     if item_dumpable?
  102.       Sound.play_ok
  103.       @number_window.set(item, max_item)
  104.       @number_window.show.activate
  105.       @item_window.deactivate
  106.     else
  107.       Sound.play_buzzer
  108.     end
  109.   end
  110.   #--------------------------------------------------------------------------
  111.   # ● 個数入力[決定]
  112.   #--------------------------------------------------------------------------
  113.   def on_number_ok
  114.     Sound.play_ok
  115.     do_item_dump(@number_window.number)
  116.     @number_window.hide
  117.     activate_item_window
  118.   end
  119.   #--------------------------------------------------------------------------
  120.   # ● 個数入力[キャンセル]
  121.   #--------------------------------------------------------------------------
  122.   def on_number_cancel
  123.     Sound.play_cancel
  124.     @number_window.hide
  125.     activate_item_window
  126.   end
  127.   #--------------------------------------------------------------------------
  128.   # ● 捨てるの実行
  129.   #--------------------------------------------------------------------------
  130.   def do_item_dump(number)
  131.     $game_party.lose_item(item, number)
  132.   end
  133.   #--------------------------------------------------------------------------
  134.   # ● アイテムを捨てる判定
  135.   #--------------------------------------------------------------------------
  136.   def item_dumpable?
  137.     return false if item.note.include?("【禁止丢弃】")
  138.     item.is_a?(RPG::Item) ? !item.key_item? : (!item.nil?)
  139.   end
  140.   #--------------------------------------------------------------------------
  141.   # ● 所持数の取得
  142.   #--------------------------------------------------------------------------
  143.   def max_item
  144.     $game_party.item_number(item)
  145.   end
  146. end

脚本2:
RUBY 代码复制
  1. #==============================================================================
  2. # ■ 物品丢弃 + 物品种类数限制 —— by 水镜风生
  3. #------------------------------------------------------------------------------
  4. LOSE_ITEM_SE_NAME = "Evasion" # 丢弃物品时播放的SE
  5. $item_max = 30 # 最大物品种数
  6. #==============================================================================
  7. # ■ Scene_Item
  8. #------------------------------------------------------------------------------
  9. #  处理物品画面的类。
  10. #==============================================================================
  11. class Scene_Item < Scene_Base
  12. #--------------------------------------------------------------------------
  13. # ● 开始处理
  14. #--------------------------------------------------------------------------
  15. def start
  16. super
  17. create_menu_background
  18. @viewport = Viewport.new(0, 0, 544, 416)
  19. @help_window = Window_Help.new
  20. @help_window.viewport = @viewport
  21. @item_window = Window_Item.new(0, 67, 544, 280)
  22. @item_window.viewport = @viewport
  23. @item_window.help_window = @help_window
  24. @item_window.active = false
  25. @target_window = Window_MenuStatus.new(0, 0)
  26. @max_window = Window_Item_Max.new
  27. @max_window.viewport = @viewport
  28. @number_window = Window_LoseNumber.new(142, 156)
  29. @number_window.viewport = @viewport
  30. @command_window = Window_Command.new(145, [" 使用"," 丢弃"], 1, 2)
  31. @command_window.x = 200
  32. @command_window.y = 160
  33. @over_window = Window_Help.new
  34. @over_window.set_text("背包放不下了,丢弃一些没用的物品吧。")
  35. @over_window.visible = false
  36. hide_command_window
  37. hide_number_window
  38. hide_target_window
  39. end
  40. #--------------------------------------------------------------------------
  41. # ● 结束处理
  42. #--------------------------------------------------------------------------
  43. def terminate
  44. super
  45. dispose_menu_background
  46. @viewport.dispose
  47. @help_window.dispose
  48. @item_window.dispose
  49. @target_window.dispose
  50. @max_window.dispose
  51. @command_window.dispose
  52. @number_window.dispose
  53. @over_window.dispose
  54. end
  55. #--------------------------------------------------------------------------
  56. # ● 回到原画面
  57. #--------------------------------------------------------------------------
  58. def return_scene
  59. $scene = Scene_Menu.new(0)
  60. end
  61. #--------------------------------------------------------------------------
  62. # ● 更新画面
  63. #--------------------------------------------------------------------------
  64. def update
  65. super
  66. update_menu_background
  67. @over_window.update
  68. @help_window.update
  69. @item_window.update
  70. @target_window.update
  71. @max_window.update
  72. @command_window.update
  73. @number_window.update
  74. if @item_window.active
  75. update_item_selection
  76. elsif @target_window.active
  77. update_target_selection
  78. elsif @command_window.active
  79. update_command_selection
  80. elsif @number_window.active
  81. update_number_selection
  82. end
  83. end
  84. #--------------------------------------------------------------------------
  85. # ● 更新物品选择
  86. #--------------------------------------------------------------------------
  87. def update_item_selection
  88. if Input.trigger?(Input::B)
  89. if $game_party.items.size > $item_max # 如果物品种类超过限制
  90. Sound.play_buzzer
  91. @over_window.visible = true
  92. @item_window.help_window.visible = false
  93. else
  94. Sound.play_cancel
  95. return_scene
  96. end
  97. elsif Input.trigger?(Input::C)
  98. @item_window.help_window.visible = true
  99. @over_window.visible = false
  100. @item = @item_window.item
  101. if @item != nil
  102. $game_party.last_item_id = @item.id
  103. Sound.play_decision
  104. if $game_party.item_can_use?(@item) # 物品是否可用
  105. @command_window.draw_item(0,true)
  106. else @command_window.draw_item(0,false) # 不可用的话【使用】选项颜色无效
  107. end
  108. if @item.price == 0 # 物品价格是否为0
  109. @command_window.draw_item(1,false) # 是的话【丢弃】选项无效
  110. else
  111. @command_window.draw_item(1,true)
  112. end
  113. show_command_window
  114. else
  115. Sound.play_buzzer
  116. end
  117. end
  118. end
  119. #--------------------------------------------------------------------------
  120. # ● 更新目标选择
  121. #--------------------------------------------------------------------------
  122. def update_target_selection
  123. if Input.trigger?(Input::B)
  124. Sound.play_cancel
  125. if $game_party.item_number(@item) == 0 # 判断物品是否耗尽
  126. @item_window.refresh # 刷新窗口内容
  127. @max_window.refresh # 刷新物品种类窗口
  128. end
  129. hide_target_window
  130. elsif Input.trigger?(Input::C)
  131. if not $game_party.item_can_use?(@item)
  132. Sound.play_buzzer
  133. else
  134. determine_target
  135. end
  136. end
  137. end
  138. #--------------------------------------------------------------------------
  139. # ★ 更新指令选择
  140. #--------------------------------------------------------------------------
  141. def update_command_selection
  142. if Input.trigger?(Input::B)
  143. Sound.play_cancel
  144. hide_command_window
  145. elsif Input.trigger?(Input::C)
  146. if @command_window.index == 0
  147. if $game_party.item_can_use?(@item)
  148. Sound.play_decision
  149. @command_window.active = false
  150. @command_window.visible =false
  151. determine_item
  152. else
  153. Sound.play_buzzer
  154. end
  155. elsif @item == nil or @item.price == 0
  156. Sound.play_buzzer
  157. else
  158. Sound.play_decision
  159. @command_window.active = false
  160. @command_window.visible =false
  161. max = $game_party.item_number(@item)
  162. @number_window.set(@item, max)
  163. show_number_window
  164. end
  165. end
  166. end
  167. #--------------------------------------------------------------------------
  168. # ★ 更新数量输入
  169. #--------------------------------------------------------------------------
  170. def update_number_selection
  171. if Input.trigger?(Input::B)
  172. Sound.play_cancel
  173. hide_number_window
  174. elsif Input.trigger?(Input::C)
  175. Audio.se_play("Audio/SE/#{LOSE_ITEM_SE_NAME}", 80, 100)
  176. $game_party.lose_item(@item, @number_window.number)
  177. @item_window.refresh
  178. @max_window.refresh
  179. hide_number_window
  180. end
  181. end
  182. #--------------------------------------------------------------------------
  183. # ★ 显示指令选择窗口
  184. #--------------------------------------------------------------------------
  185. def show_command_window
  186. @command_window.index = 0
  187. @item_window.active = false
  188. @command_window.visible = true
  189. @command_window.active = true
  190. end
  191. #--------------------------------------------------------------------------
  192. # ★ 显示数量窗口
  193. #--------------------------------------------------------------------------
  194. def show_number_window
  195. @command_window.active = false
  196. @number_window.visible = true
  197. @number_window.active = true
  198. end
  199. #--------------------------------------------------------------------------
  200. # ★ 隐藏指令选择窗口
  201. #--------------------------------------------------------------------------
  202. def hide_command_window
  203. @item_window.active = true
  204. @command_window.visible = false
  205. @command_window.active = false
  206. @viewport.rect.set(0, 0, 544, 416)
  207. @viewport.ox = 0
  208. end
  209. #--------------------------------------------------------------------------
  210. # ★ 隐藏数量窗口
  211. #--------------------------------------------------------------------------
  212. def hide_number_window
  213. @item_window.active = true
  214. @number_window.visible = false
  215. @number_window.active = false
  216. @viewport.rect.set(0, 0, 544, 416)
  217. @viewport.ox = 0
  218. end
  219. end
  220. #==============================================================================
  221. # ■ Window_lost_item
  222. #------------------------------------------------------------------------------
  223. #  显示物品丢弃数量的窗口,仿 Window_ShopNumber。
  224. #==============================================================================
  225. class Window_LoseNumber < Window_Base
  226. #--------------------------------------------------------------------------
  227. # ★ 初始化对像
  228. # x : 窗口 X 座标
  229. # y : 窗口 Y 座标
  230. #--------------------------------------------------------------------------
  231. def initialize(x, y)
  232. super(x, y, 260, 104)
  233. @item = nil
  234. @max = 1
  235. @number = 1
  236. end
  237. #--------------------------------------------------------------------------
  238. # ★ 设置物品、最大数量
  239. #--------------------------------------------------------------------------
  240. def set(item, max)
  241. @item = item
  242. @max = max
  243. @number = 1
  244. refresh
  245. end
  246. #--------------------------------------------------------------------------
  247. # ★ 设置数量输入
  248. #--------------------------------------------------------------------------
  249. def number
  250. return @number
  251. end
  252. #--------------------------------------------------------------------------
  253. # ★ 刷新
  254. #--------------------------------------------------------------------------
  255. def refresh
  256. y = 24
  257. self.contents.clear
  258. draw_item_name(@item, 0, y)
  259. self.contents.font.color = normal_color
  260. self.contents.draw_text(164, y, 20, WLH, "×")
  261. self.contents.draw_text(190, y, 20, WLH, @number, 2)
  262. self.cursor_rect.set(186, y, 28, WLH)
  263. end
  264. #--------------------------------------------------------------------------
  265. # ★ 更新画面
  266. #--------------------------------------------------------------------------
  267. def update
  268. super
  269. if self.active
  270. last_number = @number
  271. if Input.repeat?(Input::RIGHT) and @number < @max
  272. @number += 1
  273. end
  274. if Input.repeat?(Input::LEFT) and @number > 1
  275. @number -= 1
  276. end
  277. if Input.repeat?(Input::UP) and @number < @max
  278. @number = [@number + 10, @max].min
  279. end
  280. if Input.repeat?(Input::DOWN) and @number > 1
  281. @number = [@number - 10, 1].max
  282. end
  283. if @number != last_number
  284. Sound.play_cursor
  285. refresh
  286. end
  287. end
  288. end
  289. end
  290. #==============================================================================
  291. # ■ Window_Item_Max
  292. #-----------------------------------------------------------------------------
  293. # 显示背包容量和当前物品数的窗口
  294. #============================================================================
  295.  
  296. class Window_Item_Max < Window_Base
  297. #--------------------------------------------------------------------------
  298. # ★ 初始化对像
  299. #--------------------------------------------------------------------------
  300. def initialize
  301. super(290, 360, 254, 56)
  302. refresh
  303. end
  304. #--------------------------------------------------------------------------
  305. # ★ 刷新
  306. #--------------------------------------------------------------------------
  307. def refresh
  308. self.contents.clear
  309. draw_icon(144, 0, 0)
  310. self.contents.draw_text(36, 0, 100, 24, "背包容量:")
  311. item = $game_party.items
  312. string = item.size.to_s
  313. self.contents.font.color = knockout_color if item.size > $item_max
  314. self.contents.draw_text(135, 0, 30, 24, string, 2)
  315. self.contents.font.color = normal_color
  316. string = "/ " + $item_max.to_s
  317. self.contents.draw_text(173, 0, 100, 24, string )
  318. end
  319. end

求助各位大佬!

EMMM,请版主结贴吧。估计不会得到答案了
作者: 爱羊真知己    时间: 2023-2-25 17:30
哦,忘了说了,是使用物品时,不是按A键!
作者: 灯笼菜刀王    时间: 2023-2-25 20:14
136行和137行之间增加一句   return false if item.note.include?("【禁止丢弃】")

然后要不能丢弃的物品就在备注栏里写上 【禁止丢弃】
作者: 爱羊真知己    时间: 2023-2-25 21:50
本帖最后由 爱羊真知己 于 2023-2-25 22:08 编辑
灯笼菜刀王 发表于 2023-2-25 20:14
136行和137行之间增加一句   return false if item.note.include?("【禁止丢弃】")

然后要不能丢弃的物品 ...


谢谢(不过我刚才已经更改了问题描述)
作者: 爱羊真知己    时间: 2023-3-3 21:13
一个人都没有……
作者: 爱羊真知己    时间: 2023-3-8 15:21
确实没有人……
作者: 爱羊真知己    时间: 2023-3-12 16:54
啊……难道真的做不到或太难了?
作者: 爱羊真知己    时间: 2023-3-24 19:44
再顶最后一次
作者: 爱羊真知己    时间: 2023-5-21 15:52
EMMM,请版主结贴吧。




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