Guest User

RK5 Debug Console

a guest
May 13th, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 48.30 KB | None | 0 0
  1. #==============================================================================#
  2. # Name: RK5 Debug Console #
  3. # Version: 1.2.1 #
  4. # Author: Rikifive #
  5. #==============================================================================#
  6. # UPDATES #
  7. # ------- #
  8. # [■] 03.05.2016 | Version 1.2.1 #
  9. # └► you can print hooked object's parameters by pressing [CTRL] #
  10. # └► added changeable opacity of the object to hook command #
  11. # #
  12. # [■] 29.04.2016 | Version 1.2 #
  13. # └► added 'Give' command #
  14. # └► added 'Give All' command #
  15. # └► added 'Lose All' command #
  16. # └► added 'Spawn Gold' command #
  17. # └► added 'Noclip' command #
  18. # └► improved help window - it displays information more clearly #
  19. # #
  20. # [■] 27.04.2016 | Version 1.1 #
  21. # └► added 'Hook' function #
  22. # └► incorrect codes don't crash the game anymore #
  23. # | (Thanks to BLACK WYVERN for help with this) #
  24. # └► all sounds can be configured or disabled #
  25. # └► 'optimized' script code a little to make it shorter and more effective #
  26. # #
  27. # [■] 25.04.2016 | Version 1 #
  28. # └► initial release #
  29. #==============================================================================#
  30. # DESCRIPTION #
  31. # ----------- #
  32. # This script adds an in-game console, that can be brought in any scene #
  33. # to perform a script call, that can be typed during gameplay. #
  34. # There are many, many, many possibilities of using that console, #
  35. # starting from simply changing variables to even performing advanced codes to #
  36. # affect objects or even create them. #
  37. # Besides freely typed strings, the console contains build-in commands, #
  38. # for quicker debugging like teleporting player to specific maps #
  39. # and coordinates. #
  40. # #
  41. #==============================================================================#
  42. # FEATURES #
  43. # -------- #
  44. # -=> Use build-in commands! Think of cheats or commands in Minecraft lel #
  45. # -=> Hook objects like windows to adjust their position, size or opacity #
  46. # and print the results into a txt file! #
  47. # -=> Change variables, actor/enemy stats and many, many other #
  48. # -=> Check values maintained by variables etc. #
  49. # -=> Everything is up to you! #
  50. # #
  51. #==============================================================================#
  52. # INSTRUCTIONS #
  53. # ------------ #
  54. # ► SCRIPT DIFFICULTY: ★★☆☆☆ - ★★★★☆ #
  55. # from build-in commands - to advanced usage #
  56. # #
  57. # ► REQUIRED SCRIPTS! #
  58. # [■] CP Keyboard Input script by Neon Black #
  59. # └►[profile] http://forums.rpgmakerweb.com/index.php?/profile/626-neon-black/ #
  60. # └►[script] http://pastebin.com/raw/rD4rQtKP #
  61. # #
  62. # -=> Place script(s) below ▼ Materials; above ▼ Main Process #
  63. # -=> Plug & Play #
  64. # -=> Press '~' (tilde) to bring up the console or exit from it. #
  65. # -=> Type /help in console to view available commands and such. #
  66. # #
  67. #==============================================================================#
  68. # CURRENTLY AVAILABLE COMMANDS #
  69. # ---------------------------- #
  70. # [■] Commands - Call pre-made codes. #
  71. # └► Toogle Noclip Mode | /noclip #
  72. # | Desc: Allows to go through impassable objects. #
  73. # | Usage: /noclip #=> Toogles Noclip Mode ON/OFF #
  74. # | #
  75. # └► Give Item | /give [type] [id] [amount] OR /give <item name> [amount] #
  76. # | Desc: Spawns an item in inventory. Types: 1=item 2=weapon 3=armor #
  77. # | Usage: /give 1 5 10 #=> Gives 10x item with ID 5 from item category #
  78. # | /give Small Potion 10 #=> Gives items based on their names #
  79. # | (If there will be multiple items with the same name, it will #
  80. # | give them all, even from various item categories) #
  81. # | #
  82. # └► Give All | /give all #
  83. # | Desc: Fills your inventory with everything. #
  84. # | Usage: /give all #=> Gives EVERYTHING x 99 #
  85. # | #
  86. # └► Lose All | /lose all #
  87. # | Desc: Cleans up your inventory. #
  88. # | Usage: /lose all #=> Removes EVERYTHING x 999 #
  89. # | #
  90. # └► Spawn Gold | /gold [amount] #
  91. # | Desc: Adds or removes a specified amount of gold to/from inventory. #
  92. # | Usage: /gold 1000 #=> Adds 1000 gold to player's inventory #
  93. # | #
  94. # └► Transfer Player | /tp [map_id] [x] [y] #
  95. # | Desc: Moves player to specific map and coordinates. #
  96. # | Usage: /tp 2 4 5 #=> Moves player to [4,5] position on MAP002 #
  97. # | #
  98. # └► Scene Call | /sc scene ("Scene_" is automatically added) #
  99. # | Desc: Calls a specific scene. #
  100. # | Usage: /sc Menu #=> Calls a Scene_Menu #
  101. # | #
  102. # └► Escape From Battle | /run #
  103. # | Desc: Successfully escapes from battle. #
  104. # | Usage: /run #=> Escapes from battle and gets back to Map #
  105. # | #
  106. # └► Force Victory | /win #
  107. # Desc: Forces victory by instant-killing all enemies. #
  108. # Usage: /win #=> Kills all enemies - Your new secret OP weapon #
  109. # #
  110. # [■] Functions - New logical keywords used by this console. #
  111. # └► Check Value | [var] == ? #
  112. # | Desc: Returns current value from object to the console. #
  113. # | Usage: $game_variables[5] == ? #=> Returns value from Variable #5 #
  114. # | #
  115. # └► Hook Object | /hook [object] #
  116. # Desc: Hooks an object to allow moving/resising by input. #
  117. # Usage: /hook @status_window #=> Hooks f.e. a party window from menu #
  118. # #
  119. # [■] Shortcuts - Replaces keyword into a string when pressing [TAB] button. #
  120. # └► Variables | #v #
  121. # | Desc: Code used to handle variables. #
  122. # | Usage: #v =[TAB]=> $game_variables => $game_variables[3] #
  123. # | #
  124. # └► Switches | #s #
  125. # | Desc: Code used to handle switches. #
  126. # | Usage: #s =[TAB]=> $game_switches => $game_switches[3] #
  127. # | #
  128. # └► Party Members | #a #
  129. # | Desc: Refers to a member similar to eg. 'a.hp' in Damage Formulas. #
  130. # | Usage: #a =[TAB]=> $game_party.members => $game_party.members[3].hp #
  131. # | #
  132. # └► Party Members | #b #
  133. # Desc: Refers to an enemy similar to eg. 'b.hp' in Damage Formulas. #
  134. # Usage: #b =[TAB]=> $game_troop.members => $game_troop.members[3].hp #
  135. # #
  136. # REMEMBER: You can use negative numbers to subtract values / remove items #
  137. # #
  138. # - More to come in future updates - #
  139. #==============================================================================#
  140. # TERMS OF USE #
  141. # ------------ #
  142. # You ARE allowed to use this script in non-commercial projects. #
  143. # You ARE NOT allowed to use this script in commercial projects. #
  144. # You ARE allowed to edit this script to your needs. #
  145. # You ARE NOT allowed to repost or post modified versions of this script!!! #
  146. # You ARE DEFINITELY NOT allowed to claim this script as your own. #
  147. # Crediting me, Rikifive would be heavily appreciated. #
  148. # You ARE obligated to read and follow the terms of use of #
  149. # CP Keyboard Input script created by Neon Black as well #
  150. # #
  151. # While I won't kill anybody for breaking these rules, it still would be #
  152. # a violation of personal rights, that shouldn't happen. #
  153. # By using this script you accept these terms of use. #
  154. # Not reading them DOES NOT exempt you from liability. #
  155. # #
  156. #==============================================================================#
  157. # LAST WORDS #
  158. # ---------- #
  159. # This script has been written as a sort of an experiment. #
  160. # I'm not a professional scriptwriter - I wanted a simple console, that would #
  161. # do what I want without any unecessary fancy thingies. Also I wanted to learn #
  162. # more about strings/arrays, so I've started toying with them here. #
  163. # Most likely this code will look extremely noobish, but hey! It works and #
  164. # I'm really proud of it! So deal with it! (▀Ĺ̯▀̿) #
  165. # #
  166. # But if you have contructive suggestions, opinions and ideas, then feel free #
  167. # to tell me about them, but there's no need to be mean. #
  168. #==============================================================================#
  169.  
  170. #===============================================================================
  171. # >>> CONFIGURATION
  172. #===============================================================================
  173. module RK5DC
  174.  
  175. # Sound Effects | Set to true/false | ["Sound_Name", volume, pitch]
  176. PLAY_SOUND_INPUT = true # SE when typing
  177. SOUND_INPUT = ["Cursor1", 100, 100]
  178.  
  179. PLAY_SOUND_BACK = true # SE when erasing characters by 'Backspace'
  180. SOUND_BACK = ["Cancel1", 100, 100]
  181.  
  182. PLAY_SOUND_ENTER = true # SE when code is accepted
  183. SOUND_ENTER = ["Decision2", 100, 100]
  184.  
  185. PLAY_SOUND_ERROR = true # SE when code was incorrect
  186. SOUND_ERROR = ["Buzzer1",100, 100]
  187.  
  188. PLAY_SOUND_HELP = true # SE when browsing through help pages
  189. SOUND_HELP = ["Book1", 100, 100]
  190.  
  191. PLAY_SOUND_PRINT = true # SE when printing object's parameters
  192. SOUND_PRINT = ["Save", 100, 100]
  193.  
  194. end
  195. #===============================================================================
  196. # >>> END OF CONFIGURATION
  197. #-------------------------------------------------------------------------------
  198. # /!\ WARNING!
  199. # ------------
  200. # Editing anything below can result in breaking the script, which will give
  201. # you errors as a gift in return. ( °͜ʖ°)
  202. #===============================================================================
  203.  
  204.  
  205. #===============================================================================
  206. # >>> Create Console For Debugging
  207. #===============================================================================
  208. class Window_RK5_Debug_Console < Window_Base
  209.  
  210. #-----------------------------------------------------------------------------
  211. # >>> Object Initialization
  212. #-----------------------------------------------------------------------------
  213. def initialize
  214. super(-12, Graphics.height - 83, Graphics.width + 24, 95)
  215. self.z = 1000
  216. self.opacity = 0
  217. setup_window
  218. end
  219.  
  220. #-----------------------------------------------------------------------------
  221. # >>> Setup Window
  222. #-----------------------------------------------------------------------------
  223. def setup_window
  224. @hide_console = false
  225.  
  226. @string = ""
  227. @last = -1
  228. @cursor_position = 0
  229. @cursor_visibility = 0
  230.  
  231. @current_page = 0
  232. setup_help
  233.  
  234. @hook = false
  235.  
  236. refresh
  237. end
  238.  
  239. #-----------------------------------------------------------------------------
  240. # >>> Setup Sounds
  241. #-----------------------------------------------------------------------------
  242. def se_input; RPG::SE.new(RK5DC::SOUND_INPUT[0],RK5DC::SOUND_INPUT[1],RK5DC::SOUND_INPUT[2]).play if RK5DC::PLAY_SOUND_INPUT; end
  243. def se_back; RPG::SE.new(RK5DC::SOUND_BACK[0],RK5DC::SOUND_BACK[1],RK5DC::SOUND_BACK[2]).play if RK5DC::PLAY_SOUND_BACK; end
  244. def se_enter; RPG::SE.new(RK5DC::SOUND_ENTER[0],RK5DC::SOUND_ENTER[1],RK5DC::SOUND_ENTER[2]).play if RK5DC::PLAY_SOUND_ENTER; end
  245. def se_error; RPG::SE.new(RK5DC::SOUND_ERROR[0],RK5DC::SOUND_ERROR[1],RK5DC::SOUND_ERROR[2]).play if RK5DC::PLAY_SOUND_ERROR; end
  246. def se_help; RPG::SE.new(RK5DC::SOUND_HELP[0],RK5DC::SOUND_HELP[1],RK5DC::SOUND_HELP[2]).play if RK5DC::PLAY_SOUND_HELP; end
  247. def se_print; RPG::SE.new(RK5DC::SOUND_PRINT[0],RK5DC::SOUND_PRINT[1],RK5DC::SOUND_PRINT[2]).play if RK5DC::PLAY_SOUND_PRINT; end
  248.  
  249. #-----------------------------------------------------------------------------
  250. # >>> Refresh
  251. #-----------------------------------------------------------------------------
  252. def refresh
  253. self.contents.clear
  254. return if @hide_console
  255.  
  256. input_y = 35
  257.  
  258. # >>> Configuring Font
  259. self.contents.font.size = 24
  260.  
  261. # >>> Draw Console Title
  262. contents.fill_rect(0, 0, 98, 2, Color.new(160,210,255))
  263. contents.fill_rect(98, 0, 2, 29, Color.new(160,210,255))
  264. contents.fill_rect(0, 2, 98, 27, Color.new(60,40,40))
  265. self.contents.font.color = Color.new(255,200,100)
  266. draw_text(0, 2, 100, 24, "CONSOLE", 1)
  267.  
  268. # >>> Make Input Box
  269. contents.fill_rect(0, input_y - 6, self.width, 2, Color.new(160,210,255))
  270. contents.fill_rect(0, input_y - 4, self.width, 32, Color.new(40,40,40))
  271. contents.fill_rect(0, input_y + 28, self.width, 2, Color.new(160,210,255))
  272.  
  273. @string_size = self.contents.text_size(@string).width
  274.  
  275. @move_text = [@string_size - 500,0].max
  276.  
  277. @string_rect = @cursor_position > 0 ? self.contents.text_size(@string[0..@cursor_position - 1]).width : 0
  278. @cursor_position_x = 20 + @string_rect - @move_text
  279.  
  280. @move_text = [@move_text - (500 - @cursor_position_x),0].max if @string_size > 480
  281.  
  282. self.contents.font.color = Color.new(150,255,255)
  283. draw_text(10 - @move_text, input_y, 10, 24, ">")
  284. self.contents.font.color = Color.new(255,255,255) if !@hook
  285. self.contents.font.color = Color.new(190,220,255) if @hook
  286. draw_text(20 - @move_text, input_y, @string_size + 5, 24, @string)
  287.  
  288. if @cursor_visibility < 40 && !@hook
  289. self.contents.font.color = Color.new(255,255,100)
  290. draw_text(20 + @string_rect - @move_text, input_y, 10, 24, "|")
  291. end
  292.  
  293. # >>> Make Help Box
  294. if @string == "/"; if @scroll_help; refresh_help(0); end
  295. help = "Type /help to view available commands"
  296. self.contents.font.color = Color.new(255,190,255)
  297. elsif @hook
  298. help = "WSAD - Move | Arrow Keys - Resize (Window Objects Only)" if @help_page == 1
  299. help = "Q and E - Priority | [ and ] - Opacity" if @help_page == 2
  300. help = "Tab - Hide Console | CTRL - Print Parameters | Enter - Unhook" if @help_page == 3
  301. self.contents.font.color = Color.new(255,255,175)
  302. self.contents.font.size = 20
  303. elsif @string.end_with? "#v"; if @scroll_help; refresh_help(0); end
  304. help = "[TAB] -> $game_variables"
  305. self.contents.font.color = Color.new(150,255,150)
  306. elsif @string.end_with? "#s"; if @scroll_help; refresh_help(0); end
  307. help = "[TAB] -> $game_switches"
  308. self.contents.font.color = Color.new(150,255,150)
  309. elsif @string.end_with? "#a"; if @scroll_help; refresh_help(0); end
  310. help = "[TAB] -> $game_party.members"
  311. self.contents.font.color = Color.new(150,255,150)
  312. elsif @string.end_with? "#b"; if @scroll_help; refresh_help(0); end
  313. help = "[TAB] -> $game_troop.members"
  314. self.contents.font.color = Color.new(150,255,150)
  315. elsif @string.end_with? " == ?"; if @scroll_help; refresh_help(0); end
  316. help = "[FUN] Check Value"
  317. self.contents.font.color = Color.new(150,255,255)
  318. elsif @string.start_with? "/hook"; if !@scroll_help; refresh_help(2); end
  319. help = "[FUN] Hook Object | /hook <object>" if @help_page == 1
  320. help = "[FUN] Hook Object | ex: /hook @status_window" if @help_page == 2
  321. self.contents.font.color = Color.new(150,255,255)
  322. elsif @string.start_with? "/noclip"; if @scroll_help; refresh_help(0); end
  323. help = "[COM] Toogle Noclip Mode"
  324. self.contents.font.color = Color.new(255,200,150)
  325. elsif @string.start_with? "/give all"; if @scroll_help; refresh_help(0); end
  326. help = "[COM] Get All Items"; if @scroll_help; refresh_help(0); end
  327. self.contents.font.color = Color.new(255,200,150)
  328. elsif @string.start_with? "/lose all"; if @scroll_help; refresh_help(0); end
  329. help = "[COM] Remove All Items"; if @scroll_help; refresh_help(0); end
  330. self.contents.font.color = Color.new(255,200,150)
  331. elsif @string.start_with? "/give"; if !@scroll_help; refresh_help(4); end
  332. help = "[COM] Give Item | /give [type] [id] [amount]" if @help_page == 1
  333. help = "[COM] Give Item | ex: /give 1 5 10" if @help_page == 2
  334. help = "[COM] Give Item | /give <name> [amount]" if @help_page == 3
  335. help = "[COM] Give Item | ex: /give Small Potion 10" if @help_page == 4
  336. self.contents.font.color = Color.new(255,200,150)
  337. elsif @string.start_with? "/gold"; if !@scroll_help; refresh_help(2); end
  338. help = "[COM] Spawn Gold | /gold [amount]" if @help_page == 1
  339. help = "[COM] Spawn Gold | ex: /gold 1000" if @help_page == 2
  340. self.contents.font.color = Color.new(255,200,150)
  341. elsif @string.start_with? "/tp"; if !@scroll_help; refresh_help(2); end
  342. help = "[COM] Transfer Player | /tp [map_id] [x] [y]" if @help_page == 1
  343. help = "[COM] Transfer Player | ex: /tp 5 15 10" if @help_page == 2
  344. self.contents.font.color = Color.new(255,200,150)
  345. elsif @string.start_with? "/sc"; if !@scroll_help; refresh_help(2); end
  346. help = "[COM] Scene Call | /sc <scene name>" if @help_page == 1
  347. help = "[COM] Scene Call | ex: /sc Menu" if @help_page == 2
  348. self.contents.font.color = Color.new(255,200,150)
  349. elsif @string.start_with? "/run"; if @scroll_help; refresh_help(0); end
  350. help = "[COM] Escape From Battle"
  351. self.contents.font.color = Color.new(255,200,150)
  352. elsif @string.start_with? "/win"; if @scroll_help; refresh_help(0); end
  353. help = "[COM] Kill All Enemies"
  354. self.contents.font.color = Color.new(255,200,150)
  355. elsif @string == "/help"; if @scroll_help; refresh_help(0); end
  356. setup_help
  357. help = @page[@current_page]
  358. self.contents.font.color = Color.new(255,190,255)
  359. self.contents.font.size = 15
  360. else; @scroll_help; refresh_help(0); end
  361. if help != nil
  362. help_rect = self.contents.text_size(help).width
  363. contents.fill_rect(100, 0, Graphics.width - 100, 2, Color.new(160,210,255))
  364. contents.fill_rect(100, 2, Graphics.width - 100, 27, Color.new(40,40,60))
  365. contents.fill_rect(100, 2, Graphics.width - 100, 27, Color.new(60,40,70)) if @string == "/help"
  366. contents.fill_rect(100, 2, Graphics.width - 100, 27, Color.new(40,70,50)) if @hook
  367. draw_text(110, 4, help_rect + 5, 24, help)
  368. end
  369.  
  370. reset_font_settings
  371. end
  372.  
  373. #-----------------------------------------------------------------------------
  374. # >>> Setup Help
  375. #-----------------------------------------------------------------------------
  376. def setup_help
  377. @page = []
  378. @page[@page.size] = "Use arrow keys to browse through pages."
  379. @page[@page.size] = "Functions are new logical keywords used by this console."
  380. @page[@page.size] = "[FUNCTION] == ? | Returns value maintained by something."
  381. @page[@page.size] = "[FUNCTION] /hook | Allows to adjust an object by input."
  382. @page[@page.size] = "Shortcuts are keywords, that are replaced by code when pressing [TAB]."
  383. @page[@page.size] = "[SHORTCUT] '#v' | => $game_variables | Variable[ID]"
  384. @page[@page.size] = "[SHORTCUT] '#s' | => $game_switches | Switch[ID]"
  385. @page[@page.size] = "[SHORTCUT] '#a' | => $game_party.members | Party Member[ID]"
  386. @page[@page.size] = "[SHORTCUT] '#b' | => $game_troop.members | Enemy[ID]"
  387. @page[@page.size] = "Commands are pre-made codes for quicker debugging."
  388. @page[@page.size] = "[COMMAND] /noclip | Toggle ability to walk through impassable tiles."
  389. @page[@page.size] = "[COMMAND] /give | Spawns items in the inventory."
  390. @page[@page.size] = "[COMMAND] /give all | Gives all items."
  391. @page[@page.size] = "[COMMAND] /lose all | Removes all items."
  392. @page[@page.size] = "[COMMAND] /gold | Spawns Gold."
  393. @page[@page.size] = "[COMMAND] /tp | Transfers player to specific map and coordinates."
  394. @page[@page.size] = "[COMMAND] /sc | Calls a scene."
  395. @page[@page.size] = "[COMMAND] /run | Successfully escapes from battle."
  396. @page[@page.size] = "[COMMAND] /win | Forces victory by killing all enemies."
  397. @page[@page.size] = "More functionality will be added in future updates."
  398. @page[@page.size] = "Feel free to leave a suggestion for adding more commands/features"
  399.  
  400. @page.size.times do |page|
  401. text = "Page " + (@current_page+1).to_s + "/" + @page.size.to_s + " | "
  402. @page[page].insert(0, text)
  403. end
  404. end
  405.  
  406. #-----------------------------------------------------------------------------
  407. # >>> Refresh Help
  408. #-----------------------------------------------------------------------------
  409. def refresh_help(pages = 1)
  410. if pages == 0; @scroll_help = false; return; end
  411. @scroll_help = true
  412. @help_pages = pages
  413. @help_timer = 0
  414. @help_page = 1
  415. end
  416.  
  417. #-----------------------------------------------------------------------------
  418. # >>> Update
  419. #-----------------------------------------------------------------------------
  420. def update
  421. super
  422. update_cursor if !@hook
  423. update_help_timer if @scroll_help
  424. update_input
  425. end
  426.  
  427. #-----------------------------------------------------------------------------
  428. # >>> Update Text Cursor
  429. #-----------------------------------------------------------------------------
  430. def update_cursor
  431. @cursor_visibility = @cursor_visibility >= 79 ? 0 : @cursor_visibility + 1
  432. refresh if @cursor_visibility % 40 == 0
  433. end
  434.  
  435. #-----------------------------------------------------------------------------
  436. # >>> Update Help Scrolling
  437. #-----------------------------------------------------------------------------
  438. def update_help_timer
  439. @help_timer = @help_timer >= 200 * @help_pages - 1 ? 0 : @help_timer + 1
  440. if @help_timer % 200 == 0; @help_page = @help_timer / 200 + 1; refresh; end
  441. end
  442.  
  443. #-----------------------------------------------------------------------------
  444. # >>> Update Input
  445. #-----------------------------------------------------------------------------
  446. def update_input
  447. ###=[ 'HOOK' FUNCTION ACTIVATED ]=##########################################
  448. if @hook
  449.  
  450. # MOVE OBJECT
  451. # SHIFT?
  452. if caps?
  453. SceneManager.scene.console_move_object("y",-1) if Input.press?(:kW)
  454. SceneManager.scene.console_move_object("y",1) if Input.press?(:kS)
  455. SceneManager.scene.console_move_object("x",-1) if Input.press?(:kA)
  456. SceneManager.scene.console_move_object("x",1) if Input.press?(:kD)
  457. SceneManager.scene.console_move_object("z",-1) if Input.press?(:kQ)
  458. SceneManager.scene.console_move_object("z",1) if Input.press?(:kE)
  459. SceneManager.scene.console_move_object("-",0,0,0,-1) if Input.press?(:kLEFTBRACE)
  460. SceneManager.scene.console_move_object("-",0,0,0,1) if Input.press?(:kRIGHTBRACE)
  461. SceneManager.scene.console_move_object("-",0,0,-1) if Input.press?(:kUP)
  462. SceneManager.scene.console_move_object("-",0,0,1) if Input.press?(:kDOWN)
  463. SceneManager.scene.console_move_object("-",0,-1) if Input.press?(:kLEFT)
  464. SceneManager.scene.console_move_object("-",0,1) if Input.press?(:kRIGHT)
  465. end
  466.  
  467. if Input.repeat?(:kW); SceneManager.scene.console_move_object("y",-1)
  468. elsif Input.repeat?(:kS); SceneManager.scene.console_move_object("y",1)
  469. elsif Input.repeat?(:kA); SceneManager.scene.console_move_object("x",-1)
  470. elsif Input.repeat?(:kD); SceneManager.scene.console_move_object("x",1)
  471. elsif Input.repeat?(:kQ); SceneManager.scene.console_move_object("z",-1)
  472. elsif Input.repeat?(:kE); SceneManager.scene.console_move_object("z",1)
  473. elsif Input.repeat?(:kLEFTBRACE); SceneManager.scene.console_move_object("-",0,0,0,-1)
  474. elsif Input.repeat?(:kRIGHTBRACE); SceneManager.scene.console_move_object("-",0,0,0,1)
  475. elsif Input.repeat?(:kUP); SceneManager.scene.console_move_object("-",0,0,-1)
  476. elsif Input.repeat?(:kDOWN); SceneManager.scene.console_move_object("-",0,0,1)
  477. elsif Input.repeat?(:kLEFT); SceneManager.scene.console_move_object("-",0,-1)
  478. elsif Input.repeat?(:kRIGHT); SceneManager.scene.console_move_object("-",0,1)
  479. end
  480.  
  481. # REFRESH CONSOLE
  482. if caps?
  483. if Input.press?(:kW) || Input.press?(:kS) || Input.press?(:kA) || Input.press?(:kD) ||
  484. Input.press?(:kUP) || Input.press?(:kDOWN) || Input.press?(:kLEFT) || Input.press?(:kRIGHT) ||
  485. Input.press?(:kQ) || Input.press?(:kE) ||
  486. Input.press?(:kLEFTBRACE) || Input.press?(:kRIGHTBRACE)
  487. @string = SceneManager.scene.console_move_object; refresh; end
  488. else
  489. if Input.repeat?(:kW) || Input.repeat?(:kS) || Input.repeat?(:kA) || Input.repeat?(:kD) ||
  490. Input.repeat?(:kUP) || Input.repeat?(:kDOWN) || Input.repeat?(:kLEFT) || Input.repeat?(:kRIGHT) ||
  491. Input.repeat?(:kQ) || Input.repeat?(:kE) ||
  492. Input.repeat?(:kLEFTBRACE) || Input.repeat?(:kRIGHTBRACE)
  493. @string = SceneManager.scene.console_move_object; refresh; end
  494. end
  495.  
  496.  
  497. # HIDE CONSOLE
  498. if Input.trigger?(:kTAB); @hide_console = @hide_console ? false : true ; refresh; end
  499.  
  500. # PRINT PARAMETERS
  501. if Input.trigger?(:kCTRL)
  502. se_print
  503. current_scene = SceneManager.scene.to_s
  504. scene = current_scene[2, current_scene.index(":") -2]
  505. object = SceneManager.scene.console_hook_object("-",get_object = true)
  506. File.open("RK5 Debug Console Print.txt", "a") {|f| f.write(
  507. "[ Scene: " + scene + " | Object: " + object + " ]\n" + @string.to_s + "\n\n") }
  508. end
  509.  
  510. # UNHOOK
  511. setup_window if Input.trigger?(:kENTER)
  512.  
  513.  
  514. ###=[ NO FUNCTIONS ACTIVATED ]=#############################################
  515. else
  516. # LETTERS
  517. if Input.repeat?(:kA); @sym = caps? ? 'A' : 'a'; add_symbol
  518. elsif Input.repeat?(:kB); @sym = caps? ? 'B' : 'b'; add_symbol
  519. elsif Input.repeat?(:kC); @sym = caps? ? 'C' : 'c'; add_symbol
  520. elsif Input.repeat?(:kD); @sym = caps? ? 'D' : 'd'; add_symbol
  521. elsif Input.repeat?(:kE); @sym = caps? ? 'E' : 'e'; add_symbol
  522. elsif Input.repeat?(:kF); @sym = caps? ? 'F' : 'f'; add_symbol
  523. elsif Input.repeat?(:kG); @sym = caps? ? 'G' : 'g'; add_symbol
  524. elsif Input.repeat?(:kH); @sym = caps? ? 'H' : 'h'; add_symbol
  525. elsif Input.repeat?(:kI); @sym = caps? ? 'I' : 'i'; add_symbol
  526. elsif Input.repeat?(:kJ); @sym = caps? ? 'J' : 'j'; add_symbol
  527. elsif Input.repeat?(:kK); @sym = caps? ? 'K' : 'k'; add_symbol
  528. elsif Input.repeat?(:kL); @sym = caps? ? 'L' : 'l'; add_symbol
  529. elsif Input.repeat?(:kM); @sym = caps? ? 'M' : 'm'; add_symbol
  530. elsif Input.repeat?(:kN); @sym = caps? ? 'N' : 'n'; add_symbol
  531. elsif Input.repeat?(:kO); @sym = caps? ? 'O' : 'o'; add_symbol
  532. elsif Input.repeat?(:kP); @sym = caps? ? 'P' : 'p'; add_symbol
  533. elsif Input.repeat?(:kQ); @sym = caps? ? 'Q' : 'q'; add_symbol
  534. elsif Input.repeat?(:kR); @sym = caps? ? 'R' : 'r'; add_symbol
  535. elsif Input.repeat?(:kS); @sym = caps? ? 'S' : 's'; add_symbol
  536. elsif Input.repeat?(:kT); @sym = caps? ? 'T' : 't'; add_symbol
  537. elsif Input.repeat?(:kU); @sym = caps? ? 'U' : 'u'; add_symbol
  538. elsif Input.repeat?(:kV); @sym = caps? ? 'V' : 'v'; add_symbol
  539. elsif Input.repeat?(:kW); @sym = caps? ? 'W' : 'w'; add_symbol
  540. elsif Input.repeat?(:kX); @sym = caps? ? 'X' : 'x'; add_symbol
  541. elsif Input.repeat?(:kY); @sym = caps? ? 'Y' : 'y'; add_symbol
  542. elsif Input.repeat?(:kZ); @sym = caps? ? 'Z' : 'z'; add_symbol
  543.  
  544. # NUMBERS
  545. elsif Input.repeat?(:k1); @sym = caps? ? '!' : '1'; add_symbol
  546. elsif Input.repeat?(:k2); @sym = caps? ? '@' : '2'; add_symbol
  547. elsif Input.repeat?(:k3); @sym = caps? ? '#' : '3'; add_symbol
  548. elsif Input.repeat?(:k4); @sym = caps? ? '$' : '4'; add_symbol
  549. elsif Input.repeat?(:k5); @sym = caps? ? '%' : '5'; add_symbol
  550. elsif Input.repeat?(:k6); @sym = caps? ? '^' : '6'; add_symbol
  551. elsif Input.repeat?(:k7); @sym = caps? ? '&' : '7'; add_symbol
  552. elsif Input.repeat?(:k8); @sym = caps? ? '*' : '8'; add_symbol
  553. elsif Input.repeat?(:k9); @sym = caps? ? '(' : '9'; add_symbol
  554. elsif Input.repeat?(:k0); @sym = caps? ? ')' : '0'; add_symbol
  555.  
  556. # SYMBOLS
  557. elsif Input.repeat?(:kSPACE); @sym = ' '; add_symbol
  558. elsif Input.repeat?(:kUNDERSCORE); @sym = caps? ? '_' : '-'; add_symbol
  559. elsif Input.repeat?(:kEQUAL); @sym = caps? ? '+' : '='; add_symbol
  560. elsif Input.repeat?(:kLEFTBRACE); @sym = caps? ? '{' : '['; add_symbol
  561. elsif Input.repeat?(:kRIGHTBRACE); @sym = caps? ? '}' : ']'; add_symbol
  562. elsif Input.repeat?(:kCOLON); @sym = caps? ? ':' : ';'; add_symbol
  563. elsif Input.repeat?(:kAPOSTROPHE); @sym = caps? ? '"' : "'"; add_symbol
  564. elsif Input.repeat?(:kBACKSLASH); @sym = caps? ? '|' : '\\'; add_symbol
  565. elsif Input.repeat?(:kCOMMA); @sym = caps? ? '<' : ','; add_symbol
  566. elsif Input.repeat?(:kPERIOD); @sym = caps? ? '>' : '.'; add_symbol
  567. elsif Input.repeat?(:kSLASH); @sym = caps? ? '?' : '/'; add_symbol
  568.  
  569. # ARROWS
  570. elsif Input.repeat?(:kUP)
  571. #---[=> Help ]
  572. if @string == "/help"
  573. if @current_page < @page.size - 1
  574. se_help; @current_page = [@current_page + 10,@page.size - 1].min
  575. else; return; end
  576. #---[=> Get Next Recent String ]
  577. elsif $game_temp.last_string.size - 1 > @last
  578. se_input
  579. @last += 1
  580. @string = $game_temp.last_string.at(@last)
  581. @cursor_position = @string.size
  582. else; return; end
  583. refresh
  584.  
  585. elsif Input.repeat?(:kDOWN)
  586. #---[=> Help ]
  587. if @string == "/help"
  588. if @current_page > 0
  589. se_help; @current_page = [@current_page - 10,0].max
  590. else; return; end
  591. #---[=> Get Previous Recent String ]
  592. elsif @last > -1
  593. se_input
  594. @last -= 1
  595. @string = @last >= 0 ? $game_temp.last_string.at(@last) : ""
  596. @cursor_position = @string.size
  597. else; return; end
  598. refresh
  599.  
  600. elsif Input.repeat?(:kLEFT)
  601. #---[=> Help ]
  602. if @string == "/help"
  603. if @current_page > 0; se_help; @current_page -= 1; else; return; end
  604. #---[=> Move Cursor ]
  605. elsif @cursor_position > 0
  606. @cursor_position -= 1
  607. @cursor_visibility = 0
  608. else; return; end
  609. refresh
  610.  
  611. elsif Input.repeat?(:kRIGHT)
  612. #---[=> Help ]
  613. if @string == "/help"
  614. if @current_page < @page.size - 1; se_help; @current_page += 1; else; return; end
  615. #---[=> Move Cursor ]
  616. elsif @cursor_position < @string.size && @string != "/help"
  617. @cursor_position += 1
  618. @cursor_visibility = 0
  619. else; return; end
  620. refresh
  621.  
  622.  
  623. # BACKSPACE
  624. elsif Input.repeat?(:kBACKSPACE) && @string.size > 0
  625. se_back
  626. if @cursor_position > 0
  627. @string[@cursor_position - 1] = ""
  628. @cursor_position -= 1
  629. else
  630. @string[@cursor_position] = ""
  631. end
  632. @cursor_visibility = 0
  633. refresh
  634.  
  635. # USE SHORTCUT
  636. elsif Input.trigger?(:kTAB)
  637. check_shortcuts
  638.  
  639. # RUN CODE
  640. elsif Input.trigger?(:kENTER)
  641. begin
  642. scan_string
  643. se_enter
  644. rescue
  645. se_error; SceneManager.scene.dispose_rk5_console
  646. rescue SyntaxError => se
  647. se_error; SceneManager.scene.dispose_rk5_console
  648. end
  649. end
  650. end # FUNCTION!
  651.  
  652. end
  653.  
  654. #-----------------------------------------------------------------------------
  655. # >>> Check Shift Buttons
  656. #-----------------------------------------------------------------------------
  657. def caps?
  658. if Input.press?(:kLSHIFT) || Input.press?(:kRSHIFT)
  659. return true
  660. else
  661. return false
  662. end
  663. end
  664.  
  665. #-----------------------------------------------------------------------------
  666. # >>> Add Symbol
  667. #-----------------------------------------------------------------------------
  668. def add_symbol
  669. se_input
  670. @string.insert(@cursor_position, @sym)
  671. @cursor_position += 1
  672. @cursor_visibility = 0
  673. refresh
  674. end
  675.  
  676. #-----------------------------------------------------------------------------
  677. # >>> Scan String
  678. #-----------------------------------------------------------------------------
  679. def scan_string
  680. #===[ Scan String ]=========================================================
  681. # Store Recently Typed String
  682. $game_temp.last_string.unshift(@string)
  683. # Clean Strings Older Than 50 Entries
  684. $game_temp.last_string.pop if $game_temp.last_string.size > 50
  685. # >>> Toggle Noclip Mode
  686. if @string.start_with? "/noclip"
  687. @string = "$game_temp.noclip = " + ($game_temp.noclip ? "false" : "true")
  688. run_code
  689. # >>> Give All Items
  690. elsif @string.start_with? "/give all"
  691. @string = "$data_items.each {|item| $game_party.gain_item(item, 99)}; " +
  692. "$data_weapons.each {|item| $game_party.gain_item(item, 99)}; " +
  693. "$data_armors.each {|item| $game_party.gain_item(item, 99)}"
  694. run_code
  695. # >>> Lose All Items
  696. elsif @string.start_with? "/lose all"
  697. @string = "$data_items.each {|item| $game_party.gain_item(item, -999)}; " +
  698. "$data_weapons.each {|item| $game_party.gain_item(item, -999)}; " +
  699. "$data_armors.each {|item| $game_party.gain_item(item, -999)}"
  700. run_code
  701. # >>> Give
  702. elsif @string.start_with? "/give"
  703. part = @string.split
  704. if part[1] == "1" || part[1] == "2" || part[1] == "3" # [type] [id] [amount]
  705. case part[1]; when "1"; type = "items"; when "2"; type = "weapons"; when "3"; type = "armors"; end
  706. @string = "$game_party.gain_item($data_" + type + "[" + part[2].to_s + "], " +
  707. part[3].to_s + ")"
  708. else # [name] [amount]
  709. name_parts = @string.split; name_parts.pop; name_parts.shift
  710. name = "'" + name_parts * " " + "'"
  711. @string = "$data_items.each {|item| $game_party.gain_item(item, " + part.last.to_s + ") if item && item.name == " + name.to_s + "}; " +
  712. "$data_weapons.each {|item| $game_party.gain_item(item, " + part.last.to_s + ") if item && item.name == " + name.to_s + "}; " +
  713. "$data_armors.each {|item| $game_party.gain_item(item, " + part.last.to_s + ") if item && item.name == " + name.to_s + "}"
  714. end # id/name
  715. run_code
  716. # >>> Get Gold
  717. elsif @string.start_with? "/gold"
  718. part = @string.split
  719. @string = "$game_party.gain_gold(" + part[1].to_s + ")"
  720. run_code
  721. # >>> Player Transfer Command
  722. elsif @string.start_with? "/tp"
  723. part = @string.split
  724. location = part[1].to_s + "," + part[2].to_s + "," + part[3].to_s
  725. @string = "$game_player.reserve_transfer(" + location + ")"
  726. run_code
  727. # >>> Scene Call
  728. elsif @string.start_with? "/sc"
  729. @string = @string[4, @string.size]
  730. @string = "SceneManager.call(Scene_" + @string + ")"
  731. run_code
  732. # >>> Escape From Battle
  733. elsif @string.start_with? "/run"
  734. @string = "BattleManager.abort"
  735. run_code
  736. # >>> Kill All Enemies
  737. elsif @string.start_with? "/win"
  738. @string = "$game_troop.members.each do |e|; e.hp -= 99999999999; e.perform_collapse_effect; end"
  739. run_code
  740. # >>> Hook Object
  741. elsif @string.start_with? "/hook"
  742. SceneManager.scene.console_hook_object(@string)
  743. @hook = true
  744. refresh_help(3)
  745. @string = SceneManager.scene.console_move_object
  746. refresh
  747. # >>> Asking for the value
  748. elsif @string.end_with? " == ?"
  749. check_for_value
  750. @string = @string + " = " + SceneManager.scene.console_ask_for_value.to_s
  751. @cursor_position = @string.size
  752. refresh
  753. # >>> When there's no special code detected
  754. else
  755. run_code
  756. end
  757.  
  758. end
  759.  
  760. #-----------------------------------------------------------------------------
  761. # >>> Run Code!
  762. #-----------------------------------------------------------------------------
  763. def run_code
  764. if Input.press?(:kPDOWN); @cursor_position = @string.size; refresh; return; end
  765. SceneManager.scene.console_eval_string(@string)
  766. end
  767.  
  768. #-----------------------------------------------------------------------------
  769. # >>> Check For Value
  770. #-----------------------------------------------------------------------------
  771. def check_for_value
  772. # Reset Last String Position
  773. @last = -1
  774. # Clean String From Special Format
  775. @string = @string[0, @string.size - 5]
  776. # Run Code!
  777. SceneManager.scene.console_ask_for_value(@string)
  778. end
  779.  
  780. #-----------------------------------------------------------------------------
  781. # >>> Check For Shortcuts
  782. #-----------------------------------------------------------------------------
  783. def check_shortcuts
  784. if @string.end_with? "#v" #=> VARIABLES
  785. @string = @string.size > 2 ? @string[0, @string.size - 2] : ""
  786. @string += "$game_variables"
  787. shortcut_return_string
  788. elsif @string.end_with? "#s" #=> SWITCHES
  789. @string = @string.size > 2 ? @string[0, @string.size - 2] : ""
  790. @string += "$game_switches"
  791. shortcut_return_string
  792. elsif @string.end_with? "#a" #=> MEMBERS
  793. @string = @string.size > 2 ? @string[0, @string.size - 2] : ""
  794. @string += "$game_party.members"
  795. shortcut_return_string
  796. elsif @string.end_with? "#b" #=> ENEMIES
  797. @string = @string.size > 2 ? @string[0, @string.size - 2] : ""
  798. @string += "$game_troop.members"
  799. shortcut_return_string
  800. end
  801. end
  802.  
  803. def shortcut_return_string(pos = @string.size)
  804. se_enter
  805. @cursor_position = pos
  806. refresh
  807. end
  808.  
  809. end
  810.  
  811. #===============================================================================
  812. # >>> Modification of Scene_Base
  813. #===============================================================================
  814. class Scene_Base
  815.  
  816. #-----------------------------------------------------------------------------
  817. # >>> [OVERWRITE] Main
  818. # -=> Replacing 'update' method with even 'greater' one...
  819. #-----------------------------------------------------------------------------
  820. def main
  821. start
  822. post_start
  823. update_game until scene_changing?
  824. pre_terminate
  825. terminate
  826. end
  827.  
  828. #-----------------------------------------------------------------------------
  829. # >>> [CREATE] Main Update Method
  830. # -=> Takes priority over 'update' method, so that when the console is open,
  831. # everything 'freezes', except that debug window.
  832. #-----------------------------------------------------------------------------
  833. def update_game
  834. if debug_mode?
  835. update_console_only
  836. else
  837. update
  838. end
  839. end
  840.  
  841. #-----------------------------------------------------------------------------
  842. # >>> [CREATE] Checking if Debug Mode is Enabled
  843. # -=> Detects if the console is open.
  844. #-----------------------------------------------------------------------------
  845. def debug_mode?
  846. @rk5_console_window
  847. end
  848.  
  849. #-----------------------------------------------------------------------------
  850. # >>> [ALIAS] Update
  851. # -=> Just adds input detection for a button, that opens the console.
  852. #-----------------------------------------------------------------------------
  853. alias :rk5_console_update :update
  854. def update
  855. rk5_console_update
  856. update_console_call
  857. end
  858.  
  859. #-----------------------------------------------------------------------------
  860. # >>> [CREATE] Update (Console Only)
  861. # -=> Just like the update, but updates only the console window.
  862. #-----------------------------------------------------------------------------
  863. def update_console_only
  864. Graphics.update
  865. Input.update
  866. @rk5_console_window.update
  867. update_console_call
  868. end
  869.  
  870. #-----------------------------------------------------------------------------
  871. # >>> [CREATE] Update Console Call
  872. # -=> Brings or disposes the console when [~] button is pressed.
  873. #-----------------------------------------------------------------------------
  874. def update_console_call
  875. if Input.trigger?(:kTILDE)
  876. if @rk5_console_window == nil
  877. @rk5_console_window = Window_RK5_Debug_Console.new
  878. else
  879. dispose_rk5_console
  880. end
  881. end
  882. end
  883.  
  884. #-----------------------------------------------------------------------------
  885. # >>> [CREATE] Dispose RK5 Console Window
  886. #-----------------------------------------------------------------------------
  887. def dispose_rk5_console
  888. @rk5_console_window.dispose if @rk5_console_window
  889. @rk5_console_window = nil
  890. end
  891.  
  892. #-----------------------------------------------------------------------------
  893. # >>> [CREATE] Console Eval String
  894. # -=> Runs the typed string.
  895. #-----------------------------------------------------------------------------
  896. def console_eval_string(string)
  897. dispose_rk5_console
  898. eval string
  899. end
  900.  
  901. #-----------------------------------------------------------------------------
  902. # >>> [CREATE] Console Ask For Value
  903. # -=> Special Function: Asking for a variable.
  904. # -> Checks the current value of typed variable and returns it to the console.
  905. #-----------------------------------------------------------------------------
  906. def console_ask_for_value(string = nil)
  907. if string != nil
  908. @console_result = nil
  909. @console_result = eval string
  910. @console_result = "nil" if @console_result == nil
  911. else
  912. return @console_result
  913. end
  914. end
  915.  
  916. #-----------------------------------------------------------------------------
  917. # >>> [CREATE] Hook Object
  918. # -=> Special Function: Moves or resizes an object.
  919. # -> Hooks an object to move or resize it by input.
  920. #-----------------------------------------------------------------------------
  921. def console_hook_object(string,get_object = false)
  922. return @console_hooked_object_name if get_object
  923. object = string[6, string.size]
  924. @console_hooked_object_name = object
  925. @console_hooked_object = eval object
  926. end
  927.  
  928. #-----------------------------------------------------------------------------
  929. # >>> [CREATE] Console Move Object - Hook Object Function
  930. # -> Performs an action and stores object's parameters.
  931. #-----------------------------------------------------------------------------
  932. def console_move_object(dir="x",dist=0,rewi=0,rehei=0,opac=0)
  933. obj = @console_hooked_object
  934. object = instance_variable_get(@console_hooked_object_name)
  935. obj.x += dist if dir == "x" && dist != 0
  936. obj.y += dist if dir == "y" && dist != 0
  937. obj.z += dist if dir == "z" && dist != 0
  938. obj.width += rewi if rewi != 0 && object.is_a?(Window)
  939. obj.height += rehei if rehei != 0 && object.is_a?(Window)
  940. obj.opacity += opac if opac != 0
  941. object_parameters = "x: " + obj.x.to_s + " | y: " + obj.y.to_s + " | z: " + obj.z.to_s +
  942. " | w: " + obj.width.to_s + " | h: " + obj.height.to_s + " | o: " + obj.opacity.to_s
  943. return object_parameters
  944. end
  945.  
  946. end
  947.  
  948. class Game_Player < Game_Character
  949. #-----------------------------------------------------------------------------
  950. # >>> [ALIAS] debug_through?
  951. # -> Implements Noclip Mode.
  952. #--------------------------------------------------------------------------
  953. alias :rk5_console_debug_through? :debug_through?
  954. def debug_through?
  955. rk5_console_debug_through? || $game_temp.noclip
  956. end
  957. end
  958.  
  959. #===============================================================================
  960. # >>> Store Recently Typed String
  961. #===============================================================================
  962. class Game_Temp
  963. attr_accessor :last_string
  964. attr_accessor :noclip
  965.  
  966. alias :rk5_console_initialize :initialize
  967. def initialize
  968. rk5_console_initialize
  969. @last_string = []
  970. @noclip = false
  971. end
  972. end
Add Comment
Please, Sign In to add comment