Switch Tags VX

Switch Tags VX

by Kyonides
​

Introduction

With this scriptlet you will be able to turn on or off any given switch by leaving 3 different tags in the show text box! 😀
You will see the effects of that action while it is still printing the text on screen! 😮

Ruby:
# * Switch Tags VX * #
#    Scripter : Kyonides Arkanthes
#    2024-01-07

# The script implements the use of 2 game switch tags that look something like
# this: First \s[10] and later \+ or \-

class Window_Message
  alias :kyon_switch_tag_win_mess_conv_sp_char :convert_special_characters
  def convert_special_characters
    @switch_block = Proc.new {}
    @text.gsub!(/\\\+/, "\x18")
    @text.gsub!(/\\\-/, "\x19")
    kyon_switch_tag_win_mess_conv_sp_char
    @text.gsub!(/\\s\[(\d+)\]/i) { @switch_block = switch_proc($1.to_i); "" }
  end

  def switch_proc(switch_id)
    Proc.new do |state|
      $game_switches[switch_id] = state
      $game_map.need_refresh = true
    end
  end

  def process_character(c)
    case c
    when "\x01"
      @text.sub!(/\[([0-9]+)\]/, "")
      contents.font.color = text_color($1.to_i)
    when "\x02"
      @gold_window.refresh
      @gold_window.open
    when "\x03"
      @wait_count = 15
      @break = true
    when "\x04"
      @wait_count = 60
      @break = true
    when "\x05"
      self.pause = true
      @break = true
    when "\x06"
      @line_show_fast = true
    when "\x07"
      @line_show_fast = false
    when "\x08"
      @pause_skip = true
    when "\x18"
      @switch_block.call(true)
    when "\x19"
      @switch_block.call(false)
    else
      contents.draw_text(@contents_x, @contents_y, 40, WLH, c)
      c_width = contents.text_size(c).width
      @contents_x += c_width
    end
  end

  def update_message
    loop do
      c = @text.slice!(/./m)
      case c
      when nil
        finish_message
        break
      when "\x00"
        new_line
        if @line_count >= MAX_LINE
          unless @text.empty?
            self.pause = true
            break
          end
        end
      end
      process_character(c)
      if @break
        @break = nil
        break
      end
      break unless @show_fast or @line_show_fast
    end
  end
end

Terms & Conditions

Free for use in ANY game.
Due credit is optional.
That's it! 😛

Original thread: https://forums.rpgmakerweb.com/threads/switch-tags-vx.164595/