Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-------------------------------------------------------------------------------
- # Don't remove this header!
- #-------------------------------------------------------------------------------
- # Timed choices
- # by Trihan
- #
- # Version : 1.1
- #
- # This script is commissioned by Batworks Software.
- #-------------------------------------------------------------------------------
- #-------------------------------------------------------------------------------
- # Version History
- #-------------------------------------------------------------------------------
- # 1.1 - Added an on-screen timer for the choices.
- # 1.0 - Initial script.
- #-------------------------------------------------------------------------------
- #-------------------------------------------------------------------------------
- # This script allows for a timer in the choice window that can call a branch
- # after a certain number of frames has elapsed without the player making a
- # choice.
- #
- # To activate it, add the following script call before the choice:
- # $game_message.start_choice_timer(number_of_frames)
- #
- # Example: $game_message.start_choice_timer(120) for a 2-second delay.
- #
- # For best results, select the "Branch" option in the "When Cancel" section.
- # When the timer expires, it will run the code inside the cancel branch.
- #-------------------------------------------------------------------------------
- #==============================================================================
- # ** Sprite_Timer
- #------------------------------------------------------------------------------
- # This sprite is for timer displays. It monitors $game_timer and automatically
- # changes sprite states.
- #==============================================================================
- class Game_Message
- attr_reader :choice_timer
- alias :tlb_game_show_clear :clear
- def clear
- tlb_game_show_clear
- @choice_timer = nil
- end
- def start_choice_timer(frames)
- @choice_timer = frames
- end
- def update
- if @choice_timer
- @choice_timer -= 1
- end
- end
- def choice_time
- (@choice_timer || 0 / Graphics.frame_rate).to_f
- end
- def choice_timer_working?
- @choice_timer && @choice_timer > 0
- end
- end
- class Sprite_ChoiceTimer < Sprite_Timer
- def update_bitmap
- if $game_message.choice_time != @total_sec
- @total_sec = $game_message.choice_time
- redraw
- end
- end
- def timer_text
- sprintf("%3.2f", @total_sec / 60)
- end
- def update_position
- self.x = Graphics.width / 2 - self.bitmap.width / 2
- self.y = 0
- self.z = 200
- end
- def update_visibility
- self.visible = $game_message.choice_timer_working?
- end
- end
- class Spriteset_Map
- alias :tlb_game_show_create_timer :create_timer
- def create_timer
- tlb_game_show_create_timer
- @choice_timer_sprite = Sprite_ChoiceTimer.new(@viewport2)
- end
- alias :tlb_game_show_dispose_timer :dispose_timer
- def dispose_timer
- tlb_game_show_dispose_timer
- @choice_timer_sprite.dispose
- end
- alias :tlb_game_show_update_timer :update_timer
- def update_timer
- tlb_game_show_update_timer
- @choice_timer_sprite.update
- end
- end
- class Window_ChoiceList < Window_Command
- def update
- super
- if $game_message.choice_timer && $game_message.choice_timer == 0
- process_cancel
- end
- end
- end
- class Scene_Map < Scene_Base
- def update
- super
- $game_map.update(true)
- $game_player.update
- $game_timer.update
- $game_message.update
- @spriteset.update
- update_scene if scene_change_ok?
- end
- end
Add Comment
Please, Sign In to add comment