Group: Member
Posts: 20
Type: Developer
RM Skill: Skilled
Timed Choices v1.4
by XIV
Introduction This simple script allows you to put a timer on player's choices, so whenever there is a "Show Choices" event command the player has a limited time to make a choice before you make one for him or the script chooses one randomly. The wait time can be easily set by using a variable.
Version History: v1.4 - added option to show the choice timer directly above the message box v1.3 - bugfix, thanks to //mitchi.exe v1.2 - damn, I just figured out how to really use accessors, small code edit v1.1 - fixed a cancel branching bug
Features - set a timer on player's choices with a variable - running an additional timer in the background is possible - set a random choice when the timer reaches 00:00 or use your own choice from the event command
How to Use Copy the script below. Paste it above Main in your project. Setup variable and switch IDs and read the instructions. Use and enjoy!
# Features: # - set a timer on player's choices with a variable # - running an additional timer in the background is possible # - set a random choice when the timer reaches 00:00 or use your own choice from # the event command
# How to use: # 1. Paste this script above Main in your project. # 2. Setup the switch and variable IDs below. # 3. Use and enjoy!
# NOTE! # If you plan on using this with a custom message system, it WILL work fine as # long as you don't mess with the "choice-box positioning"! # If you want to make this script compatible with any custom message system's # choice-box positioning, contact me either in the thread where you found this or # via PM on rpgmakervx.net.
# For Ultimate Timer users: # This script does NOT function properly with the count-up timer or the # variable timer on, although it works perfectly with other features of the # Ultimate Timer!
module XIV module TimedChoice # This variable determines the wait time before the choices close. CHOICE_TIME = 5
# This switch enables(ON) or disables(OFF) the randomness of the choice when # the choice timer reaches 00:00 RANDOM_CHOICE = 5
# Set this to true if you want the choice timer to be directly above the message # box. ABOVE_MSG = true end end #------------------------------------------------------------------------------- # * END CUSTOMIZATION #------------------------------------------------------------------------------- class Game_System attr_accessor :choice_on attr_accessor :return_pos end # Game_System
class Sprite_Timer < Sprite #-------------------------------------------------------------------------- # * Object Initialization # viewport : viewport #-------------------------------------------------------------------------- alias xiv_timedchoices_init initialize unless $@ def initialize(viewport) xiv_timedchoices_init(viewport) @xy = [self.x,self.y] $game_system.return_pos = true if XIV::TimedChoice::ABOVE_MSG self.x = 120 self.y = 240 $game_system.return_pos = false end end # initialize
alias xiv_timedchoices_up update unless $@ def update xiv_timedchoices_up if $game_system.return_pos self.x = @xy[0] self.y = @xy[1] end end # update end # Sprite_Timer
class Window_Timer < Window_Base def initialize super(120, 240, 88, 50) self.z = 0 end end
class Window_Message < Window_Selectable #----------------------------------------------------------------------------- # * start_choice alias #----------------------------------------------------------------------------- alias new_start_choice_XTC start_choice unless $@ def start_choice new_start_choice_XTC $game_system.choice_on = true @win = Window_Timer.new if XIV::TimedChoice::ABOVE_MSG if $game_system.timer_working @timer_worked = true @old_time = $game_system.timer end $game_system.timer = $game_variables[XIV::TimedChoice::CHOICE_TIME] * Graphics.frame_rate $game_system.timer_working = true end # start_choice
#----------------------------------------------------------------------------- # * input_choice alias #----------------------------------------------------------------------------- alias new_input_choice_XTC input_choice unless $@ def input_choice new_input_choice_XTC if $game_system.timer == 0 rand_choice Sound.play_cancel terminate_message $game_system.choice_on = false if XIV::TimedChoice::ABOVE_MSG @win.dispose $game_system.return_pos = true end return_timer end if Input.trigger?(Input::C) $game_system.timer_working = false $game_system.choice_on = false if XIV::TimedChoice::ABOVE_MSG @win.dispose $game_system.return_pos = true end return_timer end end # input_choice
#----------------------------------------------------------------------------- # * new method determines the random choice #----------------------------------------------------------------------------- def rand_choice if $game_switches[XIV::TimedChoice::RANDOM_CHOICE] random_choice = rand(6) while random_choice == 0 or (random_choice != 5 and random_choice > $game_message.choice_max) or ($game_message.choice_cancel_type < 5 and random_choice == 5) do random_choice = rand(6) end else random_choice = $game_message.choice_cancel_type end $game_message.choice_proc.call(random_choice - 1) end # rand_choice
#----------------------------------------------------------------------------- # * new_method returns the timer if it ran before choice processing #----------------------------------------------------------------------------- def return_timer if @timer_worked @diff = ($game_variables[XIV::TimedChoice::CHOICE_TIME] * Graphics.frame_rate) - $game_system.timer - Graphics.frame_rate timing = @old_time - @diff $game_system.timer = timing if $game_system.timer <= 0 $game_system.timer = 0 end $game_system.timer_working = true end end # return_timer end # Window_Message
Credit Not necessary, but it would be cool.
Author's Notes Any bugs reports and suggestions should be posted in this thread or sent to me via PM.
Compatibilty
This script aliases the following methods: - start_choice of the Window_Message class - input_choice of the Window_Message class - update of the Sprite_Timer class - initialize of the Sprite_Timer class
This post has been edited by XIV: Jan 7 2011, 04:37 AM
Group: Member
Posts: 2
Type: Writer
RM Skill: Advanced
Might have found a problem? After doing one timed choice with the window above the text box, something screws up. If you try to do another timed choice after that, the window is blank, and the timer runs in the upper right-hand corner instead. Also, if you don't pick a choice -- window enabled or not -- the timer in the upper right-hand corner just hangs out while you're walking around. Though you can easily work around this by adding a 'stop timer' command at the end of the event.
Other than that, this is a great script! Thanks for the upload
This post has been edited by teknoarcanist: Jan 25 2011, 08:33 AM
Group: Member
Posts: 7
Type: Writer
RM Skill: Intermediate
Hi there, just a quick question here; How do you make it so the timed choices only apply to certain events? I've got choice options all over in my game so far and once I plugged in the script it automatically made my other choice options to be timed and on top of that I don't even really get a timer it just shows the choices then ends the conversation. Could anyone help me?