Introduction
This script is designed to search throughout your RPGMaker XP's project to find and record all used RPGMaker XP switches to a file. It will search through both the common event database and through each map and map event, and the troop database recording all switches used to a file. The output file will be named "Switch Extractor.txt" within your project's folder.
Each line will include the Common Event ID, Map/Event/Page number or Troop ID/Page number before listing the switch. With this, the report may be able to help organize their system during game creation.
Script
The Script
Code:
#==============================================================================
# ** Switch Extraction Generator
#------------------------------------------------------------------------------
# version 1.2
# by DerVVulfman
# 06-18-2020
# RGSS and ReGaL Compliant
#==============================================================================
#
# INTRODUCTION:
#
# This script is designed to search throughout your RPGMaker XP's project to
# find and record all used RPGMaker XP switches to a file. It will search
# through both the common event database and through each map and map
# event, and the troop database recording all switches used to a file. The
# output file will be named "Switch Extractor.txt" within your project's folder.
#
# Each line will include the Common Event ID, Map/Event/Page number or Troop
# ID/Page number before listing the switch. With this, the report may be able
# to help organize their system during game creation.
#
#
#------------------------------------------------------------------------------
#
# INSTRUCTIONS:
#
# * Insert below your scripts.
# * Run project.
# * Read report when you're done.
#
#
#------------------------------------------------------------------------------
#
# CREDITS:
#
# Inspiration for the system, and suggestion to include both common events
# and show choices text by yamina-chan. Additional suggestion of Troops
# Database text made by Kain_Nobel.
#
#
#------------------------------------------------------------------------------
#
# NOTE:
#
# It only searches through the common event page within the database and the
# events within the map systems. It does not search through custom scripts.
#
#
#==============================================================================
#==============================================================================
# ** Switch_Extractor
#------------------------------------------------------------------------------
# This is a module searches through all map events, common events and troop
# database content to generate a textfile list of all used RMXP switches for
# game developer review.
#==============================================================================
module Switch_Extractor
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
def self.main
# Create Header
f = File.new("Switch Extractor.txt", "w+")
f.puts "SWITCH EXTRACTION LIST"
f.puts ""
# Gain Data Resources
set_resource_database
f.puts "COMMON EVENT PORTION:"
f.puts ""
search_resource_common(f)
f.puts ""
f.puts "MAP LIST PORTION:"
f.puts ""
search_resource_map(f)
f.puts ""
f.puts "BATTLESYSTEM PORTION:"
f.puts ""
search_resource_enemy(f)
f.puts ""
search_resource_troop(f)
f.close
end
#--------------------------------------------------------------------------
# * Project Database Values
#--------------------------------------------------------------------------
def self.set_resource_database
@switch_list = load_data("Data/System.rxdata")
@common_list = load_data("Data/CommonEvents.rxdata")
@map_list = load_data("Data/MapInfos.rxdata")
@troop_list = load_data("Data/Troops.rxdata")
@enemy_list = load_data("Data/Enemies.rxdata")
end
#--------------------------------------------------------------------------
# * Common Events Database Search
#--------------------------------------------------------------------------
def self.search_resource_common(file)
text_width_size = 25
return if @common_list.nil?
counter = 0
for event in @common_list
next if event.nil?
name = event.name
trigger = event.trigger
list = event.list
counter += 1
had_content = false
if [1,2].include?(trigger)
had_content = true
header = counter.to_s + ") "+ name
temp_text = header + " "
temp_text = temp_text[0, text_width_size]
switch_text = "#" + event.switch_id.to_s
switch_text = switch_text + " / " +
@switch_list.switches[event.switch_id]
final_text = temp_text + " <Switch:> " + switch_text
file.puts final_text
temp_text = " "
temp_text = temp_text[0, text_width_size]
end
file.puts "" if had_content == true
header = counter.to_s + ") "+ name
search_resource_page_item(file, header, text_width_size, list)
end
end
#--------------------------------------------------------------------------
# * Enemy Database Search
#--------------------------------------------------------------------------
def self.search_resource_enemy(file)
file.puts "Enemy Content:"
file.puts ""
text_width_size = 40
tcounter = 0
for enemy in @enemy_list
next if enemy.nil?
tcounter += 1
counter = 0
for action in enemy.actions
counter += 1
id = tcounter
name = enemy.name
had_content = false
if action.condition_switch_id > 0
header = id.to_s + ") " + name + " (Action #: " + counter.to_s + ") "
temp_text = header + " "
temp_text = temp_text[0, text_width_size]
switch_text = "#" + action.condition_switch_id.to_s
switch_text = switch_text + " / " +
@switch_list.switches[action.condition_switch_id]
file.puts temp_text + " " + switch_text
temp_text = " "
temp_text = temp_text[0, text_width_size]
end
file.puts "" if had_content == true
end
end
end
#--------------------------------------------------------------------------
# * Troop Database Search
#--------------------------------------------------------------------------
def self.search_resource_troop(file)
file.puts "Troop Content:"
file.puts ""
text_width_size = 25
tcounter = 0
for troop in @troop_list
next if troop.nil?
tcounter += 1
counter = 0
for page in troop.pages
counter += 1
id = tcounter
name = troop.name
name = name.slice(0,10)
condition = page.condition
had_content = false
if condition.switch_valid == true
had_content = true
header = id.to_s + ") " + name + " / Pg: " + counter.to_s + " "
temp_text = header + " "
temp_text = temp_text[0, text_width_size]
switch_text = "#" + condition.switch_id.to_s
switch_text = switch_text + " / " +
@switch_list.switches[condition.switch_id]
file.puts temp_text + " <Switch:> " + switch_text
temp_text = " "
temp_text = temp_text[0, text_width_size]
end
file.puts "" if had_content == true
list = page.list
header = id.to_s + ") " + name + " / Pg: " + counter.to_s + " "
search_resource_page_item(file, header, text_width_size, list)
end
end
end
#--------------------------------------------------------------------------
# * Map Database Search
#--------------------------------------------------------------------------
def self.search_resource_map(file)
text_width_size = 25
for map in @map_list.sort
# Get map ID
id = map[0]
# Get Individual Map Data
map_data = load_data(sprintf("Data/Map%03d.rxdata", id))
# Set map event data
events = {}
for i in map_data.events.keys
events[i] = map_data.events[i]
end
# Sorth through Event Array
for event in events.sort
counter = 0
# Sort through Event Pages
for page in event[1].pages.reverse
counter += 1
condition = page.condition
had_content = false
end
end
end
end
#--------------------------------------------------------------------------
# * Page List Search (whether troop or map pages)
#--------------------------------------------------------------------------
def self.search_resource_page_item(file, header, sized, list)
temp_text = header + " "
temp_text = temp_text[0, sized]
had_content = false
# Cycle through items
for list_item in list
# If Conditional Branch
if [111].include?(list_item.code)
# If conditional is switch
if list_item.parameters[0] == 0
# File value of Switch
switch_val = list_item.parameters[1]
switch_text = "#" + switch_val.to_s
switch_text = switch_text + " / " + @switch_list.switches[switch_val]
file.puts temp_text + " <Event List:> " + switch_text
temp_text = " "
temp_text = temp_text[0, sized]
had_content = true
end
# If Control Switch
elsif [121].include?(list_item.code)
# Loop for group control
for i in list_item.parameters[0] .. list_item.parameters[1]
# File value of Switch
switch_text = "#" + i.to_s
switch_text = switch_text + " / " + @switch_list.switches[i]
file.puts temp_text + " <Event List:> " + switch_text
temp_text = " "
temp_text = temp_text[0, sized]
had_content = true
end
end
end
file.puts "" if had_content == true
end
end
There were TWO issues with the previous version. First, I neglected to realize that Enemies had switch conditions, not just Troops. But second, there was an issue where map event triggers were returning incorrect switch IDs.