class Interpreter
#-----------------------------------------------------------------------------
# * Alias Listings
#-----------------------------------------------------------------------------
alias_method :troopselfswitches_interpreter_command111, :command_111
alias_method :troopselfswitches_interpreter_command123, :command_123
#-----------------------------------------------------------------------------
# * Conditional Branch
#-----------------------------------------------------------------------------
def command_111
# Unless in battle and parameter signifies self-switches
unless $scene.is_a?(Scene_Battle) && @parameters[0] == 2
# The usual
return troopselfswitches_interpreter_command111
end
# Default result to false
result = false
# If troop ID is valid
if $game_temp.battle_troop_id > 0
# Get switch value
switch = case @parameters[1]
when 'A' then $game_troop.switch_a
when 'B' then $game_troop.switch_b
when 'C' then $game_troop.switch_c
when 'D' then $game_troop.switch_d
end
# If checking for switch to be true
if @parameters[2] == 0
# Set result based on switch being true
result = (switch == true)
# If checking for switch to be false
else
# Set result based on switch being false
result = (switch != true)
end
end
# Store determinant results in hash
@branch[@list[@index].indent] = result
# If determinant results are true
if @branch[@list[@index].indent] == true
# Delete branch data
@branch.delete(@list[@index].indent)
# Continue
return true
end
# If it doesn't meet the conditions: command skip
command_skip
end
#-----------------------------------------------------------------------------
# * Control Self Switch
#-----------------------------------------------------------------------------
def command_123
# Unless in battle
unless $scene.is_a?(Scene_Battle)
# The usual
return troopselfswitches_interpreter_command123
end
# If troop ID is valid
if $game_temp.battle_troop_id > 0
# Set switch value
case @parameters[0]
when 'A' then $game_troop.switch_a = (@parameters[1] == 0)
when 'B' then $game_troop.switch_b = (@parameters[1] == 0)
when 'C' then $game_troop.switch_c = (@parameters[1] == 0)
when 'D' then $game_troop.switch_d = (@parameters[1] == 0)
end
end
# Refresh map
$game_map.need_refresh = true
# Continue
true
end
end
class Game_Troop
#-----------------------------------------------------------------------------
# * Alias Listings
#-----------------------------------------------------------------------------
alias_method :troopselfswitches_gmtroop_initialize, :initialize
#-----------------------------------------------------------------------------
# * Object Initialization
#-----------------------------------------------------------------------------
def initialize
# The usual
troopselfswitches_gmtroop_initialize
# Create self switches variable
@switches = Hash.new
# For each troop in database
for troop_id in 1...$data_troops.size
# Create a hash object for troop
@switches[troop_id] = Hash.new
# A, B, C, D each...
[:a, :b, :c, :d].each {|sign| @switches[troop_id][sign] = false}
end
end
#-----------------------------------------------------------------------------
# * Switch A
#-----------------------------------------------------------------------------
def switch_a
@switches[$game_temp.battle_troop_id][:a]
end
#-----------------------------------------------------------------------------
# * Switch A = (value)
#-----------------------------------------------------------------------------
def switch_a=(value)
@switches[$game_temp.battle_troop_id][:a] = value
end
#-----------------------------------------------------------------------------
# * Switch B
#-----------------------------------------------------------------------------
def switch_b
@switches[$game_temp.battle_troop_id][:b]
end
#-----------------------------------------------------------------------------
# * Switch B = (value)
#-----------------------------------------------------------------------------
def switch_b=(value)
@switches[$game_temp.battle_troop_id][:b] = value
end
#-----------------------------------------------------------------------------
# * Switch C
#-----------------------------------------------------------------------------
def switch_c
@switches[$game_temp.battle_troop_id][:c]
end
#-----------------------------------------------------------------------------
# * Switch C = (value)
#-----------------------------------------------------------------------------
def switch_c=(value)
@switches[$game_temp.battle_troop_id][:c] = value
end
#-----------------------------------------------------------------------------
# * Switch D
#-----------------------------------------------------------------------------
def switch_d
@switches[$game_temp.battle_troop_id][:d]
end
#-----------------------------------------------------------------------------
# * Switch D = (value)
#-----------------------------------------------------------------------------
def switch_d=(value)
@switches[$game_temp.battle_troop_id][:d] = value
end
end
Screen Shots
Nothing fancy, just an example of use. This is in the Database > Troops tab.
Message displays only once; first time you fight Basilisk (x2). Useful for quick tutorial battles.
Author's Notes
My good friend PK8 wrote a Self Data Suite, which also has Troop Self Switch capabilities. My script is only Troop-related, so I'm not exactly sure what the differences are. PK8's suite, on the other hand, handles tons more self-switch related content for Actors, Enemies, Troops, Maps, etc. so it might be worth checking out.
Additional Capabilities
You've gained new functions!
Code:
# You can set Troop Self-Switches A-D
$game_troop.switch_a = bool
# You can check Troop Self-Switches A-D too!
unless $game_troop.switch_a
p 'Hello world!'
$game_troop.switch_a = true
end
Use within Call Script and/or Conditional Branch > Call Script commands :)
These calls will only work while in battle; I have not designed them to work on map events.
Credits
Free for commercial and non-commercial use. Just credit Kain Nobel and enjoy!