#==============================================================================
#
# HERETIC'S CONTROL SELF SWITCHES ANYWHERE
# Version 1.0
# Monday, September 9th, 2013
#
#==============================================================================
#
# The Default Game Engine allows you to change Game Switches from a Move Route
# but does NOT have anything to allow you to change Self Switches. This
# script will allow you to Check and Change ANY Self Switches for Any Event
# on your Current Map.
#
# * get_self_switch( Letter, event_id)
# - Letter is 'A', 'B', 'C', or 'D', WITH Quotes, Upper case doesnt matter
# - Returns True if Switch is ON
# - Returns False if Switch is OFF
# * set_self_switch( Letter, On or Off, event_id)
# - Letter is 'A', 'B', 'C', or 'D', WITH Quotes, Upper case doesnt matter
# - Sets Switch Letter to Value (true or false, 'On' and 'Off' okay too)
#
# The intent of this script is to save you from always having to use
# Game Switches by allowing you more access to Self Switches. Too
# many Game Switches can make your game excessively comples for things
# that will most likely only relate to Events on One Map. If you need
# to check Switches across Game Maps or during Battle, then the use of
# Game Switches is a better idea.
#
# NOTE: The script calls in Event -> Script and Move Route -> Script are
# quite similar, but not exactly the same. It may be easiest for you to
# use this script by calling ALL of the arguments.
#
# get_self_switch can use TWO Arguments
# set_self_switch can use THREE Arguments
#
# If you have any difficulty with the Script Calls, just use all arguments
# and that will usually solve your problems. I tried to set up this script
# to provide lots of error messages that clearly explain what went wrong
# should something go wrong in your script call.
#
# NOTE: I allowed for the usage of get_self_switch inside of Set Move Route
# because you can use a Ternary Operator for Conditional Move Routes. It is
# very unlikely that you'll ever need to use get_self_switch inside of
# Set Move Route -> Script.
#
# NOTE: You can set a Self Switch for ANY Event on your Game Map, even from
# setting a Player Move Route -> Script. When using Player, you MUST call
# for an Event ID as the Game Player has no Self Switches. This may be
# much easier than jumping in and out of Set Move Route when trying to
# synchronize movements.
#
# Installation
#
# Put anywhere between the Default Scripts and Main. These are all unique
# definitions so this script should be perfectly compatible with ALL other
# scripts in existence.
#
# --- Limitations ---
#
# You cant use during either Battle or Different Maps.
#
# --- Usage ---
#
# You can use anywhere you can make a Script Call, except in Battle.
#
# For Conditional Branching, in Events Page 1, click on Conditional Branch.
# Then in Page 4 of the Conditional Branch, go to Script.
# In Script, enter "get_self_switch(Letter, event_id) == true / false"
# - Dont use Quotes on the whole statement
# - Dont use the word IF
# - (Letter is 'A', 'B', 'C', or 'D') WITH Quotes in the Script Call.
# - Event ID does NOT have Quotes.
#
# Dont forget you CAN PRINT anywhere you can enter a Script Call also.
# print get_self_switch(Letter, event_id)
#
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
# * Set Self Switch(ch, value, id)
# ch : A, B, C, or D
# value : true, false, 'On', 'Off', 1, or 0
# id : Event ID
#
# - Change a Self Switch from a Move Route Event
#--------------------------------------------------------------------------
def set_self_switch(ch, value, id = @id)
# if Player Move Route and id is not Specified
if id == 0 and $DEBUG
# Print Error
print "When using set_self_switch for Player Move Route, you need to\n",
"specify an Event ID because the Game Player does not\n",
"have any Self Switches"
end
# Valid Values
value_valid = [true, false, 0, 1, 'on','off']
if value.is_a?(String)
value = true if value.to_s.downcase == 'on'
value = false if value.to_s.downcase == 'off'
elsif value.is_a?(Integer)
value = true if value == 1
value = false if value == 0
end
# If we have A, B, C, or D, and the Event exists
if ch.is_a?(String) and "ABCD".include?(ch.upcase) and
(value == true or value == false) and $game_map.events[id]
# If event ID is valid
if @id > 0 and
# Make Upper Case for Key
ch = ch.to_s.upcase
# Make a self switch key
key = [$game_map.map_id, id, ch]
# Change self switches
$game_self_switches[key] = value
end
# Refresh map
$game_map.need_refresh = true
# Continue
return true
else
if $DEBUG
print "Warning: set_self_switch expects Two Arguments\n",
"The First Argument should be the letter A, B, C, or D\n",
"The Second Argument should be either True or False.\n",
"(On or Off is acceptable too. Just need you",
"to say what you want to set it to.)\n\n",
"Example: set_self_switch('A',true)\n\n",
"Example 2: set_self_switch('A','On')\n\n",
"There is an Optional 3rd Argument for",
"specifying an Event ID\n\n",
"Example 2: set_self_switch('B',false, 32)\n\n",
"This Script call to get_self_switch was made\n",
"from MOVE ROUTE => SCRIPT\n\n",
"set_self_switch in MOVE ROUTES => SCRIPT expect TWO Arguments, THIRD Optional\n",
"set_self_switch in EVENT => SCRIPT expects THREE Arguments\n\n",
"Your Script: Move Route -> Script set_self_switch('",ch,"','",value,"','",id,"')"
if not $game_map.events[id]
print "The Event ID: ", id, " you specified\n",
"doesn't exist on this map"
end
end
end
end
#--------------------------------------------------------------------------
# * Get Self Switch(ch, id)
# ch : A, B, C, or D
# id : Event ID
#
# - Returns True if a Switch is ON, False if Switch is OFF
# - This is usually only good with Ternary Operator but I included it anyway
# Example: @direction = (get_self_switch('A',15) ? 8 : 2
#--------------------------------------------------------------------------
def get_self_switch(ch, id = @id)
# if Player Move Route and id is not Specified
if id == 0 and $DEBUG
# Print Error
print "When using get_self_switch for Player Set Move Route, you need to\n",
"specify an Event ID because the Game Player does not\n",
"have any Self Switches\n\n",
"Calling in Player with no ID argument causes\n",
"the ID to be set to 0"
end
# If we have A, B, C, or D, and the Event exists
if ch.is_a?(String) and "ABCD".include?(ch.upcase) and
id and $game_map.events[id]
# Make a Key
key = [$game_map.map_id, id, ch.upcase]
return $game_self_switches[key]
else
if $DEBUG
print "Warning: get_self_switch expects Two Arguments\n",
"The First Argument should be the Letter of\n",
" the Self Switch you are Checking, A, B, C, or D\n",
"The Second Argument should be the Event's ID\n",
"Example: get_self_switch('B', 23)\n\n",
"This Script call to get_self_switch was made\n",
"from MOVE ROUTE => SCRIPT\n\n",
"Your Script: Move Route -> Script get_self_switch('",ch,"','",id,"')"
if not $game_map.events[id]
print "The Event ID: ", id, " you specified\n",
"doesn't exist on this map"
end
end
end
end
end
class Interpreter
#--------------------------------------------------------------------------
# * Get Self Switch(ch, id)
# ch : A, B, C, or D
# id : Event ID (Default to self.id)
#
# - Returns True if a Switch is ON, False if Switch is OFF
# - This is NOT called from Move Route - Script
#--------------------------------------------------------------------------
def get_self_switch(ch, id = nil)
# If we have A, B, C, or D, and the Event exists
if ch.is_a?(String) and "ABCD".include?(ch.upcase) and
id and $game_map.events[id]
# Make a Key
key = [$game_map.map_id, id, ch.upcase]
return $game_self_switches[key]
else
if $DEBUG
print "Warning: get_self_switch expects Two Arguments\n",
"The First Argument should be the Letter of\n",
" the Self Switch you are Checking, A, B, C, or D\n",
"The Second Argument should be the Event's ID\n",
"Example: get_self_switch('B', 23)\n\n",
"Note: The call that generated this error",
"was NOT called from a Move Route\n ",
"just an Event Script\n\n",
"Your Script: Event -> Script get_self_switch('",ch,"','",id,"')"
if id.nil?
print "The Event ID: ", id, " isn't set in your script call"
elsif not $game_map.events[id]
print "The Event ID: ", id, " doesn't exist on this map"
end
end
end
end
#--------------------------------------------------------------------------
# * Set Self Switch(ch, value, id)
# ch : A, B, C, or D
# value : true, false, 'On', 'Off', 1, or 0
# id : Event ID (default self.id)
#
# - Change a Self Switch for any Event from another Event -> Script
# - Use this ONLY to change a Self Switch for another Event. The
# game engine already has a button for changing Self Switches.
# - This is NOT called from Move Route - Script
#--------------------------------------------------------------------------
def set_self_switch(ch, value, id=nil)
# Valid Values
value_valid = [true, false, 0, 1, 'on','off']
if value.is_a?(String)
value = true if value.to_s.downcase == 'on'
value = false if value.to_s.downcase == 'off'
elsif value.is_a?(Integer)
value = true if value == 1
value = false if value == 0
end
if ch.is_a?(String) and "ABCD".include?(ch.upcase) and
(value == true or value == false) and id and $game_map.events[id]
# If event ID is valid
if id > 0 and
# Make Upper Case for Key
ch = ch.to_s.upcase
# Make a self switch key
key = [$game_map.map_id, id, ch]
# Change self switches
$game_self_switches[key] = value
end
# Refresh map
$game_map.need_refresh = true
# Continue
return true
else
if $DEBUG
print "Warning: set_self_switch expects THREE Arguments\n",
"The First Argument should be the letter A, B, C, or D\n",
"The Second Argument should be either True or False\n",
"The 3rd Argument is used to specify an Event ID\n\n",
"Example: set_self_switch('B','Off', 32)\n\n",
"Note: The call that generated this error ",
"was NOT called from a Move Route\n",
"just an Event Script\n\n",
"set_self_switch in MOVE ROUTES => SCRIPT expect TWO Arguments, THIRD Optional\n",
"set_self_switch in EVENT => SCRIPT expects THREE Arguments\n\n",
"Your Script: Event -> Script set_self_switch('",ch,"','",value,"','",id,"')"
if id.nil?
print "The Event ID: ", id, " isn't set in your script call"
elsif not $game_map.events[id]
print "The Event ID: ", id, " doesn't exist on this map"
end
end
end
end
end