[XP]Chrono Cross Key Items Script Help [SOLVED]

Started by Poptart, August 07, 2015, 05:47:43 am

Previous topic - Next topic

Poptart

August 07, 2015, 05:47:43 am Last Edit: August 08, 2015, 08:46:33 am by Poptart
Hello, I'm just requesting a little help with the script "Chrono Cross Key Items". Everything seems to work nicely with the exception of, if I make two or more conditional branches, only the first one will work. But, I'd like to have an event react differently to different items selected...



Link to script:
http://forum.chaos-project.com/index.php/topic,12727.0.html

Any help would be appreciated..

KK20

The reason is this:

class Interpreter
  def used_item(id)
    flag = id == $game_temp.key_item
    $game_temp.key_item = 0 #<============= This
    return flag
  end
end

The item you select is stored in $game_temp.key_item. Then, when you call used_item the first time, it will clear out the $game_temp.key_item with a zero. Thus, using used_item a second time will compare your ID with a zero...so it will always fail.

You can remove this offending line from the script, but I would suggest that, in all your events using the script call used_item, to put another script call

$game_temp.key_item = 0

somewhere near the end of it.

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!

Poptart


G_G

September 24, 2015, 01:08:13 pm #3 Last Edit: September 24, 2015, 01:30:33 pm by gameus
Okay, it didn't take very long to fix it. I didn't really test it much but I think it should work technically.

Code: ruby
#===============================================================================
# Chrono Cross Key Items
# Version 1.1
# 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
#
# 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
     $game_temp.key_item = selected_item.id
     $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
     $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


EDIT: Just tested it.

Spoiler: ShowHide


Works great. I know the thread was about a month old, but saw it and wanted to fix it. Will update main post now.