Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #==============================================================================
  2. # Scene Tutorial
  3. # Version 1.0
  4. # Original Author: modern algebra (rmrk.net)
  5. # Date: September 15, 2008
  6. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  7. # Scene Tutorial to VX ACE
  8. # Version 1.1
  9. # Author: TinyMine (rpgmaker-vx-ace.de)
  10. # Date: 15.06.2014
  11. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  12. # Description:
  13. # This script allows you to freeze user input for a scene and run a special
  14. # common event that controls input. Effectively, this allows you to run a
  15. # scene and direct a tutorial to that scene that explains what the scene is.
  16. # So, if you ever wanted to give the players to your game a tutorial on
  17. # using the Menu scene, then this is the script for you.
  18. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  19. # Instructions:
  20. # Okay, this script can be slightly difficult to use, so you have to pay
  21. # careful attention to the instructions.
  22. #
  23. # To start a tutorial, you must use a call script with this code:
  24. #
  25. # start_tutorial(scene, common_id, return_scene)
  26. #
  27. # where scene is the name of the scene to call, (like Scene_Menu or
  28. # Scene_Battle) and common event ID is the ID of the common event that
  29. # controls the tutorial. Return_scene however is the true or false - true
  30. # for returning to last scene when tutorial was called and false for staying
  31. # in the scene, when tutorial is finished. Now, that's the easy part. Setting
  32. # up the controller common event will be tricky at first, but once you get the
  33. # hang of it, you'll be fine. Now, read the instructions very carefully:
  34. #
  35. # The Standard Wait Variable - You set what Variable this will be at line
  36. # 200. The value of this variable determines how many frames to wait for
  37. # after each command.
  38. #
  39. # The controller common event is similar to a regular common event in some
  40. # ways but many of the commands will be unavailable to you while others will
  41. # be irrelevant and others still will have a different effect than you would
  42. # expect. In the instructions, I will go over the functions of what will be
  43. # the most important commands in making a scene tutorial, but I just wanted
  44. # to warn you that many commands will not work as you expect them to. (For
  45. # instance, pictures, screen tone etc... will only work in a battle or map
  46. # tutorial). So, depending on how the scene is built, some things are
  47. # possible while others are not. Note, however, that in a number of cases,
  48. # you can simulate the effect that is not possible. That being said, it can
  49. # get quite convoluted, but that was as far as I was willing to go with this
  50. # script. I apologize for the difficulty.
  51. #
  52. # Anyway, there are a couple of specialized commands that have their function
  53. # changed from what they would normally do. These are:
  54. #
  55. # Control Variable
  56. # Set Move Route
  57. #
  58. # These have been changed so that rather than do what they would normally,
  59. # they instead interpret input. Since player input is frozen during a
  60. # tutorial, scene movement is handled by you, the game creator. It is done
  61. # through these two commands. This can be rather non-intuitive, but for each
  62. # value of 0 through 19, a button is attached. It is similar for Set Move
  63. # Route, but let's go over the variable way of setting input first.
  64. #
  65. # To set it, it must be a single variable set to a constant. If any other
  66. # option is chosen, then the Control Variable command will function normally.
  67. # Also, the control variable command will behave normally if the variable you
  68. # choose is the one you choose for setting standard wait time. Anyway, here
  69. # is the list of values and their effects:
  70. #
  71. # 0 - Down Cursor
  72. # 1 - Left Cursor
  73. # 2 - Right Cursor
  74. # 3 - Up Cursor
  75. # 4 - Button A
  76. # 5 - Button B
  77. # 6 - Button C
  78. # 7 - Button X
  79. # 8 - Button Y
  80. # 9 - Button Z
  81. # 10 - Button L
  82. # 11 - Button R
  83. # 12 - SHIFT
  84. # 13 - CTRL
  85. # 14 - ALT
  86. # 15 - F5
  87. # 16 - F6
  88. # 17 - F7
  89. # 18 - F8
  90. # 19 - F9
  91. #
  92. # If you want to wait some frames, the Wait command will work normally.
  93. #
  94. # Set Move Route has a similar set of moves attached. They are:
  95. # Move Down - Down Cursor
  96. # Move Left - Left Cursor
  97. # Move Right - Right Cursor
  98. # Move Up - Up Cursor
  99. # Move Lower Left - Button A
  100. # Move Lower Right - Button B
  101. # Move Upper Left - Button C
  102. # Move Upper Right - Button X
  103. # Move at Random - Button Y
  104. # Move Toward Player - Button Z
  105. # Move Away from Player - Button L
  106. # One Step Forward - Button R
  107. # One Step Backward - SHIFT
  108. # Jump - CTRL
  109. # Wait - Waits for however many frames
  110. # Turn Down - ALT
  111. # Turn Left - F5
  112. # Turn Right - F6
  113. # Turn Up - F7
  114. # Turn 90 Left - F8
  115. # Turn 90 Right - F9
  116. #
  117. # So basically, using those commands will make the scene react as if the
  118. # corresponding button had just been pressed.
  119. #==============================================================================
  120. # *** Input
  121. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  122. # Summary of Changes:
  123. # aliased method - update, trigger?, press?, repeat?
  124. #==============================================================================
  125. module Input class << self
  126. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  127. # * Frame Update
  128. #````````````````````````````````````````````````````````````````````````
  129. # Reset the Button if Input.update was not called from default scene update
  130. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  131. alias modalg_tutorials_update_9rt
  132. update unless self.method_defined? :)modalg_tutorials_update_9rt)
  133. def update
  134. if $tutorial.active? && caller[0][/`([^']*)'/, 1] != "update_basic"
  135. $tutorial.button = false
  136. end
  137. # Run Original Method
  138. modalg_tutorials_update_9rt
  139. end
  140. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  141. # * Trigger?
  142. #````````````````````````````````````````````````````````````````````````
  143. # If Tutorial is running, freezes input and accepts only tutorial input
  144. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  145. alias modalg_tut_frz_inpt_trig_dj5 trigger?
  146. unless self.method_defined? :)modalg_tut_frz_inpt_trig_dj5)
  147. def trigger? (key)
  148. if $tutorial.active? && !$tutorial.upd_input
  149. return $tutorial.button == key
  150. end
  151. # Run Original Method
  152. modalg_tut_frz_inpt_trig_dj5 (key)
  153. end
  154. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  155. # * Repeat?
  156. #````````````````````````````````````````````````````````````````````````
  157. # If Tutorial is running, freezes input and accepts only tutorial input
  158. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  159. alias modalg_rpt_tutorial_upd_8fn repeat?
  160. unless self.method_defined? :)modalg_rpt_tutorial_upd_8fn)
  161. def repeat? (key)
  162. if $tutorial.active? && !$tutorial.upd_input
  163. return $tutorial.button == key
  164. end # Run Original Method
  165. modalg_rpt_tutorial_upd_8fn (key)
  166. end
  167. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  168. # * Press?
  169. #````````````````````````````````````````````````````````````````````````
  170. # If Tutorial is running, freezes input and accepts only tutorial input
  171. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  172. alias modalg_tut_prs_frz_inpt_9nfg press?
  173. unless self.method_defined? :)modalg_tut_prs_frz_inpt_9nfg)
  174. def press? (key)
  175. if $tutorial.active? && !$tutorial.upd_input
  176. return $tutorial.button == key
  177. end
  178. # Run Original Method
  179. modalg_tut_prs_frz_inpt_9nfg (key)
  180. end
  181. end
  182. end
  183. #==============================================================================
  184. # *** Scene_Base
  185. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  186. # Summary of Changes:
  187. # aliased method - update_basic
  188. #==============================================================================
  189. class Scene_Base
  190. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  191. # * Frame Update
  192. #````````````````````````````````````````````````````````````````````````
  193. # Updates tutorial as well if it exists. Update along with scenes to sync
  194. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  195. alias_method :modalg_tut_upd_sce_base_3837 ,:update_basic
  196. def update_basic
  197. modalg_tut_upd_sce_base_3837
  198. $tutorial.update if $tutorial.active?
  199. end
  200. end
  201. #==============================================================================
  202. # ** Game_Interpreter
  203. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  204. # Summary of Changes:
  205. # new method: start_tutorial
  206. #==============================================================================
  207. class Game_Interpreter
  208. def start_tutorial(scene, common_id, return_scene)
  209. $tutorial.start(scene,common_id, return_scene)
  210. # Execute hack command to avoid fiber resuming in new scene
  211. wait(1)
  212. end
  213. end
  214. #==============================================================================
  215. # ** Tutorial Guide
  216. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  217. # This class handles the interpretation of the common event for a tutorial
  218. #==============================================================================
  219. class Game_TutorialGuide < Game_Interpreter
  220. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  221. # * Constant
  222. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  223. # STANDARD WAIT VARIABLE is the ID of the event variable that holds a
  224. # standard wait between input commands. Basically, if this is set to 2,
  225. # then Variable with ID 2 will control the wait between actions. So, if
  226. # Variable with ID 2 is set to 4, then it will wait four frames before
  227. # executing the next command in the common event STANDARD_WAIT_VARIABLE = 97
  228. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  229. # * Object Initialization
  230. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  231. def initialize @wait_frames = 0
  232. super
  233. end
  234. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  235. # * Execute Fiber
  236. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  237. def run
  238. wait_for_transition
  239. super
  240. end
  241. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  242. # * Control Variable
  243. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  244. def command_122
  245. if @params[3] == 0 || @params[0] == STANDARD_WAIT_VARIABLE
  246. command_input (@params[4] + 1)
  247. else
  248. super
  249. end
  250. end
  251. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  252. # * Set Move Route
  253. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  254. def command_205
  255. @move_route = @params[1].list
  256. @moveroute_index = 0
  257. while @move_route[@moveroute_index]
  258. # Execute Input command
  259. command_move (@move_route[@moveroute_index])
  260. @moveroute_index += 1
  261. Fiber.yield
  262. end
  263. end
  264. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  265. # * Frame Update
  266. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  267. def update
  268. return unless Graphics.brightness == 255
  269. if @wait_frames > 0
  270. @wait_frames -= 1
  271. return
  272. end
  273. super
  274. return false unless @fiber
  275. end
  276. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  277. # * Command Input
  278. # button_code : the key a button corresponds to.
  279. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  280. def command_input (button_value)
  281. $tutorial.button = case button_value
  282. when 1 then Input::DOWN
  283. # Cursor Down
  284. when 2 then Input::LEFT
  285. # Cursor Left
  286. when 3 then Input::RIGHT
  287. # Cursor Right
  288. when 4 then Input::UP
  289. # Cursor Up
  290. when 5 then Input::A
  291. # Press A
  292. when 6 then Input::B
  293. # Press B
  294. when 7 then Input::C
  295. # Press C
  296. when 8 then Input::X
  297. # Press X
  298. when 9 then Input::Y
  299. # Press Y
  300. when 10 then Input::Z
  301. # Press Z
  302. when 11 then Input::L
  303. # Press L
  304. when 12 then Input::R
  305. # Press R
  306. when 13 then Input::SHIFT
  307. # Press SHIFT
  308. when 14 then Input::CTRL
  309. # Press CTRL
  310. when 15 then Input::ALT
  311. # Press ALT
  312. when 16 then Input::F5
  313. # Press F5
  314. when 17 then Input::F6
  315. # Press F6
  316. when 18 then Input::F7
  317. # Press F7
  318. when 19 then Input::F8
  319. # Press F8
  320. when 20 then Input::F9
  321. # Press F9
  322. end
  323. @wait_frames = [$game_variables[STANDARD_WAIT_VARIABLE], 1].max
  324. end
  325. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  326. # * Command Move
  327. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  328. def command_move (command)
  329. command_input (command.code) if command.code < 15
  330. command_wait (command.parameters[0] - 1)
  331. if command.code == 15
  332. command_input (command.code - 1)
  333. if command.code.between?(16,21)
  334. end
  335. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  336. # * Command Wait
  337. # duration : the number of frames to wait
  338. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  339. def command_wait (duration)
  340. # Wait Frames - Subtract Standard wait frames tacked on by previous command
  341. @wait_frames = duration
  342. end
  343. def wait_for_transition
  344. Fiber.yield until Graphics.brightness == 255
  345. end
  346. end
  347. #==============================================================================
  348. # ** Tutorial
  349. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  350. # This class basically interprets a common event and navigates a scene by the
  351. # codes used in that common event
  352. #==============================================================================
  353. class Tutorial
  354. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  355. # * Public Instance Variables
  356. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  357. attr_reader :upd_input attr_accessor :button
  358. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  359. # * Object Initialization
  360. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  361. def initialize
  362. # Initialize variables
  363. @button = false
  364. @upd_input = false
  365. @active = false
  366. @tutorial_guide = Game_TutorialGuide.new
  367. end
  368. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  369. # * Start
  370. # scene : the scene to guide through
  371. # common_event_id : the navigation common event
  372. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  373. def start (scene, common_event_id, return_last)
  374. @tutorial_guide.setup ($data_common_events[common_event_id].list)
  375. if !!return_last == return_last
  376. return_last ? @old_scene = SceneManager.scene.class : @old_scene = nil
  377. else
  378. defined?(return_last) ? @old_scene = return_last : @old_scene = nil
  379. end Window_MenuCommand::init_command_position
  380. # if Scene_Menu SceneManager.call(scene)
  381. # Get Common Event
  382. @active = true @message_window = Window_Message.new if @message_window.nil?
  383. @message_window.z = 500
  384. end
  385. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  386. # * Update
  387. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  388. def update @button = false
  389. # Deactivate Input update and Tutorial update while message is active
  390. @upd_input = true @active = false @message_window.update
  391. # Reactivate Input update and Tutorial update when message is done
  392. @upd_input = false @active = true if $game_message.visible
  393. return
  394. end
  395. if @tutorial_guide.update == false @active = false
  396. SceneManager.call(@old_scene) unless @old_scene.nil?
  397. end
  398. end
  399. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  400. # * Active?
  401. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  402. def active? return @active
  403. end
  404. end
  405. #==============================================================================
  406. # ** DataManager
  407. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  408. # Summary of Changes:
  409. # aliased methods - load_normal_database, load_battle_test_database
  410. #==============================================================================
  411. module DataManager
  412. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  413. # * Load Database
  414. #``````````````````````````````````````````````````````````````````````````
  415. # Initialize $tutorial
  416. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  417. class << self alias modalg_tutorial_scenes_ldb_init_nf4 load_normal_database
  418. alias modalg_tutrl_scn_lbtdb_ak42 load_battle_test_database
  419. end
  420. def self.load_normal_database
  421. # Run Original Method
  422. modalg_tutorial_scenes_ldb_init_nf4
  423. # Initialize Tutorial
  424. $tutorial = Tutorial.new
  425. end
  426. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  427. # * Load Battle Test Database
  428. #``````````````````````````````````````````````````````````````````````````
  429. # Initialize $tutorial
  430. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  431. def self.load_battle_test_database
  432. # Run Original Method
  433. modalg_tutrl_scn_lbtdb_ak42
  434. # Initialize Tutorial
  435. $tutorial = Tutorial.new
  436. end
  437. end