pigu_6

XS| Inventory Weight

Dec 16th, 2012
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.63 KB | None | 0 0
  1. #==============================================================================
  2. # XaiL System - Inventory Weight
  3. # Author: Nicke
  4. # Created: 02/05/2012
  5. # Edited: 12/05/2012
  6. # Version: 1.0b
  7. #==============================================================================
  8. # Instructions
  9. # -----------------------------------------------------------------------------
  10. # To install this script, open up your script editor and copy/paste this script
  11. # to an open slot below ? Materials but above ? Main. Remember to save.
  12. #
  13. # This script enables you to have a inventory weight.
  14. # The max weight will increase based on level from default. This can be altered
  15. # as you like. See the settings for more details about customizing that.
  16. #
  17. # From default an item's weight is 0.0 unless you specify it in the notetag like
  18. # this:
  19. # <WEIGHT|weight: number>
  20. #
  21. # Examples:
  22. # <weight: 20.0>
  23. # <WEIGHT: 40.0>
  24. #
  25. # At default if an item exists already it won't increase the weight again
  26. # so you can stack up an item to the default max value (99). This can be changed
  27. # in the settings.
  28. #
  29. # The max weight will be 0 from start. To refresh it do the following in a
  30. # script call:
  31. # $game_party.refresh_weight
  32. #
  33. # The standard methods from the event page will add an item as default.
  34. # To add/remove an item with weight you need to use the following method
  35. # in a script call:
  36. # $game_party.weight_item(item, amount = 1, type = :item, weight_type = :gain)
  37. #
  38. # Examples:
  39. # $game_party.weight_item(1) # // Add one of item_id 1 with type item.
  40. # $game_party.weight_item(1, 2, :weapon) # // Add 2 of item_id 1 with type weapon.
  41. # $game_party.weight_item(1, 1, :armor, :lose) # // Remove one of item_id 1 with type armor.
  42. # Note: With this you can go beyond 99 which is the default max if you are
  43. # using a script that enables you to stack up more then 99 items.
  44. # You can use my script called XS - Hero Control for that.
  45. # However, my script uses a variable to change the stack for the items and it's
  46. # not so intuitive if you are gonna change alot of items.
  47. #
  48. # You can use a quick method to add/remove items as well in a script call:
  49. # w_item(25, 5)
  50. # w_item(1, 2, :armor, :lose)
  51. # Using this method is recommened because it's easier to read and it fits better.
  52. #
  53. # To check the current weight as well as the max weight do the following in a
  54. # script call:
  55. # $game_party.weight
  56. # $game_party.max_weight
  57. # Those can be used in a conditional branch etc for certain things.
  58. # Warning: Don't try to use those methods to alter the max weight or weight
  59. # because that will throw an error.
  60. #
  61. # *** Only for RPG Maker VX Ace. ***
  62. #==============================================================================
  63. ($imported ||= {})["XAIL-INVENTORY-WEIGHT"] = true
  64.  
  65. module XAIL
  66. module INV_WEIGHT
  67. #--------------------------------------------------------------------------#
  68. # * Settings
  69. #--------------------------------------------------------------------------#
  70. # Should weight be increased if you stack up items?
  71. # i.e if you have 2 or more of the same items.
  72. # STACK_WEIGHT = true/false
  73. STACK_WEIGHT = true
  74.  
  75. # Max MAX_WEIGHT_TYPE = :symbol
  76. # :default = Increase max weight based on actor level.
  77. # :str = Increase max_weight based on actor strength (atk).
  78. # :custom = Increase max_weight based on custom parameters.
  79. MAX_WEIGHT_TYPE = :default
  80.  
  81. # Formula for max weight based on level.
  82. def self.weight_level
  83. case $game_party.leader.level
  84. when 1..10 ; weight = 100.0
  85. when 11..19 ; weight = 200.0
  86. when 20..30 ; weight = 300.0
  87. when 31..40 ; weight = 400.0
  88. when 41..50 ; weight = 500.0
  89. end
  90. return weight
  91. end
  92.  
  93. # Custom formula. Currently set to be based on actor's atk and agi
  94. # divided by 2.
  95. # Choose what you like in here.
  96. # Note: Don't use if you are not familiar with how parameters work.
  97. def self.weight_custom
  98. $game_party.leader.atk.to_f + $game_party.leader.agi.to_f / 2.0
  99. end
  100.  
  101. # Enable this if you want the player to be able to get encumbered.
  102. # For example: At 50% of current weight the actor will run/walk at a
  103. # decreased speed until an item is consumed or sold/dropped.
  104. # At 90% of total weight the dashing option is not enabled as well.
  105. # USE_ENCUMBER = true/false
  106. USE_ENCUMBER = true
  107.  
  108. # This decides the actor's move speed if USE_ENCUMBER is enabled.
  109. # Explaination:
  110. # At 50% the movement speed is decreased to 3.8.
  111. # At 75% the movement speed is decreased to 3.4.
  112. # At 90% the movement speed is decreased to 3.2.
  113. # At 95% the movement speed is decreased to 3.0.
  114. # Under 50% the movement speed is set to default.
  115. def self.encumber_speed(weight, max, default)
  116. $game_player.move_speed = 3.8 if weight >= max * 0.50
  117. $game_player.move_speed = 3.4 if weight >= max * 0.75
  118. $game_player.move_speed = 3.2 if weight >= max * 0.90
  119. $game_player.move_speed = 3.0 if weight >= max * 0.95
  120. $game_player.move_speed = default if weight <= max * 0.50
  121. end
  122. end
  123. end
  124. # *** Don't edit below unless you know what you are doing. ***
  125. #==============================================================================#
  126. # ** RPG::BaseItem
  127. #==============================================================================#
  128. class RPG::BaseItem
  129.  
  130. def weight
  131. # // Method to set a item weight.
  132. @note.scan(/<(?:WEIGHT|weight):\s(\d+.\d+)>/i)
  133. return ($1.to_f > 0.0 ? $1.to_f : 0.0)
  134. end
  135.  
  136. end
  137. #==============================================================================#
  138. # ** Game_Party
  139. #==============================================================================#
  140. class Game_Party < Game_Unit
  141.  
  142. attr_reader :weight
  143. attr_reader :max_weight
  144.  
  145. alias xail_item_weight_sys_init initialize
  146. def initialize(*args, &block)
  147. # // Method to initialize.
  148. xail_item_weight_sys_init(*args, &block)
  149. @weight = 0.0
  150. @max_weight = 0.0
  151. end
  152.  
  153. def refresh_weight
  154. # // Method to refresh the max weight.
  155. @max_weight = max_weight? unless leader.nil?
  156. end
  157.  
  158. def max_weight?
  159. # // Method to check the max weight.
  160. case XAIL::INV_WEIGHT::MAX_WEIGHT_TYPE
  161. when :default ; return @max_weight = XAIL::INV_WEIGHT.weight_level
  162. when :str ; return @max_weight = leader.atk.to_f
  163. when :custom ; return @max_weight = XAIL::INV_WEIGHT.weight_custom
  164. end
  165. end
  166.  
  167. def weight_item(item, amount = 1, type = :item, weight_type = :gain)
  168. # // Method to gain an item with weight.
  169. case type
  170. when :item ; type = $data_items
  171. when :weapon ; type = $data_weapons
  172. when :armor ; type = $data_armors
  173. end
  174. item = type[item]
  175. case weight_type
  176. when :gain
  177. # // Gain: Increase the current weight.
  178. unless item.nil?
  179. unless XAIL::INV_WEIGHT::STACK_WEIGHT
  180. unless has_item?(type[item.id])
  181. @weight += item.weight
  182. end
  183. else
  184. @weight += item.weight
  185. end
  186. if @weight > max_weight?
  187. return @weight -= item.weight
  188. end
  189. gain_item(item, amount, false)
  190. end
  191. when :lose
  192. # // Lose: Decrease the current weight.
  193. return unless has_item?(type[item.id])
  194. unless item.nil?
  195. unless XAIL::INV_WEIGHT::STACK_WEIGHT
  196. unless has_item?(type[item.id])
  197. @weight -= item.weight unless @weight <= 0.0
  198. end
  199. if item_number(item) < 2
  200. @weight -= item.weight unless @weight <= 0.0
  201. end
  202. else
  203. @weight -= item.weight unless @weight <= 0.0
  204. end
  205. gain_item(item, -amount, false)
  206. end
  207. end
  208. end
  209.  
  210. end
  211. #==============================================================================#
  212. # ** Game_Player
  213. #==============================================================================#
  214. class Game_Player < Game_Character
  215.  
  216. attr_accessor :move_speed
  217.  
  218. alias xail_item_weight_game_player_init initialize
  219. def initialize
  220. # // Method to initialize game player.
  221. @weight = $game_party.weight
  222. @max_weight = $game_party.max_weight
  223. xail_item_weight_game_player_init
  224. @default_move_speed = @move_speed.to_f
  225. end
  226.  
  227. alias xail_item_weight_game_player_dash? dash?
  228. def dash?
  229. # // Method to check if player can dash.
  230. return false if $game_party.weight >= $game_party.max_weight * 0.90 if XAIL::INV_WEIGHT::USE_ENCUMBER
  231. xail_item_weight_game_player_dash?
  232. end
  233.  
  234. alias xail_item_weight_game_player_update update
  235. def update
  236. # // Method to refresh game player.
  237. if XAIL::INV_WEIGHT::USE_ENCUMBER
  238. if @weight != $game_party.weight
  239. @weight = $game_party.weight
  240. @max_weight = $game_party.max_weight
  241. XAIL::INV_WEIGHT.encumber_speed(@weight, @max_weight, @default_move_speed)
  242. end
  243. end
  244. xail_item_weight_game_player_update
  245. end
  246.  
  247. end
  248. #==============================================================================#
  249. # ** Game_Interpreter
  250. #==============================================================================#
  251. class Game_Interpreter
  252.  
  253. def w_item(item, amount = 1, type = :item, weight_type = :gain)
  254. # // Quick method to add/remove an item with weight.
  255. $game_party.weight_item(item, amount, type, weight_type)
  256. end
  257.  
  258. end # END OF FILE
  259.  
  260. #=*==========================================================================*=#
  261. # ** END OF FILE
  262. #=*==========================================================================*=#
Add Comment
Please, Sign In to add comment