Countdown timer that interrupts messages

Quoted from my post in the VXA board:
Is it possible to have a countdown timer that activates a game over even while ex. you are in the middle of talking to someone? I understand how to create the countdown timer and it does work. However if the game is in the middle of displaying text messages when the timer is 0, the game over only occurs after the messages finish. I want it to interrupt the messages instead of waiting until they are over.
I was told this would be best achieved with a script but I'm a noob at scripting.
Just a heads up for the future. If you have a similar situation again where you have started a thread and been told that it needs to be somewhere else, just Report your post and ask for the thread to be moved. That way we don't end up with orphaned and duplicate threads.
Thanks.
I'll answer what you asked in the previous thread as well. With a script call you could do this before calling the Game Over command:
Code:
$game_message.clear
$game_message.visible = false

With a script you can simply add this below Materials
Code:
class Scene_Map < Scene_Base
  alias hrk_scene_change_old scene_change_ok?
  def scene_change_ok?
    $game_switches[pick_a_switch_id] || hrk_scene_change_old
  end
end

Of course, you have to change "pick_a_switch_id" with a real switch ID (it can be any ID). Once you do, you can set that switch to true and the game will allow you to perform a scene change even if the message is visible.
Kes, sorry! I'm new to the forums.

Heirukichi, the script call doesn't seem to work. I tried your script but it's not working for me either, what am I doing wrong?
I used switch 47 for the script. Here's basically what I did

Code:
class Scene_Map < Scene_Base
  alias hrk_scene_change_old scene_change_ok?
  def scene_change_ok?
    $game_switches[47] || hrk_scene_change_old
  end
end

Autorun:
Timer start
Switch 47 on
Self-switch A on

Parallel process with condition self-switch A:
Conditional branch: timer 0
>Game over

It's still only triggering game over after the messages finish.
the script call doesn't seem to work
That's strange, it works perfectly in a blank project. I didn't use the timer, but the Game Over scene was successfully called even with the message there. Here is my event.
index.php

The first line is used to wait 3 seconds, don't mind it.
Huh, so I tried the script call without the timer and it does work. It just doesn't seem to be working with the timer.

Would you mind testing it out with a timer?
You are right, having both the timer sprite and the message window visible prevents the Parallel Process interpreter from running, that is the reason why it does not stop. You can solve it using this
Code:
class Scene_Map < Scene_Base
  alias hrk_update_no_timer_old update
  def update
    hrk_update_no_timer_old
    if ($game_switches[47] && ($game_timer.sec == 0))
      SceneManager.call(Scene_Gameover) 
    end
  end # Update
end # Scene_Map class

It does not check if it is possible to change scene, it automatically switches to the Game Over scene, even if the message is visible. Just be sure not to use your switch/timer combination anywhere else, if the timer reaches 0 and the switch is still ON it will trigger a Game Over, no matter what.
It works! Thank you so much : )
You are right, having both the timer sprite and the message window visible prevents the Parallel Process interpreter from running, that is the reason why it does not stop. You can solve it using this
Code:
class Scene_Map < Scene_Base
  alias hrk_update_no_timer_old update
  def update
    hrk_update_no_timer_old
    if ($game_switches[47] && ($game_timer.sec == 0))
      SceneManager.call(Scene_Gameover)
    end
  end # Update
end # Scene_Map class

It does not check if it is possible to change scene, it automatically switches to the Game Over scene, even if the message is visible. Just be sure not to use your switch/timer combination anywhere else, if the timer reaches 0 and the switch is still ON it will trigger a Game Over, no matter what.
I know this is basically a necro post, but I thought I could share a slight change to the proposed script.
I just had someone that wanted a similar thing and I was stumped to figure out how, but then I found this post and voila. However my search was for a battle scenario. So I just changed the Scene and done. Next was to show a message. In Scene_Battle that was easy the method exists, but for Scene_Map I figured out to just copy over the necessary functions and now I have this.
Show a message when the timer runs out (and switch is on).

*updated to correct for game timer aborting battle when 0
Ruby:
# Credit
# Heirukichi
# Roninator2

module R2_Battle_Timer_End
  Switch = 47
end

class Scene_Map < Scene_Base
  alias hrk_update_no_timer_old update
  def update
    hrk_update_no_timer_old
    if ($game_switches[R2_Battle_Timer_End::Switch] && ($game_timer.sec == 0))
      $game_message.add("Death Comes For You.")
      wait_for_message while $game_message.busy?
      SceneManager.call(Scene_Gameover)
    end
  end
  def wait_for_message
    Graphics.update
    Input.update
    update_all_windows
  end
end

class Scene_Battle < Scene_Base
  alias hrk_update_no_timer_old update
  def update
    hrk_update_no_timer_old
    if ($game_switches[R2_Battle_Timer_End::Switch] && ($game_timer.sec == 0))
      $game_message.add("Death Comes For You.")
      wait_for_message
      SceneManager.call(Scene_Gameover)
    end
  end
end

module BattleManager
  class << self; alias :r2_switch_off_victory  :process_victory; end
  def self.process_victory
    $game_switches[R2_Battle_Timer_End::Switch] = false
    $game_timer.stop if $game_timer.working?
    r2_switch_off_victory
  end
end
class Game_Timer
  def on_expire
  end
end

Original thread: https://forums.rpgmakerweb.com/threads/countdown-timer-that-interrupts-messages.111513/