Advertisement
LiTTleDRAgo

[RGSS/2] Multi Use Items

Feb 1st, 2012
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.70 KB | None | 0 0
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  2. # Multi use items
  3. # Version 1.25
  4. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
  5. #
  6. # Do you think it's strange if hero used up entire potion with one gulp?
  7. # This script will make item can be used multiple times
  8. #
  9. # How To Use
  10. #
  11. # For XP
  12. #
  13. #    There are configuration below
  14. #
  15. # For VX
  16. #
  17. #    Type in Note Editor at tab items
  18. #    Multi Use = X
  19. #      
  20. #    Replace X with number
  21. #
  22. # Example
  23. #  
  24. #  Multi Use = 4
  25. #  Then that item can be used 4 times
  26. #
  27. #
  28. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  29.  
  30. module LiTTleDRAgo
  31.  
  32.   Show_Use_String   = 'Used '
  33.   Show_Times_String = ' times. '
  34.  
  35.   def self.multi_use_item(id) # Only for XP
  36.     case id
  37.     when 1,2 then 2 # This means potion & high potion can be used twice
  38.     when 3 then 4
  39.     end
  40.   end  
  41. end
  42. #==============================================================================
  43. # ** Game_Party
  44. #------------------------------------------------------------------------------
  45. #  This class handles the party. It includes information on amount of gold
  46. # and items. The instance of this class is referenced by $game_party.
  47. #==============================================================================
  48. class Game_Party
  49.   #--------------------------------------------------------------------------
  50.   # * Constants
  51.   #--------------------------------------------------------------------------
  52.   VX   = defined?(Window_BattleMessage)
  53.   name =  VX ? "(items, n, include_equip = false)" : "(items, n)"
  54.   eval_text = "
  55.  #--------------------------------------------------------------------------
  56.  # * Gain Items (or lose)
  57.  #--------------------------------------------------------------------------
  58.  def gain_item#{name}
  59.    @multi_use = [] if @multi_use.nil?
  60.    item_id, number = (VX ? items.id : items),item_number(items)
  61.    if item_id > 0
  62.      if multiuse?(item_id) && n > 0
  63.        (0...n).each {|i| @multi_use.push([item_id,multiuse?(item_id)])}
  64.      end
  65.      @items[item_id] = [[number+n,0].max,99].min
  66.      return if !VX
  67.      n += item_number(item_id)
  68.      members.each {|actor|
  69.        while n < 0 && actor.equips.include?(items)
  70.        actor.discard_equip(items);  n += 1  end } if include_equip && n < 0
  71.    end
  72.  end
  73.  #--------------------------------------------------------------------------
  74.  # * Lose Items
  75.  #--------------------------------------------------------------------------
  76.  def lose_item#{name}
  77.    @multi_use = [] if @multi_use.nil?
  78.    item_id, i, xer = (VX ? items.id : items),0, n
  79.    if multiuse?(item_id) && have_multiuse?(item_id) && !$scene.is_a?(Scene_Shop)
  80.      @multi_use.sort! {|a,b|a[1]<=> b[1]}
  81.      for item in @multi_use
  82.        if item[0] == item_id
  83.          @multi_use[i][1]-=1
  84.          if @multi_use[i][1] == 0
  85.            @multi_use.delete(item)
  86.            @items[item_id] = [[item_number(items) -1, 0].max, 99].min
  87.          end
  88.          break
  89.        end
  90.        i+=1
  91.      end
  92.    elsif $scene.is_a?(Scene_Shop) && multiuse?(item_id)
  93.      @multi_use.sort! {|a,b|a[1]<=> b[1]}
  94.      for item in @multi_use
  95.        break if xer == 0
  96.        if item[0] == item_id then  @multi_use.delete_at(i); xer-=1 end
  97.        i+=1
  98.      end
  99.      @items[item_id] = [[item_number(items) -n, 0].max, 99].min
  100.    else
  101.      n = -n
  102.      gain_item#{name}
  103.    end
  104.  end"
  105.   eval(eval_text)
  106.   #--------------------------------------------------------------------------
  107.   # * Have Multiusables?
  108.   #--------------------------------------------------------------------------
  109.   def have_multiuse?(item_id)
  110.     @multi_use = [] if @multi_use.nil?
  111.     @multi_use.each {|item|  return true if item[0] == item_id }
  112.     return false
  113.   end
  114.   #--------------------------------------------------------------------------
  115.   # * Multiusables?
  116.   #--------------------------------------------------------------------------
  117.   def multiuse?(item_id=nil)
  118.     return @multi_use if item_id.nil?
  119.     unless VX
  120.       s = LiTTleDRAgo.multi_use_item(item_id)
  121.       return s ? s.abs : nil
  122.     end
  123.     return LiTTleDRAgo.multi_use_item(item_id) unless VX
  124.     if $data_items[item_id].note =~ /Multi Use = (\d+)/
  125.       return $1.to_i
  126.     end
  127.   end
  128. end
  129.  
  130. if LiTTleDRAgo::Show_Use_String
  131. #==============================================================================
  132. # ** Window_Item / Window_ShopSell
  133. #------------------------------------------------------------------------------
  134. #  This window displays a list of inventory items for the item screen, etc.
  135. #==============================================================================
  136.   for i in 0..1
  137.     kelas = i == 0 ? "Window_Item" : "Window_ShopSell"
  138.     break if defined?(Window_BattleMessage) && i == 1
  139.     eval_text = "
  140.    class #{kelas} < Window_Selectable
  141.      #------------------------------------------------------------------------
  142.      # * Update Help Text
  143.      #------------------------------------------------------------------------
  144.      def update_help
  145.        if $game_party.multiuse?(self.item.id)
  146.          $game_party.multiuse?.each {|item|
  147.            if item[0] == self.item.id then @uses = item[1]; break end }
  148.          times = LiTTleDRAgo::Show_Times_String
  149.          times = '' if times.nil?
  150.          description = LiTTleDRAgo::Show_Use_String + @uses.to_s + '/' +
  151.          $game_party.multiuse?(self.item.id).to_s
  152.          @help_window.set_text(description + times + self.item.description)
  153.        else
  154.          @help_window.set_text(self.item.nil? ? '' : self.item.description)
  155.        end
  156.      end
  157.    end"
  158.     eval(eval_text)
  159.   end
  160. end
  161.  
  162. $multi_use_items = true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement