#==============================================================================#
# Name: RK5 Debug Console #
# Version: 1.2.1 #
# Author: Rikifive #
#==============================================================================#
# UPDATES #
# ------- #
# 03.05.2016 | Version 1.2.1 #
# └► you can print hooked object's parameters by pressing #
# └► added changeable opacity of the object to hook command #
# #
# 29.04.2016 | Version 1.2 #
# └► added 'Give' command #
# └► added 'Give All' command #
# └► added 'Lose All' command #
# └► added 'Spawn Gold' command #
# └► added 'Noclip' command #
# └► improved help window - it displays information more clearly #
# #
# 27.04.2016 | Version 1.1 #
# └► added 'Hook' function #
# └► incorrect codes don't crash the game anymore #
# | (Thanks to BLACK WYVERN for help with this) #
# └► all sounds can be configured or disabled #
# └► 'optimized' script code a little to make it shorter and more effective #
# #
# 25.04.2016 | Version 1 #
# └► initial release #
#==============================================================================#
# DESCRIPTION #
# ----------- #
# This script adds an in-game console, that can be brought in any scene #
# to perform a script call, that can be typed during gameplay. #
# There are many, many, many possibilities of using that console, #
# starting from simply changing variables to even performing advanced codes to #
# affect objects or even create them. #
# Besides freely typed strings, the console contains build-in commands, #
# for quicker debugging like teleporting player to specific maps #
# and coordinates. #
# #
#==============================================================================#
# FEATURES #
# -------- #
# -=> Use build-in commands! Think of cheats or commands in Minecraft lel #
# -=> Hook objects like windows to adjust their position, size or opacity #
# and print the results into a txt file! #
# -=> Change variables, actor/enemy stats and many, many other #
# -=> Check values maintained by variables etc. #
# -=> Everything is up to you! #
# #
#==============================================================================#
# INSTRUCTIONS #
# ------------ #
# ► SCRIPT DIFFICULTY: ★★☆☆☆ - ★★★★☆ #
# from build-in commands - to advanced usage #
# #
# ► REQUIRED SCRIPTS! #
# CP Keyboard Input script by Neon Black #
# └► http://forums.rpgmakerweb.com/index.php?/profile/626-neon-black/ #
# └► http://pastebin.com/raw/rD4rQtKP #
# #
# -=> Place script(s) below ▼ Materials; above ▼ Main Process #
# -=> Plug & Play #
# -=> Press '~' (tilde) to bring up the console or exit from it. #
# -=> Type /help in console to view available commands and such. #
# #
#==============================================================================#
# CURRENTLY AVAILABLE COMMANDS #
# ---------------------------- #
# Commands - Call pre-made codes. #
# └► Toogle Noclip Mode | /noclip #
# | Desc: Allows to go through impassable objects. #
# | Usage: /noclip #=> Toogles Noclip Mode ON/OFF #
# | #
# └► Give Item | /give OR /give <item name> #
# | Desc: Spawns an item in inventory. Types: 1=item 2=weapon 3=armor #
# | Usage: /give 1 5 10 #=> Gives 10x item with ID 5 from item category #
# | /give Small Potion 10 #=> Gives items based on their names #
# | (If there will be multiple items with the same name, it will #
# | give them all, even from various item categories) #
# | #
# └► Give All | /give all #
# | Desc: Fills your inventory with everything. #
# | Usage: /give all #=> Gives EVERYTHING x 99 #
# | #
# └► Lose All | /lose all #
# | Desc: Cleans up your inventory. #
# | Usage: /lose all #=> Removes EVERYTHING x 999 #
# | #
# └► Spawn Gold | /gold #
# | Desc: Adds or removes a specified amount of gold to/from inventory. #
# | Usage: /gold 1000 #=> Adds 1000 gold to player's inventory #
# | #
# └► Transfer Player | /tp #
# | Desc: Moves player to specific map and coordinates. #
# | Usage: /tp 2 4 5 #=> Moves player to position on MAP002 #
# | #
# └► Scene Call | /sc scene ("Scene_" is automatically added) #
# | Desc: Calls a specific scene. #
# | Usage: /sc Menu #=> Calls a Scene_Menu #
# | #
# └► Escape From Battle | /run #
# | Desc: Successfully escapes from battle. #
# | Usage: /run #=> Escapes from battle and gets back to Map #
# | #
# └► Force Victory | /win #
# Desc: Forces victory by instant-killing all enemies. #
# Usage: /win #=> Kills all enemies - Your new secret OP weapon #
# #
# Functions - New logical keywords used by this console. #
# └► Check Value | == ? #
# | Desc: Returns current value from object to the console. #
# | Usage: $game_variables == ? #=> Returns value from Variable #5 #
# | #
# └► Hook Object | /hook #
# Desc: Hooks an object to allow moving/resising by input. #
# Usage: /hook @status_window #=> Hooks f.e. a party window from menu #
# #
# Shortcuts - Replaces keyword into a string when pressing button. #
# └► Variables | #v #
# | Desc: Code used to handle variables. #
# | Usage: #v ==> $game_variables => $game_variables #
# | #
# └► Switches | #s #
# | Desc: Code used to handle switches. #
# | Usage: #s ==> $game_switches => $game_switches #
# | #
# └► Party Members | #a #
# | Desc: Refers to a member similar to eg. 'a.hp' in Damage Formulas. #
# | Usage: #a ==> $game_party.members => $game_party.members.hp #
# | #
# └► Party Members | #b #
# Desc: Refers to an enemy similar to eg. 'b.hp' in Damage Formulas. #
# Usage: #b ==> $game_troop.members => $game_troop.members.hp #
# #
# REMEMBER: You can use negative numbers to subtract values / remove items #
# #
# - More to come in future updates - #
#==============================================================================#
# TERMS OF USE #
# ------------ #
# You ARE allowed to use this script in non-commercial projects. #
# You ARE NOT allowed to use this script in commercial projects. #
# You ARE allowed to edit this script to your needs. #
# You ARE NOT allowed to repost or post modified versions of this script!!! #
# You ARE DEFINITELY NOT allowed to claim this script as your own. #
# Crediting me, Rikifive would be heavily appreciated. #
# You ARE obligated to read and follow the terms of use of #
# CP Keyboard Input script created by Neon Black as well #
# #
# While I won't kill anybody for breaking these rules, it still would be #
# a violation of personal rights, that shouldn't happen. #
# By using this script you accept these terms of use. #
# Not reading them DOES NOT exempt you from liability. #
# #
#==============================================================================#
# LAST WORDS #
# ---------- #
# This script has been written as a sort of an experiment. #
# I'm not a professional scriptwriter - I wanted a simple console, that would #
# do what I want without any unecessary fancy thingies. Also I wanted to learn #
# more about strings/arrays, so I've started toying with them here. #
# Most likely this code will look extremely noobish, but hey! It works and #
# I'm really proud of it! So deal with it! (▀Ĺ̯▀̿) #
# #
# But if you have contructive suggestions, opinions and ideas, then feel free #
# to tell me about them, but there's no need to be mean. #
#==============================================================================#

#===============================================================================
# >>> CONFIGURATION
#===============================================================================
module RK5DC

# Sound Effects | Set to true/false |
PLAY_SOUND_INPUT = true # SE when typing
SOUND_INPUT =

PLAY_SOUND_BACK = true # SE when erasing characters by 'Backspace'
SOUND_BACK =

PLAY_SOUND_ENTER = true # SE when code is accepted
SOUND_ENTER =

PLAY_SOUND_ERROR = true # SE when code was incorrect
SOUND_ERROR =

PLAY_SOUND_HELP = true # SE when browsing through help pages
SOUND_HELP =

PLAY_SOUND_PRINT = true # SE when printing object's parameters
SOUND_PRINT =

end
#===============================================================================
# >>> END OF CONFIGURATION
#-------------------------------------------------------------------------------
# /!\ WARNING!
# ------------
# Editing anything below can result in breaking the script, which will give
# you errors as a gift in return. ( °͜ʖ°)
#===============================================================================


#===============================================================================
# >>> Create Console For Debugging
#===============================================================================
class Window_RK5_Debug_Console < Window_Base

#-----------------------------------------------------------------------------
# >>> Object Initialization
#-----------------------------------------------------------------------------
def initialize
super(-12, Graphics.height - 83, Graphics.width + 24, 95)
self.z = 1000
self.opacity = 0
setup_window
end

#-----------------------------------------------------------------------------
# >>> Setup Window
#-----------------------------------------------------------------------------
def setup_window
@hide_console = false

@string = ""
@last = -1
@cursor_position = 0
@cursor_visibility = 0

@current_page = 0
setup_help

@hook = false

refresh
end

#-----------------------------------------------------------------------------
# >>> Setup Sounds
#-----------------------------------------------------------------------------
def se_input; RPG::SE.new(RK5DC::SOUND_INPUT,RK5DC::SOUND_INPUT,RK5DC::SOUND_INPUT).play if RK5DC::PLAY_SOUND_INPUT; end
def se_back; RPG::SE.new(RK5DC::SOUND_BACK,RK5DC::SOUND_BACK,RK5DC::SOUND_BACK).play if RK5DC::PLAY_SOUND_BACK; end
def se_enter; RPG::SE.new(RK5DC::SOUND_ENTER,RK5DC::SOUND_ENTER,RK5DC::SOUND_ENTER).play if RK5DC::PLAY_SOUND_ENTER; end
def se_error; RPG::SE.new(RK5DC::SOUND_ERROR,RK5DC::SOUND_ERROR,RK5DC::SOUND_ERROR).play if RK5DC::PLAY_SOUND_ERROR; end
def se_help; RPG::SE.new(RK5DC::SOUND_HELP,RK5DC::SOUND_HELP,RK5DC::SOUND_HELP).play if RK5DC::PLAY_SOUND_HELP; end
def se_print; RPG::SE.new(RK5DC::SOUND_PRINT,RK5DC::SOUND_PRINT,RK5DC::SOUND_PRINT).play if RK5DC::PLAY_SOUND_PRINT; end

#-----------------------------------------------------------------------------
# >>> Refresh
#-----------------------------------------------------------------------------
def refresh
self.contents.clear
return if @hide_console

input_y = 35

# >>> Configuring Font
self.contents.font.size = 24

# >>> Draw Console Title
contents.fill_rect(0, 0, 98, 2, Color.new(160,210,255))
contents.fill_rect(98, 0, 2, 29, Color.new(160,210,255))
contents.fill_rect(0, 2, 98, 27, Color.new(60,40,40))
self.contents.font.color = Color.new(255,200,100)
draw_text(0, 2, 100, 24, "CONSOLE", 1)

# >>> Make Input Box
contents.fill_rect(0, input_y - 6, self.width, 2, Color.new(160,210,255))
contents.fill_rect(0, input_y - 4, self.width, 32, Color.new(40,40,40))
contents.fill_rect(0, input_y + 28, self.width, 2, Color.new(160,210,255))

@string_size = self.contents.text_size(@string).width

@move_text = .max

@string_rect = @cursor_position > 0 ? self.contents.text_size(@string).width : 0
@cursor_position_x = 20 + @string_rect - @move_text

@move_text = .max if @string_size > 480

self.contents.font.color = Color.new(150,255,255)
draw_text(10 - @move_text, input_y, 10, 24, ">")
self.contents.font.color = Color.new(255,255,255) if !@hook
self.contents.font.color = Color.new(190,220,255) if @hook
draw_text(20 - @move_text, input_y, @string_size + 5, 24, @string)

if @cursor_visibility < 40 && !@hook
self.contents.font.color = Color.new(255,255,100)
draw_text(20 + @string_rect - @move_text, input_y, 10, 24, "|")
end

# >>> Make Help Box
if @string == "/"; if @scroll_help; refresh_help(0); end
help = "Type /help to view available commands"
self.contents.font.color = Color.new(255,190,255)
elsif @hook
help = "WSAD - Move | Arrow Keys - Resize (Window Objects Only)" if @help_page == 1
help = "Q and E - Priority | - Opacity" if @help_page == 2
help = "Tab - Hide Console | CTRL - Print Parameters | Enter - Unhook" if @help_page == 3
self.contents.font.color = Color.new(255,255,175)
self.contents.font.size = 20
elsif @string.end_with? "#v"; if @scroll_help; refresh_help(0); end
help = " -> $game_variables"
self.contents.font.color = Color.new(150,255,150)
elsif @string.end_with? "#s"; if @scroll_help; refresh_help(0); end
help = " -> $game_switches"
self.contents.font.color = Color.new(150,255,150)
elsif @string.end_with? "#a"; if @scroll_help; refresh_help(0); end
help = " -> $game_party.members"
self.contents.font.color = Color.new(150,255,150)
elsif @string.end_with? "#b"; if @scroll_help; refresh_help(0); end
help = " -> $game_troop.members"
self.contents.font.color = Color.new(150,255,150)
elsif @string.end_with? " == ?"; if @scroll_help; refresh_help(0); end
help = " Check Value"
self.contents.font.color = Color.new(150,255,255)
elsif @string.start_with? "/hook"; if !@scroll_help; refresh_help(2); end
help = " Hook Object | /hook <object>" if @help_page == 1
help = " Hook Object | ex: /hook @status_window" if @help_page == 2
self.contents.font.color = Color.new(150,255,255)
elsif @string.start_with? "/noclip"; if @scroll_help; refresh_help(0); end
help = " Toogle Noclip Mode"
self.contents.font.color = Color.new(255,200,150)
elsif @string.start_with? "/give all"; if @scroll_help; refresh_help(0); end
help = " Get All Items"; if @scroll_help; refresh_help(0); end
self.contents.font.color = Color.new(255,200,150)
elsif @string.start_with? "/lose all"; if @scroll_help; refresh_help(0); end
help = " Remove All Items"; if @scroll_help; refresh_help(0); end
self.contents.font.color = Color.new(255,200,150)
elsif @string.start_with? "/give"; if !@scroll_help; refresh_help(4); end
help = " Give Item | /give " if @help_page == 1
help = " Give Item | ex: /give 1 5 10" if @help_page == 2
help = " Give Item | /give <name> " if @help_page == 3
help = " Give Item | ex: /give Small Potion 10" if @help_page == 4
self.contents.font.color = Color.new(255,200,150)
elsif @string.start_with? "/gold"; if !@scroll_help; refresh_help(2); end
help = " Spawn Gold | /gold " if @help_page == 1
help = " Spawn Gold | ex: /gold 1000" if @help_page == 2
self.contents.font.color = Color.new(255,200,150)
elsif @string.start_with? "/tp"; if !@scroll_help; refresh_help(2); end
help = " Transfer Player | /tp " if @help_page == 1
help = " Transfer Player | ex: /tp 5 15 10" if @help_page == 2
self.contents.font.color = Color.new(255,200,150)
elsif @string.start_with? "/sc"; if !@scroll_help; refresh_help(2); end
help = " Scene Call | /sc <scene name>" if @help_page == 1
help = " Scene Call | ex: /sc Menu" if @help_page == 2
self.contents.font.color = Color.new(255,200,150)
elsif @string.start_with? "/run"; if @scroll_help; refresh_help(0); end
help = " Escape From Battle"
self.contents.font.color = Color.new(255,200,150)
elsif @string.start_with? "/win"; if @scroll_help; refresh_help(0); end
help = " Kill All Enemies"
self.contents.font.color = Color.new(255,200,150)
elsif @string == "/help"; if @scroll_help; refresh_help(0); end
setup_help
help = @page
self.contents.font.color = Color.new(255,190,255)
self.contents.font.size = 15
else; @scroll_help; refresh_help(0); end
if help != nil
help_rect = self.contents.text_size(help).width
contents.fill_rect(100, 0, Graphics.width - 100, 2, Color.new(160,210,255))
contents.fill_rect(100, 2, Graphics.width - 100, 27, Color.new(40,40,60))
contents.fill_rect(100, 2, Graphics.width - 100, 27, Color.new(60,40,70)) if @string == "/help"
contents.fill_rect(100, 2, Graphics.width - 100, 27, Color.new(40,70,50)) if @hook
draw_text(110, 4, help_rect + 5, 24, help)
end

reset_font_settings
end

#-----------------------------------------------------------------------------
# >>> Setup Help
#-----------------------------------------------------------------------------
def setup_help
@page =
@page = "Use arrow keys to browse through pages."
@page = "Functions are new logical keywords used by this console."
@page = " == ? | Returns value maintained by something."
@page = " /hook | Allows to adjust an object by input."
@page = "Shortcuts are keywords, that are replaced by code when pressing ."
@page = " '#v' | => $game_variables | Variable"
@page = " '#s' | => $game_switches | Switch"
@page = " '#a' | => $game_party.members | Party Member"
@page = " '#b' | => $game_troop.members | Enemy"
@page = "Commands are pre-made codes for quicker debugging."
@page = " /noclip | Toggle ability to walk through impassable tiles."
@page = " /give | Spawns items in the inventory."
@page = " /give all | Gives all items."
@page = " /lose all | Removes all items."
@page = " /gold | Spawns Gold."
@page = " /tp | Transfers player to specific map and coordinates."
@page = " /sc | Calls a scene."
@page = " /run | Successfully escapes from battle."
@page = " /win | Forces victory by killing all enemies."
@page = "More functionality will be added in future updates."
@page = "Feel free to leave a suggestion for adding more commands/features"

@page.size.times do |page|
text = "Page " + (@current_page+1).to_s + "/" + @page.size.to_s + " | "
@page.insert(0, text)
end
end

#-----------------------------------------------------------------------------
# >>> Refresh Help
#-----------------------------------------------------------------------------
def refresh_help(pages = 1)
if pages == 0; @scroll_help = false; return; end
@scroll_help = true
@help_pages = pages
@help_timer = 0
@help_page = 1
end

#-----------------------------------------------------------------------------
# >>> Update
#-----------------------------------------------------------------------------
def update
super
update_cursor if !@hook
update_help_timer if @scroll_help
update_input
end

#-----------------------------------------------------------------------------
# >>> Update Text Cursor
#-----------------------------------------------------------------------------
def update_cursor
@cursor_visibility = @cursor_visibility >= 79 ? 0 : @cursor_visibility + 1
refresh if @cursor_visibility % 40 == 0
end

#-----------------------------------------------------------------------------
# >>> Update Help Scrolling
#-----------------------------------------------------------------------------
def update_help_timer
@help_timer = @help_timer >= 200 * @help_pages - 1 ? 0 : @help_timer + 1
if @help_timer % 200 == 0; @help_page = @help_timer / 200 + 1; refresh; end
end

#-----------------------------------------------------------------------------
# >>> Update Input
#-----------------------------------------------------------------------------
def update_input
###==##########################################
if @hook

# MOVE OBJECT
# SHIFT?
if caps?
SceneManager.scene.console_move_object("y",-1) if Input.press?(:kW)
SceneManager.scene.console_move_object("y",1) if Input.press?(:kS)
SceneManager.scene.console_move_object("x",-1) if Input.press?(:kA)
SceneManager.scene.console_move_object("x",1) if Input.press?(:kD)
SceneManager.scene.console_move_object("z",-1) if Input.press?(:kQ)
SceneManager.scene.console_move_object("z",1) if Input.press?(:kE)
SceneManager.scene.console_move_object("-",0,0,0,-1) if Input.press?(:kLEFTBRACE)
SceneManager.scene.console_move_object("-",0,0,0,1) if Input.press?(:kRIGHTBRACE)
SceneManager.scene.console_move_object("-",0,0,-1) if Input.press?(:kUP)
SceneManager.scene.console_move_object("-",0,0,1) if Input.press?(:kDOWN)
SceneManager.scene.console_move_object("-",0,-1) if Input.press?(:kLEFT)
SceneManager.scene.console_move_object("-",0,1) if Input.press?(:kRIGHT)
end

if Input.repeat?(:kW); SceneManager.scene.console_move_object("y",-1)
elsif Input.repeat?(:kS); SceneManager.scene.console_move_object("y",1)
elsif Input.repeat?(:kA); SceneManager.scene.console_move_object("x",-1)
elsif Input.repeat?(:kD); SceneManager.scene.console_move_object("x",1)
elsif Input.repeat?(:kQ); SceneManager.scene.console_move_object("z",-1)
elsif Input.repeat?(:kE); SceneManager.scene.console_move_object("z",1)
elsif Input.repeat?(:kLEFTBRACE); SceneManager.scene.console_move_object("-",0,0,0,-1)
elsif Input.repeat?(:kRIGHTBRACE); SceneManager.scene.console_move_object("-",0,0,0,1)
elsif Input.repeat?(:kUP); SceneManager.scene.console_move_object("-",0,0,-1)
elsif Input.repeat?(:kDOWN); SceneManager.scene.console_move_object("-",0,0,1)
elsif Input.repeat?(:kLEFT); SceneManager.scene.console_move_object("-",0,-1)
elsif Input.repeat?(:kRIGHT); SceneManager.scene.console_move_object("-",0,1)
end

# REFRESH CONSOLE
if caps?
if Input.press?(:kW) || Input.press?(:kS) || Input.press?(:kA) || Input.press?(:kD) ||
Input.press?(:kUP) || Input.press?(:kDOWN) || Input.press?(:kLEFT) || Input.press?(:kRIGHT) ||
Input.press?(:kQ) || Input.press?(:kE) ||
Input.press?(:kLEFTBRACE) || Input.press?(:kRIGHTBRACE)
@string = SceneManager.scene.console_move_object; refresh; end
else
if Input.repeat?(:kW) || Input.repeat?(:kS) || Input.repeat?(:kA) || Input.repeat?(:kD) ||
Input.repeat?(:kUP) || Input.repeat?(:kDOWN) || Input.repeat?(:kLEFT) || Input.repeat?(:kRIGHT) ||
Input.repeat?(:kQ) || Input.repeat?(:kE) ||
Input.repeat?(:kLEFTBRACE) || Input.repeat?(:kRIGHTBRACE)
@string = SceneManager.scene.console_move_object; refresh; end
end


# HIDE CONSOLE
if Input.trigger?(:kTAB); @hide_console = @hide_console ? false : true ; refresh; end

# PRINT PARAMETERS
if Input.trigger?(:kCTRL)
se_print
current_scene = SceneManager.scene.to_s
scene = current_scene
object = SceneManager.scene.console_hook_object("-",get_object = true)
File.open("RK5 Debug Console Print.txt", "a") {|f| f.write(
"\n" + @string.to_s + "\n\n") }
end

# UNHOOK
setup_window if Input.trigger?(:kENTER)


###==#############################################
else
# LETTERS
if Input.repeat?(:kA); @sym = caps? ? 'A' : 'a'; add_symbol
elsif Input.repeat?(:kB); @sym = caps? ? 'B' : 'b'; add_symbol
elsif Input.repeat?(:kC); @sym = caps? ? 'C' : 'c'; add_symbol
elsif Input.repeat?(:kD); @sym = caps? ? 'D' : 'd'; add_symbol
elsif Input.repeat?(:kE); @sym = caps? ? 'E' : 'e'; add_symbol
elsif Input.repeat?(:kF); @sym = caps? ? 'F' : 'f'; add_symbol
elsif Input.repeat?(:kG); @sym = caps? ? 'G' : 'g'; add_symbol
elsif Input.repeat?(:kH); @sym = caps? ? 'H' : 'h'; add_symbol
elsif Input.repeat?(:kI); @sym = caps? ? 'I' : 'i'; add_symbol
elsif Input.repeat?(:kJ); @sym = caps? ? 'J' : 'j'; add_symbol
elsif Input.repeat?(:kK); @sym = caps? ? 'K' : 'k'; add_symbol
elsif Input.repeat?(:kL); @sym = caps? ? 'L' : 'l'; add_symbol
elsif Input.repeat?(:kM); @sym = caps? ? 'M' : 'm'; add_symbol
elsif Input.repeat?(:kN); @sym = caps? ? 'N' : 'n'; add_symbol
elsif Input.repeat?(:kO); @sym = caps? ? 'O' : 'o'; add_symbol
elsif Input.repeat?(:kP); @sym = caps? ? 'P' : 'p'; add_symbol
elsif Input.repeat?(:kQ); @sym = caps? ? 'Q' : 'q'; add_symbol
elsif Input.repeat?(:kR); @sym = caps? ? 'R' : 'r'; add_symbol
elsif Input.repeat?(:kS); @sym = caps? ? 'S' : 's'; add_symbol
elsif Input.repeat?(:kT); @sym = caps? ? 'T' : 't'; add_symbol
elsif Input.repeat?(:kU); @sym = caps? ? 'U' : 'u'; add_symbol
elsif Input.repeat?(:kV); @sym = caps? ? 'V' : 'v'; add_symbol
elsif Input.repeat?(:kW); @sym = caps? ? 'W' : 'w'; add_symbol
elsif Input.repeat?(:kX); @sym = caps? ? 'X' : 'x'; add_symbol
elsif Input.repeat?(:kY); @sym = caps? ? 'Y' : 'y'; add_symbol
elsif Input.repeat?(:kZ); @sym = caps? ? 'Z' : 'z'; add_symbol

# NUMBERS
elsif Input.repeat?(:k1); @sym = caps? ? '!' : '1'; add_symbol
elsif Input.repeat?(:k2); @sym = caps? ? '@' : '2'; add_symbol
elsif Input.repeat?(:k3); @sym = caps? ? '#' : '3'; add_symbol
elsif Input.repeat?(:k4); @sym = caps? ? '$' : '4'; add_symbol
elsif Input.repeat?(:k5); @sym = caps? ? '%' : '5'; add_symbol
elsif Input.repeat?(:k6); @sym = caps? ? '^' : '6'; add_symbol
elsif Input.repeat?(:k7); @sym = caps? ? '&' : '7'; add_symbol
elsif Input.repeat?(:k8); @sym = caps? ? '*' : '8'; add_symbol
elsif Input.repeat?(:k9); @sym = caps? ? '(' : '9'; add_symbol
elsif Input.repeat?(:k0); @sym = caps? ? ')' : '0'; add_symbol

# SYMBOLS
elsif Input.repeat?(:kSPACE); @sym = ' '; add_symbol
elsif Input.repeat?(:kUNDERSCORE); @sym = caps? ? '_' : '-'; add_symbol
elsif Input.repeat?(:kEQUAL); @sym = caps? ? '+' : '='; add_symbol
elsif Input.repeat?(:kLEFTBRACE); @sym = caps? ? '{' : ''; add_symbol
elsif Input.repeat?(:kCOLON); @sym = caps? ? ':' : ';'; add_symbol
elsif Input.repeat?(:kAPOSTROPHE); @sym = caps? ? '"' : "'"; add_symbol
elsif Input.repeat?(:kBACKSLASH); @sym = caps? ? '|' : '\\'; add_symbol
elsif Input.repeat?(:kCOMMA); @sym = caps? ? '<' : ','; add_symbol
elsif Input.repeat?(:kPERIOD); @sym = caps? ? '>' : '.'; add_symbol
elsif Input.repeat?(:kSLASH); @sym = caps? ? '?' : '/'; add_symbol

# ARROWS
elsif Input.repeat?(:kUP)
#---
if @string == "/help"
if @current_page < @page.size - 1
se_help; @current_page = .min
else; return; end
#---
elsif $game_temp.last_string.size - 1 > @last
se_input
@last += 1
@string = $game_temp.last_string.at(@last)
@cursor_position = @string.size
else; return; end
refresh

elsif Input.repeat?(:kDOWN)
#---
if @string == "/help"
if @current_page > 0
se_help; @current_page = .max
else; return; end
#---
elsif @last > -1
se_input
@last -= 1
@string = @last >= 0 ? $game_temp.last_string.at(@last) : ""
@cursor_position = @string.size
else; return; end
refresh

elsif Input.repeat?(:kLEFT)
#---
if @string == "/help"
if @current_page > 0; se_help; @current_page -= 1; else; return; end
#---
elsif @cursor_position > 0
@cursor_position -= 1
@cursor_visibility = 0
else; return; end
refresh

elsif Input.repeat?(:kRIGHT)
#---
if @string == "/help"
if @current_page < @page.size - 1; se_help; @current_page += 1; else; return; end
#---
elsif @cursor_position < @string.size && @string != "/help"
@cursor_position += 1
@cursor_visibility = 0
else; return; end
refresh


# BACKSPACE
elsif Input.repeat?(:kBACKSPACE) && @string.size > 0
se_back
if @cursor_position > 0
@string = ""
@cursor_position -= 1
else
@string = ""
end
@cursor_visibility = 0
refresh

# USE SHORTCUT
elsif Input.trigger?(:kTAB)
check_shortcuts

# RUN CODE
elsif Input.trigger?(:kENTER)
begin
scan_string
se_enter
rescue
se_error; SceneManager.scene.dispose_rk5_console
rescue SyntaxError => se
se_error; SceneManager.scene.dispose_rk5_console
end
end
end # FUNCTION!

end

#-----------------------------------------------------------------------------
# >>> Check Shift Buttons
#-----------------------------------------------------------------------------
def caps?
if Input.press?(:kLSHIFT) || Input.press?(:kRSHIFT)
return true
else
return false
end
end

#-----------------------------------------------------------------------------
# >>> Add Symbol
#-----------------------------------------------------------------------------
def add_symbol
se_input
@string.insert(@cursor_position, @sym)
@cursor_position += 1
@cursor_visibility = 0
refresh
end

#-----------------------------------------------------------------------------
# >>> Scan String
#-----------------------------------------------------------------------------
def scan_string
#============================================================
# Store Recently Typed String
$game_temp.last_string.unshift(@string)
# Clean Strings Older Than 50 Entries
$game_temp.last_string.pop if $game_temp.last_string.size > 50
# >>> Toggle Noclip Mode
if @string.start_with? "/noclip"
@string = "$game_temp.noclip = " + ($game_temp.noclip ? "false" : "true")
run_code
# >>> Give All Items
elsif @string.start_with? "/give all"
@string = "$data_items.each {|item| $game_party.gain_item(item, 99)}; " +
"$data_weapons.each {|item| $game_party.gain_item(item, 99)}; " +
"$data_armors.each {|item| $game_party.gain_item(item, 99)}"
run_code
# >>> Lose All Items
elsif @string.start_with? "/lose all"
@string = "$data_items.each {|item| $game_party.gain_item(item, -999)}; " +
"$data_weapons.each {|item| $game_party.gain_item(item, -999)}; " +
"$data_armors.each {|item| $game_party.gain_item(item, -999)}"
run_code
# >>> Give
elsif @string.start_with? "/give"
part = @string.split
if part == "1" || part == "2" || part == "3" #
case part; when "1"; type = "items"; when "2"; type = "weapons"; when "3"; type = "armors"; end
@string = "$game_party.gain_item($data_" + type + "[" + part.to_s + "], " +
part.to_s + ")"
else #
name_parts = @string.split; name_parts.pop; name_parts.shift
name = "'" + name_parts * " " + "'"
@string = "$data_items.each {|item| $game_party.gain_item(item, " + part.last.to_s + ") if item && item.name == " + name.to_s + "}; " +
"$data_weapons.each {|item| $game_party.gain_item(item, " + part.last.to_s + ") if item && item.name == " + name.to_s + "}; " +
"$data_armors.each {|item| $game_party.gain_item(item, " + part.last.to_s + ") if item && item.name == " + name.to_s + "}"
end # id/name
run_code
# >>> Get Gold
elsif @string.start_with? "/gold"
part = @string.split
@string = "$game_party.gain_gold(" + part.to_s + ")"
run_code
# >>> Player Transfer Command
elsif @string.start_with? "/tp"
part = @string.split
location = part.to_s + "," + part.to_s + "," + part.to_s
@string = "$game_player.reserve_transfer(" + location + ")"
run_code
# >>> Scene Call
elsif @string.start_with? "/sc"
@string = @string
@string = "SceneManager.call(Scene_" + @string + ")"
run_code
# >>> Escape From Battle
elsif @string.start_with? "/run"
@string = "BattleManager.abort"
run_code
# >>> Kill All Enemies
elsif @string.start_with? "/win"
@string = "$game_troop.members.each do |e|; e.hp -= 99999999999; e.perform_collapse_effect; end"
run_code
# >>> Hook Object
elsif @string.start_with? "/hook"
SceneManager.scene.console_hook_object(@string)
@hook = true
refresh_help(3)
@string = SceneManager.scene.console_move_object
refresh
# >>> Asking for the value
elsif @string.end_with? " == ?"
check_for_value
@string = @string + " = " + SceneManager.scene.console_ask_for_value.to_s
@cursor_position = @string.size
refresh
# >>> When there's no special code detected
else
run_code
end

end

#-----------------------------------------------------------------------------
# >>> Run Code!
#-----------------------------------------------------------------------------
def run_code
if Input.press?(:kPDOWN); @cursor_position = @string.size; refresh; return; end
SceneManager.scene.console_eval_string(@string)
end

#-----------------------------------------------------------------------------
# >>> Check For Value
#-----------------------------------------------------------------------------
def check_for_value
# Reset Last String Position
@last = -1
# Clean String From Special Format
@string = @string
# Run Code!
SceneManager.scene.console_ask_for_value(@string)
end

#-----------------------------------------------------------------------------
# >>> Check For Shortcuts
#-----------------------------------------------------------------------------
def check_shortcuts
if @string.end_with? "#v" #=> VARIABLES
@string = @string.size > 2 ? @string : ""
@string += "$game_variables"
shortcut_return_string
elsif @string.end_with? "#s" #=> SWITCHES
@string = @string.size > 2 ? @string : ""
@string += "$game_switches"
shortcut_return_string
elsif @string.end_with? "#a" #=> MEMBERS
@string = @string.size > 2 ? @string : ""
@string += "$game_party.members"
shortcut_return_string
elsif @string.end_with? "#b" #=> ENEMIES
@string = @string.size > 2 ? @string : ""
@string += "$game_troop.members"
shortcut_return_string
end
end

def shortcut_return_string(pos = @string.size)
se_enter
@cursor_position = pos
refresh
end

end

#===============================================================================
# >>> Modification of Scene_Base
#===============================================================================
class Scene_Base

#-----------------------------------------------------------------------------
# >>> Main
# -=> Replacing 'update' method with even 'greater' one...
#-----------------------------------------------------------------------------
def main
start
post_start
update_game until scene_changing?
pre_terminate
terminate
end

#-----------------------------------------------------------------------------
# >>> Main Update Method
# -=> Takes priority over 'update' method, so that when the console is open,
# everything 'freezes', except that debug window.
#-----------------------------------------------------------------------------
def update_game
if debug_mode?
update_console_only
else
update
end
end

#-----------------------------------------------------------------------------
# >>> Checking if Debug Mode is Enabled
# -=> Detects if the console is open.
#-----------------------------------------------------------------------------
def debug_mode?
@rk5_console_window
end

#-----------------------------------------------------------------------------
# >>> Update
# -=> Just adds input detection for a button, that opens the console.
#-----------------------------------------------------------------------------
alias :rk5_console_update :update
def update
rk5_console_update
update_console_call
end

#-----------------------------------------------------------------------------
# >>> Update (Console Only)
# -=> Just like the update, but updates only the console window.
#-----------------------------------------------------------------------------
def update_console_only
Graphics.update
Input.update
@rk5_console_window.update
update_console_call
end

#-----------------------------------------------------------------------------
# >>> Update Console Call
# -=> Brings or disposes the console when button is pressed.
#-----------------------------------------------------------------------------
def update_console_call
if Input.trigger?(:kTILDE)
if @rk5_console_window == nil
@rk5_console_window = Window_RK5_Debug_Console.new
else
dispose_rk5_console
end
end
end

#-----------------------------------------------------------------------------
# >>> Dispose RK5 Console Window
#-----------------------------------------------------------------------------
def dispose_rk5_console
@rk5_console_window.dispose if @rk5_console_window
@rk5_console_window = nil
end

#-----------------------------------------------------------------------------
# >>> Console Eval String
# -=> Runs the typed string.
#-----------------------------------------------------------------------------
def console_eval_string(string)
dispose_rk5_console
eval string
end

#-----------------------------------------------------------------------------
# >>> Console Ask For Value
# -=> Special Function: Asking for a variable.
# -> Checks the current value of typed variable and returns it to the console.
#-----------------------------------------------------------------------------
def console_ask_for_value(string = nil)
if string != nil
@console_result = nil
@console_result = eval string
@console_result = "nil" if @console_result == nil
else
return @console_result
end
end

#-----------------------------------------------------------------------------
# >>> Hook Object
# -=> Special Function: Moves or resizes an object.
# -> Hooks an object to move or resize it by input.
#-----------------------------------------------------------------------------
def console_hook_object(string,get_object = false)
return @console_hooked_object_name if get_object
object = string
@console_hooked_object_name = object
@console_hooked_object = eval object
end

#-----------------------------------------------------------------------------
# >>> Console Move Object - Hook Object Function
# -> Performs an action and stores object's parameters.
#-----------------------------------------------------------------------------
def console_move_object(dir="x",dist=0,rewi=0,rehei=0,opac=0)
obj = @console_hooked_object
object = instance_variable_get(@console_hooked_object_name)
obj.x += dist if dir == "x" && dist != 0
obj.y += dist if dir == "y" && dist != 0
obj.z += dist if dir == "z" && dist != 0
obj.width += rewi if rewi != 0 && object.is_a?(Window)
obj.height += rehei if rehei != 0 && object.is_a?(Window)
obj.opacity += opac if opac != 0
object_parameters = "x: " + obj.x.to_s + " | y: " + obj.y.to_s + " | z: " + obj.z.to_s +
" | w: " + obj.width.to_s + " | h: " + obj.height.to_s + " | o: " + obj.opacity.to_s
return object_parameters
end

end

class Game_Player < Game_Character
#-----------------------------------------------------------------------------
# >>> debug_through?
# -> Implements Noclip Mode.
#--------------------------------------------------------------------------
alias :rk5_console_debug_through? :debug_through?
def debug_through?
rk5_console_debug_through? || $game_temp.noclip
end
end

#===============================================================================
# >>> Store Recently Typed String
#===============================================================================
class Game_Temp
attr_accessor :last_string
attr_accessor :noclip

alias :rk5_console_initialize :initialize
def initialize
rk5_console_initialize
@last_string =
@noclip = false
end
end