Advertisement
adiktuzmiko

SS Add-On: Total Item Limit v1.00

Sep 26th, 2014
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.96 KB | None | 0 0
  1. =begin
  2. ======================================================
  3.  
  4.   SS Add-On: Total Item Limit v1.00
  5.   by Adiktuzmiko                  
  6.  
  7.   Date Created: 09/27/2014
  8.   Date Last Updated: 09/27/2014
  9.   Requires: Shared Storage v2.10
  10.   Difficulty: Easy
  11.  
  12. ======================================================
  13.  Overview
  14. ======================================================
  15.  
  16.  Allows the shared storages to have a limit based
  17.  on total items inside of it
  18.  
  19. ======================================================
  20.  Usage
  21. ======================================================
  22.  
  23.  Put this script into your scripts editor and modify
  24.  the settings below
  25.  
  26.  To make a storage use this limit script, on the ITEM_MAX_NUMBER
  27.  of that storage, put "SceneManager.scene.get_item_limit"
  28.  
  29.  Example: If you want storage 1 to use this:
  30.  
  31.  ITEM_MAX_NUMBER[1] = "SceneManager.scene.get_item_limit"
  32.  
  33.  if you want the remaining slots to show on the custom window:
  34.    
  35.  CUSTOM_WINDOW[index] = "SceneManager.scene.get_remaining_slots"
  36.  
  37.  Example: If you want storage 1 to use this:
  38.  
  39.  CUSTOM_WINDOW[1] = "SceneManager.scene.get_remaining_slots"
  40.  
  41.  The 0 indexed setting will be the one used by default
  42.  by any storage that you open that doesn't have it's own
  43.  settings defined. So don't remove it.
  44.  
  45.  Copy paste the setting constants and modify the index to the
  46.  storage number that you want, then modify the values
  47.  
  48.  For example:
  49.  
  50.  This would be the limit for storage 1
  51.  
  52.  ITEM_TOTAL_LIMIT[1] = 10
  53.  
  54.  Do that for every setting that you want to change
  55.  for a particular storage
  56.  
  57. ======================================================
  58.  Compatibility
  59. ======================================================
  60.  
  61.  Overwrites the Shared Stash's can_store and Process
  62.  Digits methods
  63.  
  64. ======================================================
  65.  Terms and Conditions
  66. ======================================================
  67.  
  68.  View it here: http://lescripts.wordpress.com/terms-and-conditions/
  69.  
  70. ======================================================
  71. =end
  72.  
  73.  
  74. module ADIK
  75.   module SHARED_STORAGE
  76.     #Important:  Do not remove!
  77.     #======================================================
  78.     ITEM_TOTAL_LIMIT = []
  79.     #======================================================
  80.    
  81.     ITEM_TOTAL_LIMIT[0] = "1"
  82.   end
  83. end
  84.  
  85. class Scene_SharedStorage
  86.  
  87.   def get_remaining_slots
  88.     total = 0
  89.     $shared_storage.each_key do |key|
  90.       if key[0] == @storage_number
  91.         total += $shared_storage[key]
  92.       end
  93.     end
  94.     limit = ADIK::SHARED_STORAGE::ITEM_TOTAL_LIMIT[@storage_number]
  95.     limit = ADIK::SHARED_STORAGE::ITEM_TOTAL_LIMIT[0] if limit.nil?
  96.     return eval(limit) - total
  97.   end
  98.  
  99.   def get_item_limit
  100.     item = get_item
  101.     begin
  102.       return $shared_storage[[@storage_number,item.class.to_s,item.id]] + get_remaining_slots
  103.     rescue
  104.       return get_remaining_slots
  105.     end
  106.   end
  107.  
  108.   def get_item_limit_ex(item)
  109.     begin
  110.       return $shared_storage[[@storage_number,item.class.to_s,item.id]] + get_remaining_slots
  111.     rescue
  112.       return get_remaining_slots
  113.     end
  114.   end
  115.  
  116.   #Overwrites the original
  117.   def can_store(item)
  118.     if @ss_category == :deposit
  119.       numb = ADIK::SHARED_STORAGE::MAX_ITEM_NUMBER[@storage_number]
  120.       numb = ADIK::SHARED_STORAGE::MAX_ITEM_NUMBER[0] if numb.nil?
  121.       if numb == "SceneManager.scene.get_item_limit"
  122.         numb = get_item_limit_ex(item)
  123.       else
  124.         numb = eval(numb)
  125.       end
  126.       begin
  127.         numb -= $shared_storage[[@storage_number,item.class.to_s,item.id]]
  128.       rescue
  129.       end
  130.       return numb > 0
  131.     else
  132.       numb = $game_party.item_number(item)
  133.       return numb < $game_party.max_item_number(item)
  134.     end
  135.   end
  136.  
  137. end
  138.  
  139. class Window_NumberInput_SS
  140.  
  141.   #Overwrites the original
  142.   def process_digit_change
  143.     return unless active
  144.     if Input.repeat?(:UP) || Input.repeat?(:DOWN)
  145.       Sound.play_cursor
  146.       place = 10 ** (@digits_max - 1 - @index)
  147.       n = @number / place % 10
  148.       @number -= n * place
  149.       n = (n + 1) % 10 if Input.repeat?(:UP)
  150.       n = (n + 9) % 10 if Input.repeat?(:DOWN)
  151.       @number += n * place
  152.       if @category == :deposit
  153.         item = @item
  154.         numb = ADIK::SHARED_STORAGE::MAX_ITEM_NUMBER[$shared_storage_number]
  155.         numb = ADIK::SHARED_STORAGE::MAX_ITEM_NUMBER[0] if numb.nil?
  156.         if numb == "SceneManager.scene.get_item_limit"
  157.           numb = SceneManager.scene.get_item_limit_ex(item)
  158.         else
  159.           numb = eval(numb)
  160.         end
  161.         begin
  162.           numb -= $shared_storage[[$shared_storage_number,@item.class.to_s,@item.id]]
  163.         rescue
  164.         end
  165.         @number = [@number,$game_party.item_number(@item),numb].min
  166.       else
  167.         amount = $shared_storage[[$shared_storage_number,@item.class.to_s,@item.id]]
  168.         limit = $game_party.max_item_number(@item)- $game_party.item_number(@item)
  169.         @number = [@number,amount,limit].min
  170.       end
  171.       refresh
  172.     end
  173.   end
  174.  
  175. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement