=begin #=============================================================================== Title: Identify Item Author: Hime Date: Feb 9, 2013 -------------------------------------------------------------------------------- ** Change log Feb 9, 2013 - added support for sorting unknowns - Initial release -------------------------------------------------------------------------------- ** Terms of Use * Free to use in non-commercial projects * Contact me for commercial use * No real support. The script is provided as-is * Will do bug fixes, but no compatibility patches * Features may be requested but no guarantees, especially if it is non-trivial * Preserve this header -------------------------------------------------------------------------------- ** Description This script allows you to implement a system where items are not known unless you identify them somehow. Unidentified items will appear as an unknown item, with an unknown name. All references to these items will appear that way until they have been identified. -------------------------------------------------------------------------------- ** Usage -- identifying items -- Use the following note-tags to indicate how they can be identified. -item is identified through an event. This is just a reminder for you -item is identified on use. -item is identified once it is equipped You can explicitly identify items using script calls: $game_party.identify_item(obj) Where obj is an inventory object (item, weapon, armor, etc) Some convenience methods have been provided in the interpreter identify_item(item_id)) identify_weapon(weapon_id) identify_armor(armor_id) -- sort order -- You can specify how sort items are ordered in the item lists in the configuration. There are three sort options. You can use the following script call to change the unknown sort type $game_party.unknown_sort_type = x The different types are described in the configuration #=============================================================================== =end $imported = {} if $imported.nil? $imported["TH_IdentifyItem"] = true #=============================================================================== # ** Configuration #=============================================================================== module TH module Identify_Item Unknown_Name = "???" # name to display for unknown items Unknown_Icon = 270 # icon to display for unknown items Unknown_Description = "???" # description to display for unknown items # sort method for unknown items. # 0 - no sort # 1 - appear first # 2 - appear last Unknown_Sort_Type = 2 Identify_Regex = //i end end #=============================================================================== # ** Rest of script #=============================================================================== class Game_Interpreter def identify_item(id) $game_party.identify_item($data_items[id]) end def identify_weapon(id) $game_party.identify_item($data_weapons[id]) end def identify_armor(id) $game_party.identify_item($data_armors[id]) end end module RPG class Item def identify_on_use? return @use_identify unless @use_identify.nil? load_notetag_identify_item return @use_identify end def needs_identify? return @needs_identify unless @needs_identify.nil? load_notetag_identify_item return @needs_identify end def load_notetag_identify_item res = self.note.scan(TH::Identify_Item::Identify_Regex).flatten @needs_identify = !res.empty? @use_identify = res.include?("use") end alias :th_identify_item_name :name def name if needs_identify? return $game_party.identified?(self) ? @name : TH::Identify_Item::Unknown_Name else th_identify_item_name end end alias :th_identify_item_icon_index :icon_index def icon_index if needs_identify? return $game_party.identified?(self) ? @icon_index : TH::Identify_Item::Unknown_Icon else th_identify_item_icon_index end end alias :th_identify_item_description :description def description if needs_identify? return $game_party.identified?(self) ? @description : TH::Identify_Item::Unknown_Description else th_identify_item_description end end end class EquipItem def identify_on_equip? return @equip_identify unless @equip_identify.nil? load_notetag_identify_item return @equip_identify end def needs_identify? return @needs_identify unless @needs_identify.nil? load_notetag_identify_item return @needs_identify end def load_notetag_identify_item res = self.note.scan(TH::Identify_Item::Identify_Regex) @needs_identify = !res.empty? @equip_identify = res.include?("equip") end alias :th_identify_item_name :name def name if needs_identify? return $game_party.identified?(self) ? @name : TH::Identify_Item::Unknown_Name else th_identify_item_name end end alias :th_identify_item_icon_index :icon_index def icon_index if needs_identify? return $game_party.identified?(self) ? @icon_index : TH::Identify_Item::Unknown_Icon else th_identify_item_icon_index end end alias :th_identify_item_description :description def description if needs_identify? return $game_party.identified?(self) ? @description : TH::Identify_Item::Unknown_Description else th_identify_item_description end end end end class Game_Unit attr_reader :identified_items # list of items that have been identified attr_accessor :unknown_sort_type # order the unknowns should appear. See docs. alias :th_identify_item_init :initialize def initialize th_identify_item_init init_identify_items @unknown_sort_type = TH::Identify_Item::Unknown_Sort_Type end #----------------------------------------------------------------------------- # New. Hardcoded hashes #----------------------------------------------------------------------------- def init_identify_items @identified_items = {} @identified_items[:item] = {} @identified_items[:weapon] = {} @identified_items[:armor] = {} end #----------------------------------------------------------------------------- # New. Add item to identified list #----------------------------------------------------------------------------- def identify_type(item) return :item if item.is_a?(RPG::Item) return :weapon if item.is_a?(RPG::Weapon) return :armor if item.is_a?(RPG::Armor) end #----------------------------------------------------------------------------- # New. Add item to identified hash #----------------------------------------------------------------------------- def identify_item(item) return unless item @identified_items[identify_type(item)][item.id] = true end #----------------------------------------------------------------------------- # New. Remove item from identified hash #----------------------------------------------------------------------------- def unidentify_item(item) return unless item @identified_items[identify_type(item)].delete(item.id) end #----------------------------------------------------------------------------- # New. Return whether the unit has identified the item or not #----------------------------------------------------------------------------- def identified?(item) return unless item @identified_items[identify_type(item)].include?(item.id) end end class Game_Actor < Game_Battler alias :th_identify_item_use_item :use_item def use_item(item) th_identify_item_use_item(item) $game_party.identify_item(item) if item.is_a?(RPG::Item) && item.identify_on_use? end alias :th_identify_item_change_equip :change_equip def change_equip(slot_id, item) th_identify_item_change_equip(slot_id, item) $game_party.identify_item(item) end end class Window_ItemList < Window_Selectable alias :th_identify_item_make_item_list :make_item_list def make_item_list th_identify_item_make_item_list sort_unknowns end def sort_unknowns case $game_party.unknown_sort_type when 0 return when 1 @data.sort_by! {|item| (item && (!item.needs_identify? || $game_party.identified?(item))) ? 1 : -1 } when 2 @data.sort_by! {|item| (item && (!item.needs_identify? || $game_party.identified?(item))) ? -1 : 1 } end end end