SAI Key Item Button

Sailerius

Engineer
Veteran
Joined
Mar 17, 2012
Messages
605
Reaction score
140
First Language
English
Primarily Uses
SAI Key Item Button v1.0

Bishop Myers ("Sailerius")


Introduction

Inspired by Chrono Cross, this script allows you to call the Key Item dialog box at any time on the map. You can make it such that selecting an item from the dialog box will activate an adjacent action button events so that they can respond to the item used.

Features

- Adds the ability to call the key item dialog box at any time with a key

- Allows doing so to cause events to respond

- Stores ID number of used item into a variable for easy checking

How to Use

Just paste it in. Follow the instructions in the script and customize the callback methods to get the effect that you want.

Script



Code:
#==============================================================================
#
# ▼ SAI Key Item Button v1.0
# -- Last Updated: 2012.04.22
# -- Author: Bishop Myers ("Sailerius")
# -- Requires: n/a
#
#==============================================================================
$imported = {} if $imported.nil?
$imported["SAI-KeyItemButton"] = true
#==============================================================================
# ▼ Updates
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# 2012.01.12 - First release
#
#==============================================================================
# ▼ Introduction
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# Inspired by Chrono Cross, this script allows you to call the Key Item dialog
# box at any time on the map. You can make it such that selecting an item from
# the dialog box will activate an adjacent action button events so that they
# can respond to the item used.
#
#==============================================================================
# ▼ 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.
#
# To customize the script, make any edits you wish to the callback methods
# defined below.
#
# key_item_trigger?
#   When this method returns true, the key item dialog will be called. By
#   default, it checks if the X button (A key) is triggered. Feel free to change
#   this to a different button, or give it a different condition altogether.
#
# key_item_variable
#   This method returns an integer which tells the script which variable to
#   save the ID number of the key item used to. By default, it returns 2,
#   meaning that using a key item will save its ID to variable #2.
#
# call_action_events_after_key_item_dialog?
#   This method returns true if using a key item from the key item dialog should
#   trigger action button events. By default, it returns true.
#
# call_action_events_after_key_item_dialog_cancelled?
#   This method returns true if cancelling the key item dialog should trigger
#   action button events. By default, it returns false.
#
# can_call_key_item_dialog_while_moving?
#   This method returns true if the player should be able to call the key item
#   dialog while moving. By default, it returns false.
#==============================================================================
# ▼ Compatibility
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# This script should be fully compatible with any other well-written Ace
# scripts.
#
#===============================================================================
# ■ Game_Player
#===============================================================================
class Game_Player < Game_Character
  #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  # ▼ Callback Methods
  #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  # These methods are designed to be customized and redefined to suit the needs
  # of your project. They are called throughout the script, so it is crucial
  # that you do not change the method name or arguments unless you know what
  # you're doing.
  #-----------------------------------------------------------------------------
  # Function to determine what condition triggers the key item dialog
  #-----------------------------------------------------------------------------
  def key_item_trigger?
	Input.trigger?(:X)
  end
  #-----------------------------------------------------------------------------
  # Variable number in which to store the key item the player selects
  #-----------------------------------------------------------------------------
  def key_item_variable
	return 2
  end
  #-----------------------------------------------------------------------------
  # Should adjacent action events be called if the key item dialog is called?
  #-----------------------------------------------------------------------------
  def call_action_events_after_key_item_dialog?
	return true
  end
  #-----------------------------------------------------------------------------
  # Should adjacent action events be called if the key item dialog was cancelled?
  #-----------------------------------------------------------------------------
  def call_action_events_after_key_item_dialog_cancelled?
	return false
  end
  #-----------------------------------------------------------------------------
  # Should the player be able to use the key item dialog while moving?
  #-----------------------------------------------------------------------------
  def can_call_key_item_dialog_while_moving?
	return false
  end
#===============================================================================
# ▼ Editing below is not intended for beginners. Change at your own risk.
#===============================================================================
  #-----------------------------------------------------------------------------
  # Adds functionality to check for key item button
  #-----------------------------------------------------------------------------
  alias :gameplayer_update_saikib :update
  def update
	gameplayer_update_saikib
	if ((movable? || can_call_key_item_dialog_while_moving?) && key_item_trigger?)
	  setup_item_choice(key_item_variable)
	end  
  end
  #-----------------------------------------------------------------------------
  # Brings up the key item choice dialog and sets result to variable_number
  #-----------------------------------------------------------------------------
  def setup_item_choice(variable_number)
	$game_message.item_choice_variable_id = variable_number
  end
end
#===============================================================================
# ■ Window_KeyItem
#===============================================================================
class Window_KeyItem < Window_ItemList
  #-----------------------------------------------------------------------------
  # Added functionality to call action events after an item is selected
  #-----------------------------------------------------------------------------
  alias :window_keyitem_on_ok_saikib :on_ok
  def on_ok
	window_keyitem_on_ok_saikib
	if $game_player.call_action_events_after_key_item_dialog?
	  $game_player.check_action_event
	end
  end
  #-----------------------------------------------------------------------------
  # Added functionality to call action events after cancelling the key item dialog
  #-----------------------------------------------------------------------------
  alias :window_keyitem_on_cancel_saikib :on_cancel
  def on_cancel
	window_keyitem_on_cancel_saikib
	if $game_player.call_action_events_after_key_item_dialog_cancelled?
	  $game_player.check_action_event
	end
  end
end
FAQ

No questions yet asked.
 

servantb7

Servantb7
Veteran
Joined
Apr 2, 2012
Messages
263
Reaction score
36
First Language
English
Primarily Uses
RMMV
Excellent script. Very useful for exploration.
 

Rift

Villager
Member
Joined
Apr 30, 2012
Messages
6
Reaction score
1
First Language
English&Tagalog
Primarily Uses
This is brilliant, thanks for sharing, Sailerius. I want the player to think about how to interact with the environment and where to use key items, as opposed to just walking up to things and randomly pressing the action button at them until the key item selection comes up. This provides that functionality perfectly. :D

Edit: Hey Sailerius, do you know if it would be difficult to implement an on screen window in the bottom left of the screen that shows which key item is currently 'equipped' / stored in the item id variable? Something like this (game screenshot from Google Image search) :

 
Last edited by a moderator:

Latest Threads

Latest Posts

Latest Profile Posts

I haven't make anything new yet, but I'm back addicted to writing some MZ plugins. Man, I wish I have more free time like I did 5 years ago.
Holy cow... work is demanding and I'm back in college. I'm kind of scared of my dad right now after the incident, but at least I don't live with him all the time. Anyway, working on Fandom Scouts and my FNAF character set. The FNAF sprites are actually going to be used in the game... unfortunately the enemy sprites are FNAF World traces, so no sharing those.
The honeymoon period is over with Cyberpunk 2077, It sadly doesnt live up to the hype, pretty graphics arent everything (especially when I cant even do something as simple as changing the radio station over!). Replaying Breath of the wild has reminded me what a good game really looks like, plus that one has good glitches!....

Forum statistics

Threads
107,689
Messages
1,031,461
Members
139,805
Latest member
oo_K_DASH_oo
Top