SSTrihan

HorrorVale choice timer script

Apr 29th, 2022 (edited)
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.57 KB | None | 0 0
  1. #-------------------------------------------------------------------------------
  2. # Don't remove this header!
  3. #-------------------------------------------------------------------------------
  4. # Timed choices
  5. # by Trihan
  6. #
  7. # Version : 1.1
  8. #
  9. # This script is commissioned by Batworks Software.
  10. #-------------------------------------------------------------------------------
  11.  
  12. #-------------------------------------------------------------------------------
  13. # Version History
  14. #-------------------------------------------------------------------------------
  15. # 1.1 - Added an on-screen timer for the choices.
  16. # 1.0 - Initial script.
  17. #-------------------------------------------------------------------------------
  18.  
  19. #-------------------------------------------------------------------------------
  20. # This script allows for a timer in the choice window that can call a branch
  21. # after a certain number of frames has elapsed without the player making a
  22. # choice.
  23. #
  24. # To activate it, add the following script call before the choice:
  25. # $game_message.start_choice_timer(number_of_frames)
  26. #
  27. # Example: $game_message.start_choice_timer(120) for a 2-second delay.
  28. #
  29. # For best results, select the "Branch" option in the "When Cancel" section.
  30. # When the timer expires, it will run the code inside the cancel branch.
  31. #-------------------------------------------------------------------------------
  32. #==============================================================================
  33. # ** Sprite_Timer
  34. #------------------------------------------------------------------------------
  35. #  This sprite is for timer displays. It monitors $game_timer and automatically
  36. # changes sprite states.
  37. #==============================================================================
  38.  
  39. class Game_Message
  40.   attr_reader :choice_timer
  41.   alias :tlb_game_show_clear :clear
  42.   def clear
  43.     tlb_game_show_clear
  44.     @choice_timer = nil
  45.   end
  46.  
  47.   def start_choice_timer(frames)
  48.     @choice_timer = frames
  49.   end
  50.  
  51.   def update
  52.     if @choice_timer
  53.       @choice_timer -= 1
  54.     end
  55.   end
  56.  
  57.   def choice_time
  58.     (@choice_timer || 0 / Graphics.frame_rate).to_f
  59.   end
  60.  
  61.   def choice_timer_working?
  62.     @choice_timer && @choice_timer > 0
  63.   end
  64. end
  65.  
  66. class Sprite_ChoiceTimer < Sprite_Timer
  67.   def update_bitmap
  68.     if $game_message.choice_time != @total_sec
  69.       @total_sec = $game_message.choice_time
  70.       redraw
  71.     end
  72.   end
  73.  
  74.   def timer_text
  75.     sprintf("%3.2f", @total_sec / 60)
  76.   end
  77.  
  78.   def update_position
  79.     self.x = Graphics.width / 2 - self.bitmap.width / 2
  80.     self.y = 0
  81.     self.z = 200
  82.   end
  83.  
  84.   def update_visibility
  85.     self.visible = $game_message.choice_timer_working?
  86.   end
  87. end
  88.  
  89. class Spriteset_Map
  90.   alias :tlb_game_show_create_timer :create_timer
  91.   def create_timer
  92.     tlb_game_show_create_timer
  93.     @choice_timer_sprite = Sprite_ChoiceTimer.new(@viewport2)
  94.   end
  95.  
  96.   alias :tlb_game_show_dispose_timer :dispose_timer
  97.   def dispose_timer
  98.     tlb_game_show_dispose_timer
  99.     @choice_timer_sprite.dispose
  100.   end
  101.  
  102.   alias :tlb_game_show_update_timer :update_timer
  103.   def update_timer
  104.     tlb_game_show_update_timer
  105.     @choice_timer_sprite.update
  106.   end
  107. end
  108.  
  109. class Window_ChoiceList < Window_Command
  110.   def update
  111.     super
  112.     if $game_message.choice_timer && $game_message.choice_timer == 0
  113.       process_cancel
  114.     end
  115.   end
  116. end
  117.  
  118. class Scene_Map < Scene_Base
  119.   def update
  120.     super
  121.     $game_map.update(true)
  122.     $game_player.update
  123.     $game_timer.update
  124.     $game_message.update
  125.     @spriteset.update
  126.     update_scene if scene_change_ok?
  127.   end
  128. end
Add Comment
Please, Sign In to add comment