Advertisement
Vlue

Advanced Select Item

Nov 6th, 2013
2,500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.88 KB | None | 0 0
  1. #Advanced Select Item v1.1.1
  2. #----------#
  3. #Features: Let's you decide what items appear in Select Key Item.
  4. #
  5. #Usage:    Set up category in KEYITEM_CATEGORY as needed and use the supplied
  6. #           functions to determine the behaviour of Select Key Item in game.
  7. #
  8. #          keyitem_category(id)   - Determines what category is ued
  9. #          keyitem_column(value)  - Sets the number of columns to be displayed
  10. #          keyitem_height(value)  - Sets the number of rows to be displayed
  11. #
  12. #----------#
  13. #-- Script by: V.M of D.T
  14. #
  15. #- Questions or comments can be:
  16. #    given by email: sumptuaryspade@live.ca
  17. #    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
  18. #   All my other scripts and projects can be found here: http://daimonioustails.weebly.com/
  19. #
  20. #- Free to use in any project with credit given, donations always welcome!
  21.  
  22. #Select Key Item defaults: [category,column,height)
  23. $key_item_details = [0,2,4]
  24.  
  25. #The fun parts! Setting the categories. Less simple. It goes like this:
  26. #
  27. #      id => ["mod",[ [:symbol,condition,inventory] ... ] ] ],
  28. #
  29. #  You can add as many comparisons as you want, seperated by a comma
  30. #   There are examples below to show you how to do it, and never fear
  31. #   to ask questions!
  32. #
  33. # "mod" is either "&" or "|", where "&" will show each item that
  34. #   satisfies every comparison, and "|" will show each item that
  35. #   satisfies at least one comparison
  36. #
  37. # Options for :symbol include:
  38. #   :weapon, :armor, :item, :key_item, :note, :script
  39. #
  40. # Condition is what determines if the item makes it to the list!
  41. #  For :weapon, :armor, :item, and :key_item, condition is true or false.
  42. #  For :note, it's whatever you want, and if that is found in the note box of
  43. #    the item, then it's included! (That's right, you can make your own notetags)
  44. #  For :script, it's whatever script call you want it to be
  45.  
  46. #This variable will store whether the chosen item was a weapon, armor or item
  47. #And will be either 0 for weapon, 1 for armor, or 2 for item
  48. SECONDARY_KI_VARIABLE = 10
  49.  
  50. KEYITEM_CATEGORY = {
  51.    0 => ["&",[[:key_item, true]]],
  52.    1 => ["|",[[:weapon, true],[:note, "<is_tool>"]]],
  53.    2 => ["&",[[:note, "<is_tool>"]]],
  54.    3 => ["&",[[:script, "item.params[2] > 15", true]]],
  55.    }
  56.  
  57.  
  58. class Window_KeyItem
  59.   alias ki_start start
  60.   def start
  61.     make_item_list
  62.     self.height = $key_item_details[2]*line_height
  63.     ki_start
  64.   end
  65.   def include?(item,id)
  66.     return false if KEYITEM_CATEGORY[$key_item_details[0]].nil?
  67.     begin
  68.       return false if item.nil?
  69.       symbol = ki_symbol(id)
  70.       extra = param(id)
  71.       case symbol
  72.       when :weapon
  73.         if extra
  74.           return true if item.is_a?(RPG::Weapon)
  75.         else
  76.           return true if !item.is_a?(RPG::Weapon)
  77.         end
  78.       when :armor
  79.         if extra
  80.           return true if item.is_a?(RPG::Armor)
  81.         else
  82.           return true if !item.is_a?(RPG::Armor)
  83.         end
  84.       when :item
  85.         if extra
  86.           return true if item.is_a?(RPG::Item)
  87.         else
  88.           return true if !item.is_a?(RPG::Item)
  89.         end
  90.       when :key_item
  91.         if extra
  92.           return true if item.is_a?(RPG::Item) && item.key_item
  93.         else
  94.           return true if !item.is_a?(RPG::Item) && !item.key_item
  95.         end
  96.       when :note
  97.         #msgbox(extra)
  98.         return true if item.note.include?(extra)
  99.       when :script
  100.         return true if eval(extra)
  101.       end
  102.       return false
  103.     rescue
  104.       return false
  105.     end
  106.   end
  107.   def make_item_list
  108.     @data = nil
  109.     if !category.nil?
  110.       category.each_index do |id|
  111.         if all_items?(id)
  112.           weapon = $data_weapons.select {|item| include?(item,id) }
  113.           armor = $data_armors.select {|item| include?(item,id) }
  114.           items = $data_items.select {|item| include?(item,id) }
  115.           if @data.nil?
  116.             @data = weapon + armor + items
  117.           else
  118.             if modifier == "&"
  119.               @data & weapon
  120.               @data & armor
  121.               @data & items
  122.             elsif modifier == "|"
  123.               @data | weapon
  124.               @data | armor
  125.               @data | items
  126.             else
  127.               @data = weapon + armor + items
  128.             end
  129.           end
  130.         else
  131.           items = $game_party.all_items.select {|item| include?(item,id) }
  132.           if @data.nil?
  133.             @data = items
  134.           else
  135.             if modifier == "&"
  136.               @data = @data & items
  137.             elsif modifier == "|"
  138.               @data = @data | items
  139.             else
  140.               @data += items
  141.             end
  142.           end
  143.         end
  144.       end
  145.     else
  146.       @data = $game_party.all_items.select {|item| include?(item,0) }
  147.     end
  148.   end
  149.   def enable?(item)
  150.     return true
  151.   end
  152.   def col_max
  153.     return $key_item_details[1]
  154.   end
  155.   def category
  156.     KEYITEM_CATEGORY[$key_item_details[0]][1]
  157.   end
  158.   def ki_symbol(id)
  159.     KEYITEM_CATEGORY[$key_item_details[0]][1][id][0]
  160.   end
  161.   def param(id)
  162.     KEYITEM_CATEGORY[$key_item_details[0]][1][id][1]
  163.   end
  164.   def all_items?(id)
  165.     KEYITEM_CATEGORY[$key_item_details[0]][1][id][2]
  166.   end
  167.   def modifier
  168.     KEYITEM_CATEGORY[$key_item_details[0]][0]
  169.   end
  170.   def on_ok
  171.     result = item ? item.id : 0
  172.     $game_variables[$game_message.item_choice_variable_id] = result
  173.     $game_variables[SECONDARY_KI_VARIABLE] = 0 if item.is_a?(RPG::Weapon)
  174.     $game_variables[SECONDARY_KI_VARIABLE] = 1 if item.is_a?(RPG::Armor)
  175.     $game_variables[SECONDARY_KI_VARIABLE] = 2 if item.is_a?(RPG::Item)
  176.     close
  177.   end
  178. end
  179.  
  180. class Game_Interpreter
  181.   def keyitem_category(id)
  182.     $key_item_details[0] = id
  183.   end
  184.   def keyitem_column(id)
  185.     $key_item_details[1] = id
  186.   end
  187.   def keyitem_height(id)
  188.     $key_item_details[2] = id
  189.   end
  190. end
  191.  
  192. class RPG::BaseItem
  193.   def ==(object)
  194.     return false if object.nil?
  195.     self.name == object.name && self.id == object.id
  196.   end
  197. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement