Force Show Choice to terminate/dispose

Started by Vortex, May 30, 2013, 06:24:49 pm

Previous topic - Next topic

Vortex

Hello boys and girls  8)

Im trying to terminate/dispose an alredy appeared show choice message with an parallel event.

The clue behind is to get a System for timed (fast) answering.


Method terminate_message / dispose  is defined in Window_Message


Could someone help me out? (Using Hermes btw) 
Im not sure how I get it to work

Greetings

KK20

I could have sworn I have seen a script for this already. I'm gonna Google a bit and see if I can remember.

Oh whatever, I couldn't find it. Guess I'll make one myself.
Spoiler: ShowHide

#=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
# Timed Player Choices                                                Ver 1.0
#   by KK20                                                          [30/05/13]
#=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
# [ Description ]
# RPG Maker is built with a 'Show Choices' command, giving players a list of
# items to choose from. This script will throw in a timer element, limiting
# players with the amount of time they have to make a decision. Should the timer
# hit zero, the last item highlighted will be selected.
#
# [ Instructions ]
# Place below default scripts and any scripts that modify messages.
# There is very little to configure below.
#
# For events, use the script call
#
#    $game_system.choices_timer = frames
#
# replacing frames with an integer value. The timer counts down in frames. If
# your game is running at 40 frames per second, a value of 400 is equivalent to
# 10 seconds.
#
# The timer will carry on over to the next time choices are given. Thus, if you
# always want the player to have a fresh 5 seconds every time he/she is given
# choices, you will need to use the above script call every time before every
# 'Show Choices' command.
#
# If you wish to disable the timer, use the above script call but set it equal
# to -1.
#
# [ Tips ]
# Should you ever want to store the current timer, you can use this script call:
#
#     $game_variables[id] = $game_system.choices_timer
#
# replacing 'id' with the game variable you wish to use. You can then do
#
#     $game_system.choices_timer = $game_variables[id]
#
# to set the timer back.
#
# [ Compatibility ]
# Unknown as of now. Be wary of scripts that modify how messages are displayed.
# Aliases Window_Message class methods to ensure best compatibility.
#
# [ Credits ]
# KK20 - For script
#=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#                       C O N F I G U R A T I O N
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# Determines position of timer window. 0 for left, 1 for center, 2 for right.
POSITION = 0
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#                   E N D   C O N F I G U R A T I O N
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#==============================================================================
# ** Window_Message
#------------------------------------------------------------------------------
#  This message window is used to display text.
#==============================================================================

class Window_Message < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias init_choices_timer_window initialize
  def initialize
    init_choices_timer_window
    @timer_window = Window_ChoicesTimer.new(self.x,self.y,self.width,self.height)
  end
  #--------------------------------------------------------------------------
  # * Dispose
  #--------------------------------------------------------------------------
  alias dispose_timer_window dispose
  def dispose
    dispose_timer_window
    @timer_window.dispose
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  alias update_rest_of_msg_window update
  def update
    @timer_window.update
    # If choices displayed and timer has hit zero
    if $game_temp.choice_max > 0 and @contents_showing and $game_system.choices_timer == 0
      super
      # Revert timer back to -1
      $game_system.choices_timer = -1
      # Force decision based on current item highlighted
      $game_system.se_play($data_system.decision_se)
      $game_temp.choice_proc.call(self.index)
      terminate_message
      return
    end
    # Alias update method
    update_rest_of_msg_window
  end
end

#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#  Adds another variable @choices_timer
#==============================================================================
class Game_System
  attr_accessor :choices_timer
  alias init_choices_timer initialize
  def initialize
    @choices_timer = -1
    init_choices_timer
  end
end

#==============================================================================
# ** Window_ChoicesTimer
#------------------------------------------------------------------------------
#  This window displays the amount of time the player has left to make a choice.
#==============================================================================
class Window_ChoicesTimer < Window_Base
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(x,y,width,height)
    # Adjust position of window if message window is too close to screen borders
    case POSITION
    when 1 then x = x + (width / 2) - 32
    when 2 then x = x + width - 64
    end
    if y <= 48
      y += height
    else
      y -= 48
    end
    # Basic initialization variables
    super(x, y, 64, 48)
    self.contents = Bitmap.new(self.width-32, self.height-32)
    self.visible = false
    self.z = 9998
    @fade_in = false
    @fade_out = false
    self.active = false
  end
  #--------------------------------------------------------------------------
  # * Update
  #--------------------------------------------------------------------------
  def update
    super
    # If window is fading in
    if @fade_in
      self.contents_opacity += 24
      if self.contents_opacity == 255
        @fade_in = false
      end
      return
    end
    # If the timer window needs to be displayed, prepare to display it
    if !self.visible and $game_temp.message_text != nil and
    $game_temp.choice_max > 0 and $game_system.choices_timer > 0
      @fade_in = true
      self.visible = true
      self.contents_opacity = 0
      self.opacity = 255
      self.back_opacity = 160
      # Draw timer
      self.contents.clear
      self.contents.font.size = 16
      sec = $game_system.choices_timer / Graphics.frame_rate
      min = sec / 60
      time = sprintf("%02d:%02d", min, sec)
      self.contents.draw_text(0,-15,self.width,self.height,time)
      return
    end
    # If no longer making choice, fade out window
    if $game_temp.choice_max == 0
      @fade_out = true
      self.opacity -= 48
      self.contents_opacity -= 48
      if self.opacity == 0
        self.visible = false
        @fade_out = false
      end
      return
    end
    # If window is visible, count down timer and draw it to window
    if self.visible
      self.contents.clear
      self.contents.font.size = 16
      sec = $game_system.choices_timer / Graphics.frame_rate
      min = sec / 60
      time = sprintf("%02d:%02d", min, sec)
      self.contents.draw_text(0,-15,self.width,self.height,time)
      $game_system.choices_timer -= 1
    end
  end
end

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Vortex

May 31, 2013, 12:20:53 am #2 Last Edit: May 31, 2013, 12:29:24 am by Vortex
Thanks for the fast answer and your efforts (again) ^.^ we know us from that Bugtracker Topic

But it seems like it is not closing the Choice Window I would like to. just need a Command to close the Show Choice window - and continue with event script.


Anyway I've made an example project for my specific problem

232 Kb

http://ge.tt/3Kqwd6i/v/0?c


Greetings

KK20

May 31, 2013, 12:50:10 am #3 Last Edit: May 31, 2013, 12:55:25 am by KK20
I found that commenting this line out in Hermes Painting
      # Reset choice max (don't need it any more. hopefully)
     $game_temp.choice_max = 0

and by using the modified script of mine:
Spoiler: ShowHide
#=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
# Timed Player Choices                                                Ver 1.0
#   by KK20                                                          [30/05/13]
#=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
# [ Description ]
# RPG Maker is built with a 'Show Choices' command, giving players a list of
# items to choose from. This script will throw in a timer element, limiting
# players with the amount of time they have to make a decision. Should the timer
# hit zero, the last item highlighted will be selected.
#
# [ Instructions ]
# Place below default scripts and any scripts that modify messages.
# There is very little to configure below.
#
# For events, use the script call
#
#    $game_system.choices_timer = frames
#
# replacing frames with an integer value. The timer counts down in frames. If
# your game is running at 40 frames per second, a value of 400 is equivalent to
# 10 seconds.
#
# The timer will carry on over to the next time choices are given. Thus, if you
# always want the player to have a fresh 5 seconds every time he/she is given
# choices, you will need to use the above script call every time before every
# 'Show Choices' command.
#
# If you wish to disable the timer, use the above script call but set it equal
# to -1.
#
# [ Tips ]
# Should you ever want to store the current timer, you can use this script call:
#
#     $game_variables[id] = $game_system.choices_timer
#
# replacing 'id' with the game variable you wish to use. You can then do
#
#     $game_system.choices_timer = $game_variables[id]
#
# to set the timer back.
#
# [ Compatibility ]
# Unknown as of now. Be wary of scripts that modify how messages are displayed.
# Aliases Window_Message class methods to ensure best compatibility.
#
# [ Credits ]
# KK20 - For script
#=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#                       C O N F I G U R A T I O N
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# Determines position of timer window. 0 for left, 1 for center, 2 for right.
POSITION = 0
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#                   E N D   C O N F I G U R A T I O N
#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#==============================================================================
# ** Window_Message
#------------------------------------------------------------------------------
#  This message window is used to display text.
#==============================================================================

