Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2011
1,066
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 9.86 KB | None | 0 0
  1. #===============================================================================
  2. #
  3. # Shanghai Simple Script - Pick Item Event
  4. # Last Date Updated: 2010.05.25
  5. # Level: Easy
  6. #
  7. # This script prompts open a window to allow the player to select an item,
  8. # weapon, or armor from the inventory to give the NPC, show the NPC, or whatever
  9. # floats your boat. Works only on the map.
  10. #===============================================================================
  11. # Instructions
  12. # -----------------------------------------------------------------------------
  13. # To install this script, open up your script editor and copy/paste this script
  14. # to an open slot below ▼ Materials but above ▼ Main. Remember to save.
  15. #
  16. # These commands go into the script call event. Use any one of these.
  17. #   $game_variables[1] = pick_item_event
  18. #   $game_variables[1] = pick_weapon_event
  19. #   $game_variables[1] = pick_armor_event
  20. #
  21. # This will return the selected item's item ID, weapon ID, or armor ID to the
  22. # game variable you stored. 0 is returned if the player cancels.
  23. #
  24. # <key item>
  25. # Place this tagin the noteboxes of your items, weapons, or armors to make
  26. # you unable to select those items for the pick item event.
  27. #===============================================================================
  28.  
  29. $imported = {} if $imported == nil
  30. $imported["PickItemEvent"] = true
  31.  
  32. module SSS
  33.   # This sets how many items will be shown by rows and columns.
  34.   PICK_ITEM_ROWS = 8
  35.   PICK_ITEM_COLS = 8
  36. end
  37.  
  38. #==============================================================================
  39. # RPG::BaseItem
  40. #==============================================================================
  41.  
  42. class RPG::BaseItem
  43.   #--------------------------------------------------------------------------
  44.   # key_item
  45.   #--------------------------------------------------------------------------
  46.   def key_item
  47.     return @key_item if @key_item != nil
  48.     @key_item = false
  49.     self.note.split(/[\r\n]+/).each { |line|
  50.       case line
  51.       when /<(?:KEY_ITEM|key item)>/i
  52.         @key_item = true
  53.       end
  54.     }
  55.     return @key_item
  56.   end
  57. end
  58.  
  59. #==============================================================================
  60. # ** Game_Interpreter
  61. #==============================================================================
  62.  
  63. class Game_Interpreter
  64.   #--------------------------------------------------------------------------
  65.   # * Pick Item Event
  66.   #--------------------------------------------------------------------------
  67.   def pick_item_event
  68.     return 0 unless $scene.is_a?(Scene_Map)
  69.     return $scene.pick_item_event(:item)
  70.   end
  71.   #--------------------------------------------------------------------------
  72.   # * Pick Weapon Event
  73.   #--------------------------------------------------------------------------
  74.   def pick_weapon_event
  75.     return 0 unless $scene.is_a?(Scene_Map)
  76.     return $scene.pick_item_event(:weapon)
  77.   end
  78.   #--------------------------------------------------------------------------
  79.   # * Pick Armor Event
  80.   #--------------------------------------------------------------------------
  81.   def pick_armor_event
  82.     return 0 unless $scene.is_a?(Scene_Map)
  83.     return $scene.pick_item_event(:armor)
  84.   end
  85. end
  86.  
  87. #==============================================================================
  88. # ** Window_Pick_Item
  89. #==============================================================================
  90.  
  91. class Window_Pick_Item < Window_Selectable
  92.   #--------------------------------------------------------------------------
  93.   # * initialize
  94.   #--------------------------------------------------------------------------
  95.   def initialize(type)
  96.     @type = type
  97.     w = SSS::PICK_ITEM_COLS * 24 + 32
  98.     x = Graphics.width - w
  99.     h = [SSS::PICK_ITEM_ROWS * 24 + 32, Graphics.height - 184].min
  100.     y = Graphics.height - h - 128
  101.     super(x, y, w, h)
  102.     self.index = 0
  103.     self.openness = 0
  104.     @column_max = SSS::PICK_ITEM_COLS
  105.     @spacing = 0
  106.     refresh
  107.   end
  108.   #--------------------------------------------------------------------------
  109.   # * Item
  110.   #--------------------------------------------------------------------------
  111.   def item
  112.     return @data[self.index]
  113.   end
  114.   #--------------------------------------------------------------------------
  115.   # * Refresh
  116.   #--------------------------------------------------------------------------
  117.   def refresh
  118.     @data = []
  119.     case @type
  120.     when :item, :items
  121.       for item in $game_party.items
  122.         next unless item.is_a?(RPG::Item)
  123.         @data.push(item) if include?(item)
  124.       end
  125.     when :weapon, :weapons
  126.       for item in $game_party.items
  127.         next unless item.is_a?(RPG::Weapon)
  128.         @data.push(item) if include?(item)
  129.       end
  130.     when :armor, :armors, :armour, :armours
  131.       for item in $game_party.items
  132.         next unless item.is_a?(RPG::Armor)
  133.         @data.push(item) if include?(item)
  134.       end
  135.     end
  136.     @item_max = @data.size
  137.     create_contents
  138.     for i in 0...@item_max
  139.       draw_item(i)
  140.     end
  141.   end
  142.   #--------------------------------------------------------------------------
  143.   # * Include?
  144.   #--------------------------------------------------------------------------
  145.   def include?(item)
  146.     return false if item.nil?
  147.     return true
  148.   end
  149.   #--------------------------------------------------------------------------
  150.   # * Draw Item
  151.   #--------------------------------------------------------------------------
  152.   def draw_item(index)
  153.     rect = item_rect(index)
  154.     self.contents.clear_rect(rect)
  155.     item = @data[index]
  156.     unless item.nil?
  157.       icon = item.icon_index
  158.       draw_icon(icon, rect.x, rect.y, enabled?(item))
  159.       draw_item_amount(item, rect.clone)
  160.     end
  161.   end
  162.   #--------------------------------------------------------------------------
  163.   # * Enabled?
  164.   #--------------------------------------------------------------------------
  165.   def enabled?(item)
  166.     return false if item.nil?
  167.     return false if item.key_item
  168.     return true
  169.   end
  170.   #--------------------------------------------------------------------------
  171.   # * Draw Item Amount
  172.   #--------------------------------------------------------------------------
  173.   def draw_item_amount(item, rect)
  174.     self.contents.font.size = 12
  175.     number = $game_party.item_number(item)
  176.     self.contents.font.color.alpha = enabled?(item) ? 255 : 128
  177.     self.contents.draw_text(rect.x, rect.y + WLH/3, 24, WLH * 2/3, number, 2)
  178.   end
  179. end
  180.  
  181. #==============================================================================
  182. # ** Window_Pick_Item_Help
  183. #==============================================================================
  184.  
  185. class Window_Pick_Item_Help < Window_Base
  186.   #--------------------------------------------------------------------------
  187.   # * Initialize
  188.   #--------------------------------------------------------------------------
  189.   def initialize(pick_item_window)
  190.     @pick_item_window = pick_item_window
  191.     y = @pick_item_window.y - 56
  192.     w = [@pick_item_window.width, 200].max
  193.     x = Graphics.width - w
  194.     super(x, y, w, 56)
  195.     self.openness = 0
  196.     refresh
  197.   end
  198.   #--------------------------------------------------------------------------
  199.   # * Update
  200.   #--------------------------------------------------------------------------
  201.   def update
  202.     super
  203.     refresh if @last_item != @pick_item_window.item
  204.   end
  205.   #--------------------------------------------------------------------------
  206.   # * Refresh
  207.   #--------------------------------------------------------------------------
  208.   def refresh
  209.     self.contents.clear
  210.     item = @last_item = @pick_item_window.item
  211.     draw_icon(item.icon_index, 0, 0)
  212.     self.contents.draw_text(24, 0, contents.width - 24, WLH, item.name)
  213.   end
  214. end
  215.  
  216. #==============================================================================
  217. # ** Scene_Map
  218. #==============================================================================
  219.  
  220. class Scene_Map < Scene_Base
  221.   #--------------------------------------------------------------------------
  222.   # * Termination Processing
  223.   #--------------------------------------------------------------------------
  224.   alias terminate_sss_pick_item_event terminate unless $@
  225.   def terminate
  226.     unless @pick_item_window.nil?
  227.       @pick_item_window.dispose
  228.       @pick_item_window = nil
  229.       @pick_item_help.dispose
  230.       @pick_item_help = nil
  231.     end
  232.     terminate_sss_pick_item_event
  233.   end
  234.   #--------------------------------------------------------------------------
  235.   # * Pick Item Event
  236.   #--------------------------------------------------------------------------
  237.   def pick_item_event(type = :item)
  238.     case type
  239.     when :item, :items, :weapon, :weapons, :armor, :armors, :armour, :armours
  240.       @pick_item_window = Window_Pick_Item.new(type)
  241.       @pick_item_help = Window_Pick_Item_Help.new(@pick_item_window)
  242.     else
  243.       return 0
  244.     end
  245.     value = 0
  246.     @pick_item_window.open
  247.     @pick_item_help.open
  248.     loop do
  249.       update_basic
  250.       @pick_item_window.update
  251.       @pick_item_help.update
  252.       if Input.trigger?(Input::B)
  253.         Sound.play_cancel
  254.         value = 0
  255.         break
  256.       elsif Input.trigger?(Input::C)
  257.         item = @pick_item_window.item
  258.         if @pick_item_window.enabled?(item)
  259.           Sound.play_decision
  260.           value = item.id
  261.           break
  262.         else
  263.           Sound.play_buzzer
  264.         end
  265.       end
  266.     end
  267.     @pick_item_window.close
  268.     @pick_item_help.close
  269.     loop do
  270.       update_basic
  271.       @pick_item_window.update
  272.       @pick_item_help.update
  273.       break if @pick_item_window.openness == 0
  274.     end
  275.     @pick_item_window.dispose
  276.     @pick_item_window = nil
  277.     @pick_item_help.dispose
  278.     @pick_item_help = nil
  279.     return value
  280.   end
  281. end
  282.  
  283. #===============================================================================
  284. #
  285. # END OF FILE
  286. #
  287. #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement