[XP] Chrono Cross Key Items

Started by G_G, December 28, 2012, 11:30:22 am

Previous topic - Next topic

G_G

December 28, 2012, 11:30:22 am Last Edit: November 15, 2019, 11:32:25 pm by KK20
Chrono Cross Key Items
Authors: gameus, KK20
Version: 1.3
Type: Event Interaction System
Key Term: Environment Add-on

Introduction

Ever play Chrono Cross? You can bring up a window that displays a list of  your Key Items and you can use them on NPCs and events to have a certain action take place.

Features

  • Display All Items or Marked Items
  • Won't conflict while events are running
  • Use items on NPCs and have something happen

Screenshots

Not applicable. Check out the demo to get a better understanding.

Demo

Demo has outdated script but still provides example and functionaliy. Just be sure to get the updated script from here.
Demo (Box)
Demo (Direct)

Script

v1.3: ShowHide
Code: ruby
#===============================================================================
# Chrono Cross Key Items
# Version 1.3
# Author gameus, KK20
#-------------------------------------------------------------------------------
# Intro:
# Ever play Chrono Cross? You can bring up a window that displays a list of
# your Key Items and you can use them on NPCs and events to have a
# certain action take place.
#
# Features:
# -Display All Items or Marked Items
# -Won't conflict while events are running
# -Use items on NPCs and have something happen
#
# Instructions:
# This script is pretty much plug-n-play. But you have to decide if you want
# to display All Items or just Key Items. If you just want Key Items, scroll
# down and set "CCKEY_SHOW_ALL_ITEMS" to false. Then be sure to create a
# unique element which will be used as your Key Item Element. Mark any item
# with this element that you want made as a key item. Then set
# "CCKEY_ITEM_ELEMENT" to that element's id.
#
# Using this with Events:
# All it requires is a simple Conditional Branch Script Call.
#  used_item(item_id)
#  -item_id = The id of the item you'd like the event to react to.
# It's a bit hard to explain, but that's why there's a demo.
#
# You can also bring up the window by the script call:
#  select_item
# To list specific items with various elements (and not be restricted to just
# those defined under CCKEY_ITEM_ELEMENT):
#  select_item(1,2,3) # add more or less as you'd like
# You can use an array format if you'd like; it does the same thing:
#  select_item([1,2,3])
#
# Compatibility:
# -Not tested with SDK
# -Shouldn't conflict with anything
#
# Version History:
# 1.0
# -Initial Release
#
# 1.1
# -Allowed multiple item calls in one event page
#
# 1.2
# -Screw Ruby 1.8, that is all, small bug fixed
# -Fixed an input bug as well
#
# 1.3
# -Open the window via script call, and select many elements to list instead of
#  just the one
# -Prevent opening the window freely via a game switch
# -Clean up
#
# Credits:
# gameus ~ For creating the script
# SquareSoft ~ For inspiring the script
# KK20 - For v1.3
#===============================================================================
#------------------------------------------
# Button to bring up Key Item Window
#------------------------------------------
CCKEY_INPUT_BUTTON  = Input::A
#------------------------------------------
# Switch ID to toggle CCKEY_INPUT_BUTTON;
# Set this switch to OFF to disable button
# input from opening the window.
# Set to  0    to permanently disable.
# Set to  true  to always allow input.
#------------------------------------------
CCKEY_SWITCH_TOGGLE  = true
#------------------------------------------
# Whether or not to show entire inventory
# Excludes Weapons and Armors
#------------------------------------------
CCKEY_SHOW_ALL_ITEMS = true
#------------------------------------------
# If above is set to false, this element
# must be applied to any item you'd like
# to show up in the window.
# Note that this is the default, if you
# do not provide elements to select_item
# script call.
#------------------------------------------
CCKEY_ITEM_ELEMENT  = 17

#==============================================================================
# Window_CCKeyItem
#------------------------------------------------------------------------------
#  On map window to display "key items" that can be used with events
#==============================================================================
class Window_CCKeyItems < Window_Selectable
  #----------------------------------------------------------------------------
  # Creates Window
  #----------------------------------------------------------------------------
  def initialize
    super(48, 304, 544, 160)
    self.back_opacity = 160
    self.active = false
    self.visible = false
    @column_max = 2
    @item_types = []
    @fade_in = false
    refresh
  end
  #----------------------------------------------------------------------------
  # Updates Window
  #----------------------------------------------------------------------------
  def update
    super
   
    if @fade_in
      update_fade
      return
    end

    if Input.trigger?(Input::C) && self.active
      $game_system.se_play($data_system.decision_se)
      self.active = false
      self.visible = false
      if selected_item.nil?
        $game_temp.key_item = 0
      else
        $game_temp.key_item = selected_item.id
      end
      $game_temp.message_window_showing = false
      $game_temp.message_proc.call if $game_temp.message_proc
     
    elsif (CCKEY_SWITCH_TOGGLE == true || $game_switches[CCKEY_SWITCH_TOGGLE]) &&
        Input.trigger?(CCKEY_INPUT_BUTTON) &&
        !$game_temp.message_window_showing &&
        !$game_system.map_interpreter.running?
      $game_system.se_play($data_system.decision_se)
      show_window
     
    elsif Input.trigger?(Input::B) && self.active
      $game_system.se_play($data_system.cancel_se)
      self.active = false
      self.visible = false
      $game_temp.key_item = 0
      Input.update
      $game_temp.message_window_showing = false
      $game_temp.message_proc.call if $game_temp.message_proc
    end
  end
 
  #----------------------------------------------------------------------------
  # Fades the window in, only if called from events
  #----------------------------------------------------------------------------
  def update_fade
    self.opacity += 24
    self.contents_opacity += 24
    if self.opacity == 255
      @fade_in = false
      self.active = true
    end
  end
 
  #----------------------------------------------------------------------------
  # Pops up the window
  #----------------------------------------------------------------------------
  def show_window(*args)
    @item_types.clear
    args.each do |param|
      if param == :fade_in
        @fade_in = true
      elsif param.is_a?(Array) || param.is_a?(Integer)
        @item_types << param
      end
    end
    @item_types.flatten!
    if !CCKEY_SHOW_ALL_ITEMS && @item_types.empty?
      @item_types << CCKEY_ITEM_ELEMENT
    end
    refresh
    self.index = 0
    self.active = true unless @fade_in
    self.visible = true
    if @fade_in
      self.opacity = 0
      self.contents_opacity = 0
    end
    $game_temp.message_window_showing = true
  end
 
  #----------------------------------------------------------------------------
  # Refreshes Window
  #----------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @items = []
    for i in 1...$data_items.size
      item = $data_items[i]
      next if !($game_party.item_number(i) > 0)
      if (CCKEY_SHOW_ALL_ITEMS && @item_types.empty?) ||
        !(item.element_set & @item_types).empty?
        @items << item
      end
    end
    @item_max = @items.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  #----------------------------------------------------------------------------
  # Draws Item
  #----------------------------------------------------------------------------
  def draw_item(index)
    item = @items[index]
    x = 4 + index % 2 * (244 + 32)
    y = index / 2 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  end
  #----------------------------------------------------------------------------
  # Returns Selected Item
  #----------------------------------------------------------------------------
  def selected_item
    return @items[self.index]
  end
end

#==============================================================================
# Interpreter (Edit)
#------------------------------------------------------------------------------
#  Added the method "used_item(id)"
#==============================================================================
class Interpreter
  def used_item(id)
    flag = id == $game_temp.key_item
    return flag
  end
 
  alias gg_cckeys_command_end_lat command_end
  def command_end
    $game_temp.key_item = 0 if @main && @event_id > 0
    gg_cckeys_command_end_lat
  end
 
  #--------------------------------------------------------------------------
  # * Select an Item from choice window
  #  item_type
  #    :all - displays every single item in the player's inventory
  #   
  #--------------------------------------------------------------------------
  def select_item(item_elements = 0)
    return unless $scene.is_a?(Scene_Map)
    # Set message end waiting flag and callback
    @message_waiting = true
    $game_temp.message_proc = Proc.new { @message_waiting = false }
    $scene.show_key_item_window(item_elements)
  end
end

#==============================================================================
# Scene_Map (Edit)
#------------------------------------------------------------------------------
#  Modified to add Window_CCKeyItem
#==============================================================================
class Scene_Map
  #----------------------------------------------------------------------------
  # Initializes Map
  #----------------------------------------------------------------------------
  alias gg_main_cckeys_map_lat main
  def main
    @key_window = Window_CCKeyItems.new
    gg_main_cckeys_map_lat
    @key_window.dispose
  end
  #----------------------------------------------------------------------------
  # Updates Map
  #----------------------------------------------------------------------------
  alias gg_update_cckeys_map_lat update
  def update
    @key_window.update
    gg_update_cckeys_map_lat
  end
 
  def show_key_item_window(item_elements = 0)
    @key_window.show_window(:fade_in, item_elements)
  end
 
end

#==============================================================================
# Game_Temp
#------------------------------------------------------------------------------
#  Added @key_item to keep track of the used item.
#==============================================================================
class Game_Temp
  attr_accessor :key_item
end

v1.2: ShowHide
Code: ruby
#===============================================================================
# Chrono Cross Key Items
# Version 1.2
# Author gameus
#-------------------------------------------------------------------------------
# Intro:
# Ever play Chrono Cross? You can bring up a window that displays a list of
# your Key Items and you can use them on NPCs and events to have a
# certain action take place.
#
# Features:
# -Display All Items or Marked Items
# -Won't conflict while events are running
# -Use items on NPCs and have something happen
#
# Instructions:
# This script is pretty much plug-n-play. But you have to decide if you want
# to display All Items or just Key Items. If you just want Key Items, scroll
# down and set "CCKEY_SHOW_ALL_ITEMS" to false. Then be sure to create a
# unique element which will be used as your Key Item Element. Mark any item
# with this element that you want made as a key item. Then set
# "CCKEY_ITEM_ELEMENT" to that element's id.
#
# Using this with Events:
# All it requires is a simple Conditional Branch Script Call.
#   used_item(item_id)
#   -item_id = The id of the item you'd like the event to react to.
# It's a bit hard to explain, but that's why there's a demo.
#
# Compatibility:
# -Not tested with SDK
# -Shouldn't conflict with anything
#
# Version History:
# 1.0
# -Initial Release
#
# 1.1
# -Allowed multiple item calls in one event page
#
# 1.2
# -Screw Ruby 1.8, that is all, small bug fixed
# -Fixed an input bug as well
#
# Credits:
# gameus ~ For creating the script
# SquareSoft ~ For inspiring the script
#===============================================================================
#------------------------------------------
# Button to bring up Key Item Window
#------------------------------------------
CCKEY_INPUT_BUTTON   = Input::A
#------------------------------------------
# Whether or not to show entire inventory
# Excludes Weapons and Armors
#------------------------------------------
CCKEY_SHOW_ALL_ITEMS = true
#------------------------------------------
# If above is set to false, this element
# must be applied to any item you'd like
# to show up in the window
#------------------------------------------
CCKEY_ITEM_ELEMENT   = 17

#==============================================================================
# Window_CCKeyItem
#------------------------------------------------------------------------------
#  On map window to display "key items" that can be used with events
#==============================================================================
class Window_CCKeyItems < Window_Selectable
  #----------------------------------------------------------------------------
  # Creates Window
  #----------------------------------------------------------------------------
  def initialize
    super(48, 304, 544, 160)
    self.back_opacity = 160
    self.active = false
    self.visible = false
    @column_max = 2
    refresh
  end
  #----------------------------------------------------------------------------
  # Updates Window
  #----------------------------------------------------------------------------
  def update
    super
    if Input.trigger?(Input::C) && self.active
      $game_system.se_play($data_system.decision_se)
      self.active = false
      self.visible = false
      if selected_item.nil?
        $game_temp.key_item = 0
      else
        $game_temp.key_item = selected_item.id
      end
      $game_temp.message_window_showing = false
      return
    elsif Input.trigger?(CCKEY_INPUT_BUTTON) &&
        !$game_temp.message_window_showing &&
        !$game_system.map_interpreter.running?
      $game_system.se_play($data_system.decision_se)
      refresh
      self.index = 0
      self.active = true
      self.visible = true
      $game_temp.message_window_showing = true
      return
    elsif Input.trigger?(Input::B) && self.active
      $game_system.se_play($data_system.cancel_se)
      self.active = false
      self.visible = false
      Input.update
      $game_temp.message_window_showing = false
    end
  end
  #----------------------------------------------------------------------------
  # Refreshes Window
  #----------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @items = []
    for i in 1...$data_items.size
      item = $data_items[i]
      next if !($game_party.item_number(i) > 0)
      if item.element_set.include?(CCKEY_ITEM_ELEMENT) || CCKEY_SHOW_ALL_ITEMS
        @items.push(item)
      end
    end
    @item_max = @items.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  #----------------------------------------------------------------------------
  # Draws Item
  #----------------------------------------------------------------------------
  def draw_item(index)
    item = @items[index]
    x = 4 + index % 2 * (244 + 32)
    y = index / 2 * 32
    rect = Rect.new(x, y, self.width / @column_max - 32, 32)
    self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
    bitmap = RPG::Cache.icon(item.icon_name)
    self.contents.blt(x, y + 4, bitmap, Rect.new(0, 0, 24, 24))
    self.contents.draw_text(x + 28, y, 212, 32, item.name, 0)
  end
  #----------------------------------------------------------------------------
  # Returns Selected Item
  #----------------------------------------------------------------------------
  def selected_item
    return @items[self.index]
  end
end

#==============================================================================
# Interpreter (Edit)
#------------------------------------------------------------------------------
#  Added the method "used_item(id)"
#==============================================================================
class Interpreter
  def used_item(id)
    flag = id == $game_temp.key_item
    return flag
  end
 
  alias gg_cckeys_command_end_lat command_end
  def command_end
    $game_temp.key_item = 0
    gg_cckeys_command_end_lat
  end
end

#==============================================================================
# Scene_Map (Edit)
#------------------------------------------------------------------------------
#  Modified to add Window_CCKeyItem
#==============================================================================
class Scene_Map
  #----------------------------------------------------------------------------
  # Initializes Map
  #----------------------------------------------------------------------------
  alias gg_main_cckeys_map_lat main
  def main
    @key_window = Window_CCKeyItems.new
    gg_main_cckeys_map_lat
    @key_window.dispose
  end
  #----------------------------------------------------------------------------
  # Updates Map
  #----------------------------------------------------------------------------
  alias gg_update_cckeys_map_lat update
  def update
    @key_window.update
    gg_update_cckeys_map_lat
  end
end

#==============================================================================
# Game_Temp
#------------------------------------------------------------------------------
#  Added @key_item to keep track of the used item.
#==============================================================================
class Game_Temp
  attr_accessor :key_item
end


Instructions

Instructions are in the script, though they may be a bit confusing. Definitely check out the demo.

Compatibility

Not tested with SDK
Should be compatible with just about everything.

Credits and Thanks

  • gameus ~ For creating the script
  • SquareSoft ~ For creating Chrono Cross which inspired this
  • KK20 ~ For v1.3

Author's Notes

Enjoy my last public script ever. I know I said this before, but I found this gem on my grandmas computer. I think my past self meant to release it. Regardless, I cleaned up the code and am now sharing it with you guys!

Shalaren

Hey is there a way to have this work with Babs?
I cant bring up the window, I tried changing the INPUT_BUTTON but nothing works,
I'm guessing because of Blizz-abs CUSTOM_CONTROLS.
what can I do to have this work with babs?

Thanks in advance :)

KK20

Input::Key['Your_Character_Key_Here'] doesn't work?

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Shalaren

oh dam I forgot its like that, I didn't use the brackets so it kept crashing!

Seriously KK20 thank you for your quick replies :) I really appreciate all your help

G_G

Updated to 1.1.

Fixed an issue where you could only use the "used_item" command one different time per event.

e.g. You can now use two or more different items on an event.

Spoiler: ShowHide

G_G

February 07, 2018, 11:21:29 pm #5 Last Edit: February 07, 2018, 11:31:57 pm by G_G
Fixed a bug. Proper necropost. This is probably the last script for XP I'll ever update. @_@

KK20


Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!