Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- #
- # Shanghai Simple Script - Pick Item Event
- # Last Date Updated: 2010.05.25
- # Level: Easy
- #
- # This script prompts open a window to allow the player to select an item,
- # weapon, or armor from the inventory to give the NPC, show the NPC, or whatever
- # floats your boat. Works only on the map.
- #===============================================================================
- # Instructions
- # -----------------------------------------------------------------------------
- # To install this script, open up your script editor and copy/paste this script
- # to an open slot below ▼ Materials but above ▼ Main. Remember to save.
- #
- # These commands go into the script call event. Use any one of these.
- # $game_variables[1] = pick_item_event
- # $game_variables[1] = pick_weapon_event
- # $game_variables[1] = pick_armor_event
- #
- # This will return the selected item's item ID, weapon ID, or armor ID to the
- # game variable you stored. 0 is returned if the player cancels.
- #
- # <key item>
- # Place this tagin the noteboxes of your items, weapons, or armors to make
- # you unable to select those items for the pick item event.
- #===============================================================================
- $imported = {} if $imported == nil
- $imported["PickItemEvent"] = true
- module SSS
- # This sets how many items will be shown by rows and columns.
- PICK_ITEM_ROWS = 8
- PICK_ITEM_COLS = 8
- end
- #==============================================================================
- # RPG::BaseItem
- #==============================================================================
- class RPG::BaseItem
- #--------------------------------------------------------------------------
- # key_item
- #--------------------------------------------------------------------------
- def key_item
- return @key_item if @key_item != nil
- @key_item = false
- self.note.split(/[\r\n]+/).each { |line|
- case line
- when /<(?:KEY_ITEM|key item)>/i
- @key_item = true
- end
- }
- return @key_item
- end
- end
- #==============================================================================
- # ** Game_Interpreter
- #==============================================================================
- class Game_Interpreter
- #--------------------------------------------------------------------------
- # * Pick Item Event
- #--------------------------------------------------------------------------
- def pick_item_event
- return 0 unless $scene.is_a?(Scene_Map)
- return $scene.pick_item_event(:item)
- end
- #--------------------------------------------------------------------------
- # * Pick Weapon Event
- #--------------------------------------------------------------------------
- def pick_weapon_event
- return 0 unless $scene.is_a?(Scene_Map)
- return $scene.pick_item_event(:weapon)
- end
- #--------------------------------------------------------------------------
- # * Pick Armor Event
- #--------------------------------------------------------------------------
- def pick_armor_event
- return 0 unless $scene.is_a?(Scene_Map)
- return $scene.pick_item_event(:armor)
- end
- end
- #==============================================================================
- # ** Window_Pick_Item
- #==============================================================================
- class Window_Pick_Item < Window_Selectable
- #--------------------------------------------------------------------------
- # * initialize
- #--------------------------------------------------------------------------
- def initialize(type)
- @type = type
- w = SSS::PICK_ITEM_COLS * 24 + 32
- x = Graphics.width - w
- h = [SSS::PICK_ITEM_ROWS * 24 + 32, Graphics.height - 184].min
- y = Graphics.height - h - 128
- super(x, y, w, h)
- self.index = 0
- self.openness = 0
- @column_max = SSS::PICK_ITEM_COLS
- @spacing = 0
- refresh
- end
- #--------------------------------------------------------------------------
- # * Item
- #--------------------------------------------------------------------------
- def item
- return @data[self.index]
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- @data = []
- case @type
- when :item, :items
- for item in $game_party.items
- next unless item.is_a?(RPG::Item)
- @data.push(item) if include?(item)
- end
- when :weapon, :weapons
- for item in $game_party.items
- next unless item.is_a?(RPG::Weapon)
- @data.push(item) if include?(item)
- end
- when :armor, :armors, :armour, :armours
- for item in $game_party.items
- next unless item.is_a?(RPG::Armor)
- @data.push(item) if include?(item)
- end
- end
- @item_max = @data.size
- create_contents
- for i in 0...@item_max
- draw_item(i)
- end
- end
- #--------------------------------------------------------------------------
- # * Include?
- #--------------------------------------------------------------------------
- def include?(item)
- return false if item.nil?
- return true
- end
- #--------------------------------------------------------------------------
- # * Draw Item
- #--------------------------------------------------------------------------
- def draw_item(index)
- rect = item_rect(index)
- self.contents.clear_rect(rect)
- item = @data[index]
- unless item.nil?
- icon = item.icon_index
- draw_icon(icon, rect.x, rect.y, enabled?(item))
- draw_item_amount(item, rect.clone)
- end
- end
- #--------------------------------------------------------------------------
- # * Enabled?
- #--------------------------------------------------------------------------
- def enabled?(item)
- return false if item.nil?
- return false if item.key_item
- return true
- end
- #--------------------------------------------------------------------------
- # * Draw Item Amount
- #--------------------------------------------------------------------------
- def draw_item_amount(item, rect)
- self.contents.font.size = 12
- number = $game_party.item_number(item)
- self.contents.font.color.alpha = enabled?(item) ? 255 : 128
- self.contents.draw_text(rect.x, rect.y + WLH/3, 24, WLH * 2/3, number, 2)
- end
- end
- #==============================================================================
- # ** Window_Pick_Item_Help
- #==============================================================================
- class Window_Pick_Item_Help < Window_Base
- #--------------------------------------------------------------------------
- # * Initialize
- #--------------------------------------------------------------------------
- def initialize(pick_item_window)
- @pick_item_window = pick_item_window
- y = @pick_item_window.y - 56
- w = [@pick_item_window.width, 200].max
- x = Graphics.width - w
- super(x, y, w, 56)
- self.openness = 0
- refresh
- end
- #--------------------------------------------------------------------------
- # * Update
- #--------------------------------------------------------------------------
- def update
- super
- refresh if @last_item != @pick_item_window.item
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- self.contents.clear
- item = @last_item = @pick_item_window.item
- draw_icon(item.icon_index, 0, 0)
- self.contents.draw_text(24, 0, contents.width - 24, WLH, item.name)
- end
- end
- #==============================================================================
- # ** Scene_Map
- #==============================================================================
- class Scene_Map < Scene_Base
- #--------------------------------------------------------------------------
- # * Termination Processing
- #--------------------------------------------------------------------------
- alias terminate_sss_pick_item_event terminate unless $@
- def terminate
- unless @pick_item_window.nil?
- @pick_item_window.dispose
- @pick_item_window = nil
- @pick_item_help.dispose
- @pick_item_help = nil
- end
- terminate_sss_pick_item_event
- end
- #--------------------------------------------------------------------------
- # * Pick Item Event
- #--------------------------------------------------------------------------
- def pick_item_event(type = :item)
- case type
- when :item, :items, :weapon, :weapons, :armor, :armors, :armour, :armours
- @pick_item_window = Window_Pick_Item.new(type)
- @pick_item_help = Window_Pick_Item_Help.new(@pick_item_window)
- else
- return 0
- end
- value = 0
- @pick_item_window.open
- @pick_item_help.open
- loop do
- update_basic
- @pick_item_window.update
- @pick_item_help.update
- if Input.trigger?(Input::B)
- Sound.play_cancel
- value = 0
- break
- elsif Input.trigger?(Input::C)
- item = @pick_item_window.item
- if @pick_item_window.enabled?(item)
- Sound.play_decision
- value = item.id
- break
- else
- Sound.play_buzzer
- end
- end
- end
- @pick_item_window.close
- @pick_item_help.close
- loop do
- update_basic
- @pick_item_window.update
- @pick_item_help.update
- break if @pick_item_window.openness == 0
- end
- @pick_item_window.dispose
- @pick_item_window = nil
- @pick_item_help.dispose
- @pick_item_help = nil
- return value
- end
- end
- #===============================================================================
- #
- # END OF FILE
- #
- #===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement