Save-Point
Switch Tags - Printable Version

+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+--- Thread: Switch Tags (/thread-8887.html)



Switch Tags - kyonides - 01-08-2024

Switch Tags
VX + ACE

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! Grinning
You will see the effects of that action while it is still printing the text on screen! Shocked

VX Script

Code:
# * 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

VX ACE Script

Code:
# * Switch Tags ACE * #
#   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_Base
  alias :kyon_switch_tag_win_bs_conv_esc_char :convert_escape_characters
  def convert_escape_characters(text)
    @switch_block = Proc.new {}
    result = kyon_switch_tag_win_bs_conv_esc_char(text)
    result.gsub!(/\es\[(\d+)\]/i) do
      @switch_id = $1.to_i
      @switch_block = Proc.new {|state| $game_switches[@switch_id] = state }
      ""
    end
    result
  end

  def obtain_escape_code(text)
    text.slice!(/^[\+\-\$\.\|\^!><\{\}\\]|^[A-Z]+/i)
  end
end

class Window_Message
  alias :kyon_switch_tag_win_mess_proc_esc_char :process_escape_character
  def process_escape_character(code, text, pos)
    case code
    when '+'
      @switch_block.call(true)
    when '-'
      @switch_block.call(false)
    end
    kyon_switch_tag_win_mess_proc_esc_char(code, text, pos)
  end
end

Terms & Conditions

Free for use in ANY game. Gamer
Due credit is optional.
That's it! Tongue sticking out


RE: Switch Tags - kyonides - 01-08-2024

Script Backported to VX!

Well, I thought it would be unfair for those few RMVX users not to be able to turn on switches at will like the VX ACE folks could. Thus, I felt inspired enough as to come up with its VX port after a short while working on it. Grinning

Sad Sadly, RMXP won't be getting its own port for the Window_Message class isn't modular enough to let me do so without coming up with a brand new script.