XP Stop showing text event when player moves away from event

Hi,
I'm new to RPG Maker XP and I couldn't find how to make event "show text" stop showing text when player moves away from event (without the need to press the action button first), similar to sign posts in later generation Pokemon games.
You'd need to add a check that terminates the message window. IIRC, there is a way to do it via event commands, but I don't remember anything specific right now. :S

If using a custom script, you might need a Window_Message mod.
WARNING: It might clash with other custom scripts.
DISCLAIMER: I won't be held responsible for ANY disaster that might take place while implementing this scriptlet.

Ruby:
# * Hide Message XP - Move the Booty Version
#   2025-06-08

class Window_Message
  def update
    super
    # If fade in
    if @fade_in
      self.contents_opacity += 24
      if @input_number_window != nil
        @input_number_window.contents_opacity += 24
      end
      if self.contents_opacity == 255
        @fade_in = false
      end
      return
    end
    # If inputting number
    if @input_number_window != nil
      @input_number_window.update
      # Confirm
      if Input.trigger?(Input::C)
        $game_system.se_play($data_system.decision_se)
        $game_variables[$game_temp.num_input_variable_id] =
          @input_number_window.number
        $game_map.need_refresh = true
        # Dispose of number input window
        @input_number_window.dispose
        @input_number_window = nil
        terminate_message
      end
      return
    end
    # If message is being displayed
    if @contents_showing
      # If choice isn't being displayed, show pause sign
      if $game_temp.choice_max == 0
        self.pause = true
      end
      # Cancel
      if Input.trigger?(Input::B)
        if $game_temp.choice_max > 0 and $game_temp.choice_cancel_type > 0
          $game_system.se_play($data_system.cancel_se)
          $game_temp.choice_proc.call($game_temp.choice_cancel_type - 1)
          terminate_message
        end
      end
      # Confirm ## Or Just Move Away from NPC
      if Input.trigger?(Input::C) or Input.dir4 > 0
        if $game_temp.choice_max > 0
          $game_system.se_play($data_system.decision_se)
          $game_temp.choice_proc.call(self.index)
        end
        terminate_message
      end
      return
    end
    # If display wait message or choice exists when not fading out
    if @fade_out == false and $game_temp.message_text != nil
      @contents_showing = true
      $game_temp.message_window_showing = true
      reset_window
      refresh
      Graphics.frame_reset
      self.visible = true
      self.contents_opacity = 0
      if @input_number_window != nil
        @input_number_window.contents_opacity = 0
      end
      @fade_in = true
      return
    end
    # If message which should be displayed is not shown, but window is visible
    if self.visible
      @fade_out = true
      self.opacity -= 48
      if self.opacity == 0
        self.visible = false
        @fade_out = false
        $game_temp.message_window_showing = false
      end
      return
    end
  end
end
Thank you for replying!

That's quite a bit above my skill level but it's good to know there might be a way to do it via an event command. I just wonder what it is.

The only scripts I have are from the default Pokemon Essentials v21 files, if that matters.

Original thread: https://forums.rpgmakerweb.com/threads/stop-showing-text-event-when-player-moves-away-from-event.178207/