Project1

标题: 如何让携带物品数限制? [打印本页]

作者: asperta    时间: 2008-3-1 23:40
标题: 如何让携带物品数限制?
每种种类的物品数限制,
例如每个道具最多只能拿15个! [LINE]1,#dddddd[/LINE]版务信息:本贴由楼主自主结贴~
作者: Iselia雪    时间: 2008-3-1 23:49
提示: 作者被禁止或删除 内容自动屏蔽
作者: 天圣的马甲    时间: 2008-3-1 23:57
不错的方法……
我直接用了外站脚本{/hx}
注释我大概写了两句,应该很好懂也很好设置……
  1. #_______________________________________________________________________________
  2. # MOG Item Limit V1.7            
  3. #_______________________________________________________________________________
  4. # By Moghunter            
  5. # http://www.atelier-rgss.com
  6. #_______________________________________________________________________________
  7. # Permite definir o limite maximo para cada item, armas
  8. # ou armaduras.
  9. #_______________________________________________________________________________
  10. module MOG
  11. #-------------------------------------------------------------------------------  
  12. # Definição do limite padrão.
  13. #-------------------------------------------------------------------------------
  14. DEFAULT_LIMIT = 99  #给所有物品的默认数目限制
  15. #-------------------------------------------------------------------------------
  16. # A => B
  17. #
  18. # A = 你的物品ID
  19. # B = 限制数目
  20. #
  21. #-------------------------------------------------------------------------------
  22. #物品的数量限制  
  23. #-------------------------------------------------------------------------------
  24. ITEM_LIMIT = {
  25. 1=>60,       #Potion
  26. 2=>35,       #Hi Potion
  27. 3=>20,       #Full Potion
  28. 4=>45,       #Perfume
  29. 5=>30,       #Hi Perfume
  30. 6=>15,       #Full Perfume
  31. 7=>10,       #Elixir
  32. 8=>5,        #Full Elixir
  33. 9=>35,       #Tonic
  34. 10=>15,      #Full Tonic
  35. 11=>70       #Antidote
  36.              }  
  37. #-------------------------------------------------------------------------------
  38. #武器的数量限制.   
  39. #-------------------------------------------------------------------------------
  40. WEAPON_LIMIT = {
  41. 1=>9,        #Bronze Sword
  42. 2=>6,        #Iron Sword
  43. 3=>3,        #Steel Sword
  44. 4=>1,        #Mythril Sword
  45. 5=>9,        #Bronze Spear
  46. 6=>6,        #Iron Spear
  47. 7=>3,        #Steel Spear
  48. 8=>1         #Mythril Spear
  49.                }     
  50. #-------------------------------------------------------------------------------
  51. #防具的数量限制
  52. #-------------------------------------------------------------------------------
  53. ARMOR_LIMIT = {
  54. 1=>20,       #Bronze Shield
  55. 2=>15,       #Iron Shield
  56. 5=>20,       #Bronze Helm
  57. 13=>10       #Bronze Armor
  58.                }   
  59. #-------------------------------------------------------------------------------
  60. #Definição do limite maximo de dinheiro
  61. #-------------------------------------------------------------------------------
  62. GOLD_LIMIT = 100000
  63. #-------------------------------------------------------------------------------
  64. end
  65. $mogscript = {} if $mogscript == nil
  66. $mogscript["Item_Limit"] = true
  67. ##############
  68. # Game_Party #
  69. ##############
  70. class Game_Party
  71. alias mog45_gain_item gain_item
  72. def gain_item(item_id, n)
  73. if item_id > 0
  74. item_limit = MOG::ITEM_LIMIT[item_id]
  75. if item_limit != nil  
  76. @items[item_id] = [[item_number(item_id) + n, 0].max, item_limit].min
  77. else  
  78. @items[item_id] = [[item_number(item_id) + n, 0].max, MOG::DEFAULT_LIMIT].min
  79. end
  80. end
  81. return
  82. mog45_gain_item(item_id, n)
  83. end
  84. alias mog45_gain_weapon gain_weapon
  85. def gain_weapon(weapon_id, n)
  86. if weapon_id > 0
  87. weapon_limit = MOG::WEAPON_LIMIT[weapon_id]   
  88. if weapon_limit !=nil  
  89. @weapons[weapon_id] = [[weapon_number(weapon_id) + n, 0].max, weapon_limit].min
  90. else
  91. @weapons[weapon_id] = [[weapon_number(weapon_id) + n, 0].max, MOG::DEFAULT_LIMIT].min
  92. end
  93. end
  94. return
  95. mog45_gain_weapon(weapon_id, n)
  96. end
  97. alias mog45_gain_armor gain_armor
  98. def gain_armor(armor_id, n)
  99. if armor_id > 0
  100. armor_limit = MOG::ARMOR_LIMIT[armor_id]
  101. if armor_limit != nil
  102. @armors[armor_id] = [[armor_number(armor_id) + n, 0].max, armor_limit].min
  103. else  
  104. @armors[armor_id] = [[armor_number(armor_id) + n, 0].max, MOG::DEFAULT_LIMIT].min
  105. end
  106. end
  107. return
  108. mog45_gain_armor   
  109. end
  110. def gain_gold(n)
  111. @gold = [[@gold + n, 0].max, MOG::GOLD_LIMIT].min
  112. end  
  113. end
  114. ##############
  115. # Scene_Shop #
  116. ##############
  117. class Scene_Shop
  118. alias mog45_update update  
  119. def update
  120. if @sell_window.active == true
  121. $sell = true  
  122. else  
  123. $sell = false  
  124. end  
  125. mog45_update
  126. end  
  127. alias mog45_update_buy update_buy
  128. def update_buy
  129. if Input.trigger?(Input::C)  
  130. @item = @buy_window.item
  131. case @item
  132. when RPG::Item
  133. number = $game_party.item_number(@item.id)
  134. item_limit = MOG::ITEM_LIMIT[@item.id]
  135. if item_limit != nil
  136. if number >= item_limit
  137. $game_system.se_play($data_system.buzzer_se)
  138. return
  139. end
  140. else
  141. if number == MOG::DEFAULT_LIMIT
  142. $game_system.se_play($data_system.buzzer_se)
  143. return
  144. end  
  145. end
  146. when RPG::Weapon
  147. number = $game_party.weapon_number(@item.id)
  148. weapon_limit = MOG::WEAPON_LIMIT[@item.id]
  149. if weapon_limit != nil
  150. if number >= weapon_limit
  151. $game_system.se_play($data_system.buzzer_se)
  152. return
  153. end
  154. else
  155. if number == MOG::DEFAULT_LIMIT
  156. $game_system.se_play($data_system.buzzer_se)
  157. return
  158. end
  159. end
  160. when RPG::Armor
  161. number = $game_party.armor_number(@item.id)
  162. armor_limit = MOG::ARMOR_LIMIT[@item.id]
  163. if armor_limit != nil
  164. if number >= armor_limit
  165. $game_system.se_play($data_system.buzzer_se)
  166. return
  167. end
  168. else
  169. if number == MOG::DEFAULT_LIMIT
  170. $game_system.se_play($data_system.buzzer_se)
  171. return
  172. end
  173. end
  174. end  
  175. end
  176. mog45_update_buy
  177. end
  178. end
  179. #####################
  180. # Window_ShopNumber #
  181. #####################
  182. class Window_ShopNumber < Window_Base
  183. alias mog45_set set
  184. def set(item, max, price)
  185. @item = item
  186. case @item
  187. when RPG::Item
  188. number = $game_party.item_number(@item.id)
  189. item_limit = MOG::ITEM_LIMIT[@item.id]
  190. if item_limit!= nil
  191. if $sell == true
  192. valor = item_limit - number
  193. @max = item_limit - valor
  194. else
  195. @max = item_limit - number
  196. end
  197. else
  198. if $sell == true
  199. valor = MOG::DEFAULT_LIMIT - number  
  200. @max = MOG::DEFAULT_LIMIT - valor
  201. else
  202. @max = MOG::DEFAULT_LIMIT - number
  203. end
  204. end
  205. when RPG::Weapon
  206. number = $game_party.weapon_number(@item.id)
  207. weapon_limit = MOG::WEAPON_LIMIT[@item.id]
  208. if weapon_limit!= nil
  209. if $sell == true
  210. valor = weapon_limit - number
  211. @max = weapon_limit - valor
  212. else
  213. @max = weapon_limit - number
  214. end
  215. else
  216. if $sell == true  
  217. valor = MOG::DEFAULT_LIMIT - number   
  218. @max = MOG::DEFAULT_LIMIT - valor
  219. else
  220. @max = MOG::DEFAULT_LIMIT - number
  221. end
  222. end   
  223. when RPG::Armor
  224. number = $game_party.armor_number(@item.id)
  225. armor_limit = MOG::ARMOR_LIMIT[@item.id]
  226. if armor_limit!= nil
  227. if $sell == true
  228. valor = armor_limit - number
  229. @max = armor_limit - valor
  230. else
  231. @max = armor_limit - number
  232. end
  233. else
  234. if $sell == true
  235. valor = MOG::DEFAULT_LIMIT - number   
  236. @max = MOG::DEFAULT_LIMIT - valor  
  237. else
  238. @max = MOG::DEFAULT_LIMIT - number
  239. end
  240. end
  241. end
  242. @price = price
  243. @number = 1
  244. refresh
  245. return
  246. mog45_set set(item, max, price)
  247. end  
  248. end  
  249. ###############
  250. # Window_Item #
  251. ###############
  252. class Window_Item < Window_Selectable
  253. def draw_item(index)
  254. item = @data[index]
  255. case item
  256. when RPG::Item
  257. number = $game_party.item_number(item.id)
  258. item_number = MOG::ITEM_LIMIT[item.id]
  259. when RPG::Weapon
  260. number = $game_party.weapon_number(item.id)
  261. item_number = MOG::WEAPON_LIMIT[item.id]  
  262. when RPG::Armor
  263. number = $game_party.armor_number(item.id)
  264. item_number = MOG::ARMOR_LIMIT[item.id]
  265. end
  266. if item.is_a?(RPG::Item) and
  267. $game_party.item_can_use?(item.id)
  268. self.contents.font.color = normal_color
  269. else
  270. self.contents.font.color = disabled_color
  271. end
  272. x = 4 + index % 2 * (288 + 32)
  273. y = index / 2 * 32
  274. rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  275. self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  276. bitmap = RPG::Cache.icon(item.icon_name)
  277. opacity = self.contents.font.color == normal_color ? 255 : 128
  278. self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  279. self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  280. if item_number != nil
  281. self.contents.draw_text(x + 220, y, 60, 32, number.to_s + " / " + item_number.to_s, 2)
  282. else
  283. max_limit = MOG::DEFAULT_LIMIT
  284. self.contents.draw_text(x + 220, y, 60, 32, number.to_s + " / " + max_limit.to_s, 2)
  285. end
  286. end
  287. end
  288. ##################
  289. # Window_Item_Ex #
  290. ##################
  291. class Window_Item_Ex < Window_Selectable
  292. def draw_item(index)
  293. item = @data[index]
  294. case item
  295. when RPG::Item
  296. number = $game_party.item_number(item.id)
  297. item_number = MOG::ITEM_LIMIT[item.id]
  298. end
  299. if item.is_a?(RPG::Item) and
  300. $game_party.item_can_use?(item.id)
  301. self.contents.font.color = normal_color
  302. else
  303. self.contents.font.color = disabled_color
  304. end
  305. x = 4 + index % 1 * (288 + 32)
  306. y = index / 1 * 32
  307. rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  308. self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  309. self.contents.font.name = "Georgia"   
  310. bitmap = RPG::Cache.icon(item.icon_name)
  311. opacity = self.contents.font.color == normal_color ? 255 : 128   
  312. self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  313. self.contents.draw_text(x + 28, y, 190, 32, item.name, 0)
  314. if item_number != nil
  315. self.contents.draw_text(x + 195, y, 60, 32, number.to_s + " / " + item_number.to_s, 2)
  316. else
  317. max_limit = MOG::DEFAULT_LIMIT
  318. self.contents.draw_text(x + 195, y, 60, 32, number.to_s + " / " + max_limit.to_s, 2)
  319. end
  320. end  
  321. end
  322. #################
  323. # Window_Weapon #
  324. #################
  325. class Window_Weapon < Window_Selectable
  326. def draw_item(index)
  327. item = @data[index]
  328. case item
  329. when RPG::Weapon
  330. number = $game_party.weapon_number(item.id)
  331. item_number = MOG::WEAPON_LIMIT[item.id]  
  332. end
  333. if item.is_a?(RPG::Item) and
  334. $game_party.item_can_use?(item.id)
  335. self.contents.font.color = normal_color
  336. else
  337. self.contents.font.color = disabled_color
  338. end
  339. x = 4 + index % 1 * (288 + 32)
  340. y = index / 1 * 32
  341. rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  342. self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  343. self.contents.font.name = "Georgia"   
  344. bitmap = RPG::Cache.icon(item.icon_name)
  345. opacity = self.contents.font.color == normal_color ? 255 : 128   
  346. self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  347. self.contents.draw_text(x + 28, y, 190, 32, item.name, 0)
  348. if item_number != nil
  349. self.contents.draw_text(x + 195, y, 60, 32, number.to_s + " / " + item_number.to_s, 2)
  350. else
  351. max_limit = MOG::DEFAULT_LIMIT
  352. self.contents.draw_text(x + 195, y, 60, 32, number.to_s + " / " + max_limit.to_s, 2)
  353. end
  354. end  
  355. end
  356. ################
  357. # Window_Armor #
  358. ################
  359. class Window_Armor < Window_Selectable
  360. def draw_item(index)
  361. item = @data[index]
  362. case item
  363. when RPG::Armor
  364. number = $game_party.armor_number(item.id)
  365. item_number = MOG::ARMOR_LIMIT[item.id]
  366. end
  367. if item.is_a?(RPG::Item) and
  368. $game_party.item_can_use?(item.id)
  369. self.contents.font.color = normal_color
  370. else
  371. self.contents.font.color = disabled_color
  372. end
  373. x = 4 + index % 1 * (288 + 32)
  374. y = index / 1 * 32
  375. rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  376. self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  377. self.contents.font.name = "Georgia"   
  378. bitmap = RPG::Cache.icon(item.icon_name)
  379. opacity = self.contents.font.color == normal_color ? 255 : 128   
  380. self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  381. self.contents.draw_text(x + 28, y, 190, 32, item.name, 0)
  382. if item_number != nil
  383. self.contents.draw_text(x + 195, y, 60, 32, number.to_s + " / " + item_number.to_s, 2)
  384. else
  385. max_limit = MOG::DEFAULT_LIMIT
  386. self.contents.draw_text(x + 195, y, 60, 32, number.to_s + " / " + max_limit.to_s, 2)
  387. end
  388. end   
  389. end
  390. #####################
  391. # Window_ShopStatus #
  392. #####################
  393. class Window_ShopStatus < Window_Base
  394. alias mog45_refresh refresh
  395. def refresh
  396. if $mogscript["menu_shop"] == true
  397. mog45_refresh
  398. return false
  399. end
  400. self.contents.clear
  401. if @item == nil
  402. return
  403. end
  404. case @item
  405. when RPG::Item
  406. number = $game_party.item_number(@item.id)
  407. item_max = MOG::ITEM_LIMIT[@item.id]
  408. when RPG::Weapon
  409. number = $game_party.weapon_number(@item.id)
  410. item_max = MOG::WEAPON_LIMIT[@item.id]  
  411. when RPG::Armor
  412. number = $game_party.armor_number(@item.id)
  413. item_max = MOG::ARMOR_LIMIT[@item.id]
  414. end
  415. self.contents.font.color = system_color
  416. self.contents.draw_text(4, 0, 200, 32, "Stock")
  417. self.contents.font.color = normal_color
  418. if item_max != nil
  419. self.contents.draw_text(155, 0, 80, 32, number.to_s + " / " + item_max.to_s, 2)
  420. else
  421. max_limit = MOG::DEFAULT_LIMIT
  422. self.contents.draw_text(155, 0, 80, 32, number.to_s + " / " + max_limit.to_s, 2)
  423. end
  424. if @item.is_a?(RPG::Item)
  425. return
  426. end
  427. for i in 0...$game_party.actors.size
  428. actor = $game_party.actors[i]
  429. if actor.equippable?(@item)
  430. self.contents.font.color = normal_color
  431. else
  432. self.contents.font.color = disabled_color
  433. end
  434. self.contents.draw_text(4, 64 + 64 * i, 120, 32, actor.name)
  435. if @item.is_a?(RPG::Weapon)
  436. item1 = $data_weapons[actor.weapon_id]
  437. elsif @item.kind == 0
  438. item1 = $data_armors[actor.armor1_id]
  439. elsif @item.kind == 1
  440. item1 = $data_armors[actor.armor2_id]
  441. elsif @item.kind == 2
  442. item1 = $data_armors[actor.armor3_id]
  443. else
  444. item1 = $data_armors[actor.armor4_id]
  445. end
  446. if actor.equippable?(@item)
  447. if @item.is_a?(RPG::Weapon)
  448. atk1 = item1 != nil ? item1.atk : 0
  449. atk2 = @item != nil ? @item.atk : 0
  450. change = atk2 - atk1
  451. end
  452. if @item.is_a?(RPG::Armor)
  453. pdef1 = item1 != nil ? item1.pdef : 0
  454. mdef1 = item1 != nil ? item1.mdef : 0
  455. pdef2 = @item != nil ? @item.pdef : 0
  456. mdef2 = @item != nil ? @item.mdef : 0
  457. change = pdef2 - pdef1 + mdef2 - mdef1
  458. end
  459. self.contents.draw_text(124, 64 + 64 * i, 112, 32,
  460. sprintf("%+d", change), 2)
  461. end
  462. if item1 != nil
  463. x = 4
  464. y = 64 + 64 * i + 32
  465. bitmap = RPG::Cache.icon(item1.icon_name)
  466. opacity = self.contents.font.color == normal_color ? 255 : 128
  467. self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  468. self.contents.draw_text(x + 28, y, 212, 32, item1.name)
  469. end
  470. end
  471. return true
  472. mog45_refresh
  473. end
  474. end
  475. ###################
  476. # Window_ShopSell #
  477. ###################
  478. class Window_ShopSell < Window_Selectable
  479. def initialize
  480. if $mogscript["menu_shop"] == true
  481. super(-10, 180, 305, 225)
  482. self.opacity = 0
  483. @column_max = 1
  484. refresh
  485. self.index = 0
  486. else   
  487. super(0, 128, 640, 352)  
  488. @column_max = 2
  489. refresh
  490. self.index = 0   
  491. end
  492. end
  493. def draw_item(index)  
  494. item = @data[index]
  495. case item
  496. when RPG::Item
  497. number = $game_party.item_number(item.id)
  498. item_number = MOG::ITEM_LIMIT[item.id]
  499. when RPG::Weapon
  500. number = $game_party.weapon_number(item.id)
  501. item_number = MOG::WEAPON_LIMIT[item.id]  
  502. when RPG::Armor
  503. number = $game_party.armor_number(item.id)
  504. item_number = MOG::ARMOR_LIMIT[item.id]
  505. end
  506. if item.price > 0
  507. self.contents.font.color = normal_color
  508. else
  509. self.contents.font.color = disabled_color
  510. end
  511. if $mogscript["menu_shop"] == nil
  512. x = 4 + index % 2 * (288 + 32)
  513. y = index / 2 * 32
  514. rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  515. self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  516. bitmap = RPG::Cache.icon(item.icon_name)
  517. opacity = self.contents.font.color == normal_color ? 255 : 128
  518. self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  519. self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  520. if item_number != nil
  521. self.contents.draw_text(x + 220, y, 60, 32, number.to_s + " / " + item_number.to_s, 2)
  522. else
  523. max_limit = MOG::DEFAULT_LIMIT
  524. self.contents.draw_text(x + 220, y, 60, 32, number.to_s + " / " + max_limit.to_s, 2)
  525. end
  526. else
  527. self.contents.font.name = "Georgia"  
  528. x = 4 + index % 1 * (288 + 32)
  529. y = index / 1 * 32
  530. rect = Rect.new(x, y, self.width / @column_max - 32, 32)
  531. self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
  532. bitmap = RPG::Cache.icon(item.icon_name)
  533. opacity = self.contents.font.color == normal_color ? 255 : 128
  534. self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
  535. self.contents.draw_text(x + 28, y, 150, 32, item.name, 0)
  536. self.contents.font.color = Color.new(50,250,150,255)
  537. prc = item.price / 2
  538. self.contents.draw_text(x + 180, y, 80, 32, "+G " + prc.to_s, 2)
  539. end
  540. end
  541. end
复制代码

作者: Iselia雪    时间: 2008-3-2 00:08
提示: 作者被禁止或删除 内容自动屏蔽
作者: 天圣的马甲    时间: 2008-3-2 00:13
偶素哈希表无能者……只好吃现成的,而且那个不是英文,是德文{/hx}

(你那nieniexueli……无语…………{/lh}……)
作者: Iselia雪    时间: 2008-3-2 00:18
提示: 作者被禁止或删除 内容自动屏蔽
作者: 天圣的马甲    时间: 2008-3-2 00:36
没有……我只能看懂极其简单的几个德文字,其实并不会德文……= =

你那个“haishiniexueli”的方法……呃,能稍微简单地说明一下吗?0_0
作者: Iselia雪    时间: 2008-3-2 00:41
提示: 作者被禁止或删除 内容自动屏蔽
作者: 天圣的马甲    时间: 2008-3-2 00:44
哦,我记得当初为了push数组里面最大最小数的问题还纠结了很长时间……(我果然还是半吊子啊OTL)

明白了,谢谢小雪-v-
作为奖赏可以让你多捏一次=v=
作者: Iselia雪    时间: 2008-3-2 00:47
提示: 作者被禁止或删除 内容自动屏蔽




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