Submit Your Article


 
RPG Maker

Welcome Guest ( Log In | Register )


  Games Resources RPG Maker VX RPG Maker XP Scripts Tutorials Downloads

 
Reply to this topicStart new topic
> Timed Choices v1.4, When choices require a little excitment...
XIV
post Aug 22 2010, 11:44 AM
Post #1


Level 2
Group Icon

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!

Screenshot
Screenshot


Demo
Timed Choices v1.4 Demo

Script
Script

CODE
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# ======================== XIV's Timed Choices v1.4 ============================
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------

# Author: XIV
# Version: 1.4
# Date: 19.12.2010.

# 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
Go to the top of the page
 
+Quote Post
   
Paper PokéMaste...
post Aug 22 2010, 03:17 PM
Post #2


Gotta catch 'em all!
Group Icon

Group: Revolutionary
Posts: 633
Type: Event Designer
RM Skill: Skilled




Hmm. Interesting. I can see many uses for this. biggrin.gif


__________________________
CONGRATULATIONS!
You have been selected out of OVER 9000 for a -FREE- spamwich!!
Just click this link to claim your prize!
Go to the top of the page
 
+Quote Post
   
Zero2007
post Aug 27 2010, 03:13 PM
Post #3


Level 6
Group Icon

Group: Member
Posts: 79
Type: Event Designer
RM Skill: Skilled




Yes indeed...
Go to the top of the page
 
+Quote Post
   
Dan Blazing
post Aug 28 2010, 10:31 AM
Post #4


Level 7
Group Icon

Group: Revolutionary
Posts: 102
Type: Developer
RM Skill: Beginner




Quiz minigame for my game biggrin.gif

Thank you very much this will be awesome, testing it right now.


__________________________
*insert badass signature here*
Go to the top of the page
 
+Quote Post
   
Philip
post Aug 31 2010, 09:07 AM
Post #5


Nura (The Jade Ring)
Group Icon

Group: Revolutionary
Posts: 325
Type: Developer
RM Skill: Masterful




Interesting script! I've never seen one like it. Like as was posted before cool script for quiz minigames and stuff! I may actually use this in VERGO.


__________________________
"If your mind goes blank don't forget to turn off the sound." Unknown Author

Phil


Go to the top of the page
 
+Quote Post
   
XIV
post Jan 6 2011, 03:29 PM
Post #6


Level 2
Group Icon

Group: Member
Posts: 20
Type: Developer
RM Skill: Skilled




A quick update! Added an option to show a small timer window just above the choice for ease of viewing. Check the OP to see how it looks exactly.
Go to the top of the page
 
+Quote Post
   
teknoarcanist
post Jan 25 2011, 08:26 AM
Post #7



Group Icon

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 smile.gif

This post has been edited by teknoarcanist: Jan 25 2011, 08:33 AM
Go to the top of the page
 
+Quote Post
   
TheSuperSakura
post Mar 23 2011, 04:40 PM
Post #8


Level 1
Group Icon

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?


__________________________
Current projects:
RPG - UtSS
RPG -MSC
Go to the top of the page
 
+Quote Post
   

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Lo-Fi Version Time is now: 21st May 2013 - 05:42 AM
RPG RPG Revolution is an Privacy Policy and Legal
eXTReMe Tracker