class Window_Message < Window_Selectable
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 alias init_choices_timer_window initialize
 def initialize
   init_choices_timer_window
   @timer_window = Window_ChoicesTimer.new(self.x,self.y,self.width,self.height)
 end
 #--------------------------------------------------------------------------
 # * Dispose
 #--------------------------------------------------------------------------
 alias dispose_timer_window dispose
 def dispose
   dispose_timer_window
   @timer_window.dispose
 end
 #--------------------------------------------------------------------------
 # * Frame Update
 #--------------------------------------------------------------------------
 alias update_rest_of_msg_window update
 def update
   @timer_window.update
   # If choices displayed and timer has hit zero
   if $game_temp.choice_max > 0 and $game_system.choices_timer == 0
     super
     # Revert timer back to -1
     $game_system.choices_timer = -1
     # Force decision based on current item highlighted
     $game_system.se_play($data_system.decision_se)
     $game_temp.choice_proc.call(self.index)
     terminate_message
     return
   end
   # Alias update method
   update_rest_of_msg_window
 end
end

#==============================================================================
# ** Game_System
#------------------------------------------------------------------------------
#  Adds another variable @choices_timer
#==============================================================================
class Game_System
 attr_accessor :choices_timer
 alias init_choices_timer initialize
 def initialize
   @choices_timer = -1
   init_choices_timer
 end
end

#==============================================================================
# ** Window_ChoicesTimer
#------------------------------------------------------------------------------
#  This window displays the amount of time the player has left to make a choice.
#==============================================================================
class Window_ChoicesTimer < Window_Base
 #--------------------------------------------------------------------------
 # * Object Initialization
 #--------------------------------------------------------------------------
 def initialize(x,y,width,height)
   # Adjust position of window if message window is too close to screen borders
   case POSITION
   when 1 then x = x + (width / 2) - 32
   when 2 then x = x + width - 64
   end
   if y <= 48
     y += height
   else
     y -= 48
   end
   # Basic initialization variables
   super(x, y, 64, 48)
   self.contents = Bitmap.new(self.width-32, self.height-32)
   self.visible = false
   self.z = 9998
   @fade_in = false
   @fade_out = false
   self.active = false
 end
 #--------------------------------------------------------------------------
 # * Update
 #--------------------------------------------------------------------------
 def update
   super
   # If window is fading in
   if @fade_in
     self.contents_opacity += 24
     if self.contents_opacity == 255
       @fade_in = false
     end
     return
   end
   # If the timer window needs to be displayed, prepare to display it
   if !self.visible and $game_temp.message_text != nil and
   $game_temp.choice_max > 0 and $game_system.choices_timer > 0
     @fade_in = true
     self.visible = true
     self.contents_opacity = 0
     self.opacity = 255
     self.back_opacity = 160
     # Draw timer
     self.contents.clear
     self.contents.font.size = 16
     sec = $game_system.choices_timer / Graphics.frame_rate
     min = sec / 60
     time = sprintf("%02d:%02d", min, sec)
     self.contents.draw_text(0,-15,self.width,self.height,time)
     return
   end
   # If no longer making choice, fade out window
   if $game_temp.choice_max == 0
     @fade_out = true
     self.opacity -= 48
     self.contents_opacity -= 48
     if self.opacity == 0
       self.visible = false
       @fade_out = false
     end
     return
   end
   # If window is visible, count down timer and draw it to window
   if self.visible
     self.contents.clear
     self.contents.font.size = 16
     sec = $game_system.choices_timer / Graphics.frame_rate
     min = sec / 60
     time = sprintf("%02d:%02d", min, sec)
     self.contents.draw_text(0,-15,self.width,self.height,time)
     $game_system.choices_timer -= 1
   end
 end
end
placed below the Hermes scripts does work. Now if you really don't want to use my script and go the other route, I don't know what to do. First off, that's a hell of a mess of eventing you have there just for one little feature. Secondly, I'm not going to dig through all these lines of code that is a complete rewrite to the default classes. If you want, you can keep the evented timer you have and use my script, but make my timer window invisible.

I do plan to put this in the script database.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Vortex

I would prefer your route of corse, but maybe im doing sth wrong with your script.
After I configured the timer frames above the Show choice

http://s14.directupload.net/file/d/3272/9uuv5rtm_jpg.htm
The Show Choice appears, the Timer just 'displays for 1 second' and after 10 seconds the Show Choice window is still opened. Nothing happened

What did I do wrong?

KK20

Did you make the correct edits as I have posted above?

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

Vortex

It works now very well! Like I've wished

Thanks for that great script.  :up: