Advertisement
diamondandplatinum3

Idle Dialogue Exit ~ RGSS3

Jul 24th, 2013
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 16.05 KB | None | 0 0
  1. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  2. #             Idle Dialogue Exit
  3. #             Version: 1.1
  4. #             Author: DiamondandPlatinum3
  5. #             Date: July 23, 2013
  6. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. #  Description:
  8. #
  9. #    This script allows you to set an automatic continuation when your
  10. #    player is not being responsive.
  11. #    Basically if your player has not read the text in the textbox before a
  12. #    specified amount of time, you can allow it so that the NPC talking to them
  13. #    can do one of two things.
  14. #       1) Move on to the Next Event Command (this is just the next command
  15. #          in the list; so it may be another text box or a battle)
  16. #       2) Exit event processing entirely. This NPC will start doing all the
  17. #          things they were doing before you bothered them and act like you
  18. #          never spoke to them
  19. #
  20. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  21. #------------------------------------------------------------------------------
  22. #  Instructions:
  23. #
  24. #  ~  Just before a Textbox you wish Idle Dialogue Rules to apply, you must
  25. #     insert the following script call:
  26. #               begin_idle_dialogue_exit(seconds)
  27. #     Replacing 'seconds' with the time you will allow. This is done with decimals
  28. #     ie: Five seconds would be inputted as 5.0, or you can have it wait for 5.3
  29. #     seconds, etc.
  30. #
  31. #
  32. #  ~  By default the NPCs will just skip to their next event command when being
  33. #     ignored. If you'd like them to quit event processing, you must add 'true'
  34. #     inside that script call:
  35. #               begin_idle_dialogue_exit(seconds, true)
  36. #     Now whenever you ignore an NPC, they will quit event processing.
  37. #
  38. #
  39. #  ~  Additionally you may also set a Self-Switch or Event-Switch to activate
  40. #     once you have ignored an NPC. To do so you must insert a third parameter
  41. #     after the previous two so that it looks like so.
  42. #               begin_idle_dialogue_exit(seconds, true, ???)
  43. #     Replacing the question marks with either one of two things:
  44. #
  45. #       1) For Self-Switches, you must insert the Self_Switch inside of Quotation
  46. #          Marks. ie "A", "B", "C", "D".
  47. #
  48. #       2) For Event-Switches, you must insert a whole number value to represent
  49. #          the event switch id you wish to turn on.
  50. #
  51. #
  52. #
  53. #  ~  Example Screenshots of the above can be found here:
  54. #           http://i.imgur.com/D4iAwHk.png
  55. #           http://i.imgur.com/Nhr5gwt.png
  56. #           http://i.imgur.com/1WbX01M.png
  57. #           http://i.imgur.com/WtBlDE6.png
  58. #
  59. #------------------------------------------------------------------------------
  60. #  Engine Modifications:
  61. #
  62. #   ~ class Window_Message:
  63. #       input_choice        (overwritten)
  64. #       input_number        (overwritten)
  65. #       input_item          (overwritten)  
  66. #       input_pause         (overwritten)
  67. #                                       Needed to overwrite the Fiber.yield in
  68. #                                       all these methods.
  69. #
  70. #   ~ class Window_NumberInput:
  71. #       process_cursor_move (aliased)
  72. #
  73. #   ~ class Window_ChoiceList:
  74. #       process_cursor_move (aliased)
  75. #
  76. #   ~ class Window_ItemList:
  77. #       process_cursor_move (aliased)
  78. #
  79. #
  80. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  81. #
  82. #               THERE IS NO EDITABLE REGION TO THIS SCRIPT
  83. #
  84. #=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  85.  
  86.  
  87.  
  88. #==============================================================================
  89. # ** Game_Temp
  90. #------------------------------------------------------------------------------
  91. #  This class handles temporary data that is not included with save data.
  92. # The instance of this class is referenced by $game_temp.
  93. #==============================================================================
  94.  
  95. class Game_Temp
  96.   #--------------------------------------------------------------------------
  97.   # * Struct.new
  98.   #--------------------------------------------------------------------------
  99.   DialogueIdleCancel = Struct.new(:active, :event_id, :start_time, :idle_time, :exit_event_processing, :event_control) do
  100.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  101.     # * New Method: Start
  102.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  103.     def start(seconds, evnt_id, exit_processing, event_control_switch)
  104.       self.event_id               = evnt_id
  105.       self.exit_event_processing  = exit_processing
  106.       self.idle_time              = seconds
  107.       self.event_control          = event_control_switch
  108.       enable()
  109.       reset_start_timer()
  110.     end
  111.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  112.     # * New Method: Total Game Time
  113.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  114.     def total_game_time()
  115.       return (Graphics.frame_count.to_f / Graphics.frame_rate)
  116.     end
  117.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118.     # * New Method: Current Time
  119.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  120.     def current_time()
  121.       return (total_game_time() - self.start_time)
  122.     end
  123.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  124.     # * New Method: Time is Up?
  125.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  126.     def time_up?()
  127.       return (active?() && (current_time() > self.idle_time))
  128.     end
  129.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  130.     # * New Method: Enable
  131.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  132.     def enable()
  133.       self.active = true
  134.     end
  135.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  136.     # * New Method: Disable
  137.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  138.     def disable()
  139.       self.active = false
  140.     end
  141.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  142.     # * New Method: Reset Event
  143.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  144.     def reset_event()
  145.       $game_message.clear()
  146.       $game_map.events[self.event_id].dp3_get_local_interpreter_instance().dp3_cleareventcommandslist() if self.exit_event_processing
  147.    
  148.       $game_switches[self.event_control] = true if self.event_control.is_a?(Integer)
  149.       $game_map.events[self.event_id].dp3_get_local_interpreter_instance().dp3_activateeventselfswitch(self.event_control) if self.event_control.is_a?(String)
  150.     end
  151.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  152.     # * New Method: Reset All
  153.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  154.     def reset()
  155.       reset_event()
  156.       disable()
  157.     end
  158.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  159.     # * New Method: Reset Start Timer
  160.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  161.     def reset_start_timer()
  162.       self.start_time = total_game_time()
  163.     end
  164.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  165.     # * New Method: Am I Active?
  166.     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  167.     def active?()
  168.       return self.active
  169.     end
  170.   end
  171.   #--------------------------------------------------------------------------
  172.   # * Public Instance Variables
  173.   #--------------------------------------------------------------------------
  174.   attr_reader   :dp3_idledialoguecancel_instance    # Instance of DialogueIdleCancel
  175.   #--------------------------------------------------------------------------
  176.   # * Object Initialization
  177.   #--------------------------------------------------------------------------
  178.   alias dp3_dialogueidlecancel_gametemp_init_qpf7         initialize
  179.   def initialize(*args)
  180.     @dp3_idledialoguecancel_instance = DialogueIdleCancel.new(false, 0, 0.0, 0.0, false)
  181.     dp3_dialogueidlecancel_gametemp_init_qpf7(*args) # Call Original Method
  182.   end
  183. end
  184.  
  185.  
  186.  
  187. #==============================================================================
  188. # ** Window_Message
  189. #------------------------------------------------------------------------------
  190. #  This message window is used to display text.
  191. #==============================================================================
  192.  
  193. class Window_Message < Window_Base
  194.   #--------------------------------------------------------------------------
  195.   # * Overwritten Method: Choice Input Processing
  196.   #--------------------------------------------------------------------------
  197.   def input_choice
  198.     $game_temp.dp3_idledialoguecancel_instance.reset_start_timer()
  199.    
  200.     @choice_window.start
  201.     Fiber.yield while @choice_window.active && !$game_temp.dp3_idledialoguecancel_instance.time_up?()
  202.    
  203.     if $game_temp.dp3_idledialoguecancel_instance.time_up?()
  204.       @choice_window.active = false
  205.       @choice_window.close
  206.       $game_temp.dp3_idledialoguecancel_instance.reset()
  207.     end
  208.   end
  209.   #--------------------------------------------------------------------------
  210.   # * Overwritten Method: Number Input Processing
  211.   #--------------------------------------------------------------------------
  212.   def input_number
  213.     $game_temp.dp3_idledialoguecancel_instance.reset_start_timer()
  214.    
  215.     @number_window.start
  216.     Fiber.yield while @number_window.active && !$game_temp.dp3_idledialoguecancel_instance.time_up?()
  217.    
  218.     if $game_temp.dp3_idledialoguecancel_instance.time_up?()
  219.       @number_window.active = false
  220.       @number_window.close
  221.       $game_temp.dp3_idledialoguecancel_instance.reset()
  222.     end
  223.   end
  224.   #--------------------------------------------------------------------------
  225.   # * Overwritten Method: Item Selection Processing
  226.   #--------------------------------------------------------------------------
  227.   def input_item
  228.     $game_temp.dp3_idledialoguecancel_instance.reset_start_timer()
  229.    
  230.     @item_window.start
  231.     Fiber.yield while @item_window.active && !$game_temp.dp3_idledialoguecancel_instance.time_up?()
  232.    
  233.     if $game_temp.dp3_idledialoguecancel_instance.time_up?()
  234.       @item_window.active = false
  235.       @item_window.close
  236.       $game_temp.dp3_idledialoguecancel_instance.reset()
  237.     end
  238.   end
  239.   #--------------------------------------------------------------------------
  240.   # * Overwritten Method: Input Pause Processing
  241.   #--------------------------------------------------------------------------
  242.   def input_pause
  243.     $game_temp.dp3_idledialoguecancel_instance.reset_start_timer()
  244.  
  245.     self.pause = true
  246.     wait(10)
  247.     Fiber.yield until Input.trigger?(:B) || Input.trigger?(:C) || $game_temp.dp3_idledialoguecancel_instance.time_up?()
  248.     Input.update
  249.     self.pause = false
  250.    
  251.     if $game_temp.dp3_idledialoguecancel_instance.time_up?()
  252.       $game_temp.dp3_idledialoguecancel_instance.reset()
  253.     end
  254.   end
  255. end
  256.  
  257.  
  258.  
  259. #==============================================================================
  260. # ** Window_NumberInput
  261. #------------------------------------------------------------------------------
  262. #  This window is used for the event command [Input Number].
  263. #==============================================================================
  264.  
  265. class Window_NumberInput < Window_Base
  266.   #--------------------------------------------------------------------------
  267.   # * Aliased Method: Cursor Movement Processing
  268.   #--------------------------------------------------------------------------
  269.   alias dp3_idledialogueexit_windownumberinput_processcursormove_wof    process_cursor_move
  270.   def process_cursor_move(*args)
  271.     if self.active
  272.       $game_temp.dp3_idledialoguecancel_instance.reset_start_timer() if Input.press?(:RIGHT) || Input.press?(:LEFT) || Input.press?(:UP) || Input.press?(:DOWN)
  273.     end
  274.     dp3_idledialogueexit_windownumberinput_processcursormove_wof(*args)
  275.   end
  276. end
  277.  
  278.  
  279.  
  280. #==============================================================================
  281. # ** Window_ChoiceList
  282. #------------------------------------------------------------------------------
  283. #  This window is used for the event command [Show Choices].
  284. #==============================================================================
  285.  
  286. class Window_ChoiceList < Window_Command
  287.   #--------------------------------------------------------------------------
  288.   # * Aliased Method: Cursor Movement Processing
  289.   #--------------------------------------------------------------------------
  290.   alias dp3_idledialogueexit_windowchoicelist_processcursormove_wof    process_cursor_move
  291.   def process_cursor_move(*args)
  292.     if self.active
  293.       $game_temp.dp3_idledialoguecancel_instance.reset_start_timer() if Input.press?(:RIGHT) || Input.press?(:LEFT) || Input.press?(:UP) || Input.press?(:DOWN)
  294.     end
  295.     dp3_idledialogueexit_windowchoicelist_processcursormove_wof(*args)
  296.   end
  297. end
  298.  
  299.  
  300.  
  301. #==============================================================================
  302. # ** Window_ItemList
  303. #------------------------------------------------------------------------------
  304. #  This window displays a list of party items on the item screen.
  305. #==============================================================================
  306.  
  307. class Window_ItemList < Window_Selectable
  308.   #--------------------------------------------------------------------------
  309.   # * Aliased Method: Cursor Movement Processing
  310.   #--------------------------------------------------------------------------
  311.   alias dp3_idledialogueexit_windowitemlist_processcursormove_wof    process_cursor_move
  312.   def process_cursor_move(*args)
  313.     if self.active
  314.       $game_temp.dp3_idledialoguecancel_instance.reset_start_timer() if Input.press?(:RIGHT) || Input.press?(:LEFT) || Input.press?(:UP) || Input.press?(:DOWN)
  315.     end
  316.     dp3_idledialogueexit_windowitemlist_processcursormove_wof(*args)
  317.   end
  318. end
  319.  
  320.  
  321.  
  322. #==============================================================================
  323. # ** Game_Event
  324. #------------------------------------------------------------------------------
  325. #  This class handles events. Functions include event page switching via
  326. # condition determinants and running parallel process events. Used within the
  327. # Game_Map class.
  328. #==============================================================================
  329.  
  330. class Game_Event < Game_Character
  331.   #--------------------------------------------------------------------------
  332.   # * Get Local Interpreter Instance
  333.   #--------------------------------------------------------------------------
  334.   def dp3_get_local_interpreter_instance
  335.     return @intepreter if @interpreter
  336.     return $game_map.interpreter
  337.   end
  338. end
  339.  
  340.  
  341.  
  342.  
  343. #==============================================================================
  344. # ** Game_Interpreter
  345. #------------------------------------------------------------------------------
  346. #  An interpreter for executing event commands. This class is used within the
  347. # Game_Map, Game_Troop, and Game_Event classes.
  348. #==============================================================================
  349.  
  350. class Game_Interpreter
  351.   #--------------------------------------------------------------------------
  352.   # * Begin Idle Dialogue Cancel
  353.   #--------------------------------------------------------------------------
  354.   def begin_idle_dialogue_exit(seconds, exit_event_processing = false, switch_control = nil)
  355.     switch_control        = switch_control[0].upcase  if switch_control.is_a?(String)
  356.     switch_control        = nil                       unless switch_control.is_a?(Integer) || switch_control.is_a?(String)
  357.     exit_event_processing = false                     unless !!exit_event_processing == exit_event_processing
  358.     $game_temp.dp3_idledialoguecancel_instance.start(seconds.to_f, @event_id, exit_event_processing, switch_control)
  359.   end
  360.   #--------------------------------------------------------------------------
  361.   # * Clear Event Commands List
  362.   #--------------------------------------------------------------------------
  363.   def dp3_cleareventcommandslist()
  364.     @list = []
  365.   end
  366.   #--------------------------------------------------------------------------
  367.   # * Activate Self-Switch
  368.   #--------------------------------------------------------------------------
  369.   def dp3_activateeventselfswitch(selfswitchid)
  370.     @params[0] = selfswitchid
  371.     @params[1] = 0
  372.     command_123()
  373.   end
  374. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement