RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
XIV's Timed Choices v1.4

0 Members and 1 Guest are viewing this topic.

pokeball XIVOfflineMale
**
Rep:
Level 72
RMRK Junior
Timed Choices
Version: v1.4
Author: XIV
Date: February 17, 2011

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
  • v1.0 - Original Release

Description


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 using a variable.

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

Screenshots



Instructions

Copy the script below. Paste it above Main in your project. Setup variable IDs, switch IDs and read the instructions. Use and enjoy!

Script


Code: [Select]
# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
# ======================== 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


  • XIV

Thanks

  • //mitchi.exe for a bug report

Support


Any bugs reports and suggestions should be posted in this thread or sent to me via PM.

Known Compatibility Issues

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

There might be issues with other scripts that use these methods.

Demo


Timed Choices v1.4 Demo