질문과 답변

Extra Form
#==============================================================================
# ** [ERZVX] Enhanced Bitmap#draw_text (by ERZENGEL at 27-April-2008 at 19:53)
#------------------------------------------------------------------------------
#  Bitmap#draw_text is able to convert control characters.
#==============================================================================
=begin
###############################################################################

Default control characters:

V[n]    Replaced by the value of variable n (n = ID of a variable).
N[n]    Replaced by the name of actor n (n = ID of an actor).
C[n]    Change the color of the following text(n = 0 til 31).
G       Replaced by the current gold amount.
      Replaced by the '' character.

Control characters from woratanas NMS (v2.52):

MAP      Replaced by the current map name.
NC[n]    Replaced by the class of actor n (n = ID of an actor).
NP[n]    Replaced by the name of actor n in the party (n = integer between 1 and 4).
NM[n]    Replaced by the name of enemy n (n = ID of an enemy).
NT[n]    Replaced by the name of troop n (n = ID of a troop).
NI[n]    Replaced by the name of item n (n = ID of an item).
NW[n]    Replaced by the name of weapon n (n = ID of a weapon).
NA[n]    Replaced by the name of armor n (n = ID of an armor).
NS[n]    Replaced by the name of skill n (n = ID of a skill).
PRICE[n] Replaced by the price of the item n (n = ID of an item).
IC[n]    Replaced by the icon with the index n (n = Index of icon in the Iconset).
DW[n]    Replaced by the icon and name of weapon n (n = ID of a weapon).
DI[n]    Replaced by the icon and name of item n (n = ID of an item).
DA[n]    Replaced by the icon and name of armor n (n = ID of an armor).
DS[n]    Replaced by the icon and name of skill n (n = ID of a skill).
FN[str]  Following text is in font str (str = name of a font).
FS[n]    Following text is in fontsize n (n = integer. Standard is 20).

Other control characters:

BO       Following text is or isn't bold.
IT       Following text is or isn't italic.
SH       Folling text is or isn't shadowed.
AL[n]    Align text (n = integer between 0 and 2 (0 = left, 1 = center, 2 = right)).

###############################################################################
=end
#==============================================================================
# ** Bitmap
#==============================================================================
class Bitmap
  #--------------------------------------------------------------------------
  # * Draw text
  #--------------------------------------------------------------------------
  alias :erzvx_draw_text :draw_text unless $@
  def draw_text(*args)
    # Falls erstes Argument ein Rectobjekt ist
    if args[0].is_a?(Rect)
      if args.size > 3 then raise(ArgumentError) end
      x, y, width, height = args[0].x, args[0].y, args[0].width, args[0].height
      str = args[1]
      align = args[2]
    else
      if args.size > 6 then raise(ArgumentError) end
      x, y, width, height, str, align = args[0..5]
    end
    # Links ausrichten, falls Wert von align nil oder größer als 2 ist
    align = 0 if align.nil? || align > 2
    # Standardeigenschaften in Variablen speichern
    name, size,   color  = self.font.name, self.font.size,   self.font.color
    bold, italic, shadow = self.font.bold, self.font.italic, self.font.shadow
    # Temporäre Variablen erstellen
    tstr = (str.is_a?(String) ? str : str.to_s) + "n";  tc = '';  tx = 0
    begin
      lasttstr = tstr.clone
      tstr = convert_special_characters(tstr)
    end until tstr == lasttstr
    while (!(c = tstr.slice!(/./m)).nil?)
      case c
      when "x01"  # C[n]
        tstr.sub!(/[([0-9]+)]/, "")
        tcolor = $1.to_i
        self.font.color = text_color(tcolor) if tcolor >= 0 && tcolor <= 31
      when "x02"  # C[n]
        tstr.sub!(/[([0-2]+)]/, "")
        align = $1.to_i       
      when "x83"  # IC[n]
        tstr.sub!(/[([0-9]+)]/, "")
        icon_index = $1.to_i
        draw_icon(icon_index, x, y)
        tx += 24
      when "x84"  # FN[*]
        tstr.sub!(/[(.*?)]/, "")
        self.font.name = $1.to_s
      when "x85"  # FS[n]
        tstr.sub!(/[([0-9]+)]/, "")
        self.font.size = $1.to_i
      when "x88"  # BO
        self.font.bold = !self.font.bold
      when "x89"  # IT
        self.font.italic = !self.font.italic
      when "x93"  # SH
        self.font.shadow = !self.font.shadow
      when "n"    # Neue Zeile
        if align == 1     # Zentriert
          tx = width - tx
          tx = tx / 2
          erzvx_draw_text((x + tx), y, (width - tx), height, tc)
        elsif align == 2  # Rechts
          tx = width - tx
          erzvx_draw_text((x + tx), y, (width - tx), height, tc)
        end
        # Temporäre Variablen zurücksetzen
        tc = tstr = '';  tx = 0
      else         # Normal text character
        # Ausrichtungsabfrage (Links)
        if align == 0
          erzvx_draw_text((x + tx), y, width, height, c, align)
          tx += text_size(c).width
        else
          tc += c
          tx += text_size(c).width
        end
      end
    end
    # Standardeigenschaften wiederherstellen
    self.font.name, self.font.size,   self.font.color  = name, size,   color
    self.font.bold, self.font.italic, self.font.shadow = bold, italic, shadow
  end
  #--------------------------------------------------------------------------
  # * Convert Special Characters
  #--------------------------------------------------------------------------
  def convert_special_characters(str)
    # Mit Wert einer Variable ersetzen
    str.gsub!(/V[([0-9]+)]/i) { $game_variables[$1.to_i] }
    # Mit Namen eines Heldens ersetzen
    str.gsub!(/N[([0-9]+)]/i) { $game_actors[$1.to_i].name }
    # Nachfolgenden Text in anderer Farbe anzeigen
    str.gsub!(/C[([0-9]+)]/i) { "x01[#{$1}]" }
    # Mit dem aktuellen Goldbetrag ersetzen
    str.gsub!(/G/) { $game_party.gold.to_s }
    # Backslash anzeigen
    str.gsub!(/\/) { "" }
    # Ausrichtung ändern
    str.gsub!(/AL[([0-2]+)]/i) { "x02[#{$1}]" }
    # Woratana's :: Map Name
    str.gsub!(/MAP/i) { get_map_name }
    # Woratana's :: Actor Class Name
    str.gsub!(/NC[([0-9]+)]/i) {
      $data_classes[$data_actors[$1.to_i].class_id].name }
    # Woratana's :: Party Actor Name
    str.gsub!(/NP[([0-9]+)]/i) { $game_party.members[($1.to_i - 1)].name }
    # Woratana's :: Monster Name
    str.gsub!(/NM[([0-9]+)]/i) { $data_enemies[$1.to_i].name }
    # Woratana's :: Troop Name
    str.gsub!(/NT[([0-9]+)]/i) { $data_troops[$1.to_i].name }
    # Woratana's :: Item Name
    str.gsub!(/NI[([0-9]+)]/i) { $data_items[$1.to_i].name }
    # Woratana's :: Weapon Name
    str.gsub!(/NW[([0-9]+)]/i) { $data_weapons[$1.to_i].name }
    # Woratana's :: Armor Name
    str.gsub!(/NA[([0-9]+)]/i) { $data_armors[$1.to_i].name }
    # Woratana's :: Skill Name
    str.gsub!(/NS[([0-9]+)]/i) { $data_skills[$1.to_i].name }
    # Woratana's :: Item Price
    str.gsub!(/PRICE[([0-9]+)]/i) { $data_items[$1.to_i].price.to_s }
    # Woratana's :: Draw Icon
    str.gsub!(/IC[([0-9]+)]/i) { "x83[#{$1}]" }
    # Woratana's :: Draw Weapon Name + Icon
    str.gsub!(/DW[([0-9]+)]/i) {
      "x83[#{$data_weapons[$1.to_i].icon_index}]NW[#{$1.to_i}]" }
    # Woratana's :: Draw Item Name + Icon
    str.gsub!(/DI[([0-9]+)]/i) {
      "x83[#{$data_items[$1.to_i].icon_index}]NI[#{$1.to_i}]" }
    # Woratana's :: Draw Armor Name + Icon
    str.gsub!(/DA[([0-9]+)]/i) {
      "x83[#{$data_armors[$1.to_i].icon_index}]NA[#{$1.to_i}]" }
    # Woratana's :: Draw Skill Name + Icon
    str.gsub!(/DS[([0-9]+)]/i) {
      "x83[#{$data_skills[$1.to_i].icon_index}]ns[#{$1.to_i}]" }
    # Woratana's :: Font Name Change
    str.gsub!(/FN[(.*?)]/i) { "x84[#{$1}]" }
    # Woratana's :: Font Size Change
    str.gsub!(/FS[([0-9]+)]/i) { "x85[#{$1}]" }
    # Woratana's :: BOLD Text
    str.gsub!(/BO/i) { "x88" }
    # Woratana's :: ITALIC Text
    str.gsub!(/IT/i) { "x89" }
    # Woratana's :: SHADOW Text
    str.gsub!(/SH/i) { "x93" }
    return str
  end
  #--------------------------------------------------------------------------
  # * Get Text Color
  #--------------------------------------------------------------------------
  def text_color(n)
    x = 64 + (n % 8) * 8
    y = 96 + (n / 8) * 8
    windowskin = Cache.system('Window')
    return windowskin.get_pixel(x, y)
  end
  #--------------------------------------------------------------------------
  # * Get Map Name
  #--------------------------------------------------------------------------
  def get_map_name
    $data_mapinfos = load_data('Data/MapInfos.rvdata') if $data_mapinfos.nil?
    map_id = $game_map.map_id
    return $data_mapinfos[map_id].name
  end
  #--------------------------------------------------------------------------
  # * Draw Icon
  #--------------------------------------------------------------------------
  def draw_icon(icon_index, x, y)
    bitmap = Cache.system('Iconset')
    rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
    self.blt(x, y, bitmap, rect)
  end
end

게임상 텍스트에 효과를 주는 스크립트인데(색등등..)
이스크립트를 사용하려고하는데 적용시키고 테스트 플레이 실행하면

137번쨰줄에서 오류가 나네요

오류 해결해주실수 있는분이나 다른 텍스트에 효과주는 스크립트 아시는분 답변해주세요!

 

Comment '1'
  • profile
    에돌이 2011.07.12 14:33

    구글링을 통해 찾은 스크립트 원본입니다.

    스크립트를 복사하는 과정에서 손실이 있었던 것 같네요.

    해보니 제대로 됩니다.


    #==============================================================================

    # ** [ERZVX] Enhanced Bitmap#draw_text (by ERZENGEL at 27-April-2008 at 19:53)

    #------------------------------------------------------------------------------

    #  Bitmap#draw_text is able to convert control characters.

    #==============================================================================

    =begin

    ###############################################################################


    Default control characters:


    V[n]    Replaced by the value of variable n (n = ID of a variable).

    N[n]    Replaced by the name of actor n (n = ID of an actor).

    C[n]    Change the color of the following text(n = 0 til 31).

    G       Replaced by the current gold amount.

    \       Replaced by the '' character.


    Control characters from woratanas NMS (v2.52):


    MAP      Replaced by the current map name.

    NC[n]    Replaced by the class of actor n (n = ID of an actor).

    NP[n]    Replaced by the name of actor n in the party (n = integer between 1 and 4).

    NM[n]    Replaced by the name of enemy n (n = ID of an enemy).

    NT[n]    Replaced by the name of troop n (n = ID of a troop).

    NI[n]    Replaced by the name of item n (n = ID of an item).

    NW[n]    Replaced by the name of weapon n (n = ID of a weapon).

    NA[n]    Replaced by the name of armor n (n = ID of an armor).

    NS[n]    Replaced by the name of skill n (n = ID of a skill).

    PRICE[n] Replaced by the price of the item n (n = ID of an item).

    IC[n]    Replaced by the icon with the index n (n = Index of icon in the Iconset).

    DW[n]    Replaced by the icon and name of weapon n (n = ID of a weapon).

    DI[n]    Replaced by the icon and name of item n (n = ID of an item).

    DA[n]    Replaced by the icon and name of armor n (n = ID of an armor).

    DS[n]    Replaced by the icon and name of skill n (n = ID of a skill).

    FN[str]  Following text is in font str (str = name of a font).

    FS[n]    Following text is in fontsize n (n = integer. Standard is 20).


    Other control characters:


    BO       Following text is or isn't bold.

    IT       Following text is or isn't italic.

    SH       Folling text is or isn't shadowed.

    AL[n]    Align text (n = integer between 0 and 2 (0 = left, 1 = center, 2 = right)).


    ############################################################################### 

    =end

    #==============================================================================

    # ** Bitmap

    #==============================================================================

    class Bitmap

      #--------------------------------------------------------------------------

      # * Draw text

      #--------------------------------------------------------------------------

      alias :erzvx_draw_text :draw_text unless $@

      def draw_text(*args)

        # Falls erstes Argument ein Rectobjekt ist

        if args[0].is_a?(Rect)

          if args.size > 3 then raise(ArgumentError) end

          x, y, width, height = args[0].x, args[0].y, args[0].width, args[0].height

          str = args[1]

          align = args[2]

        else

          if args.size > 6 then raise(ArgumentError) end

          x, y, width, height, str, align = args[0..5]

        end

        # Links ausrichten, falls Wert von align nil oder gr��er als 2 ist

        align = 0 if align.nil? || align > 2

        # Standardeigenschaften in Variablen speichern

        name, size,   color  = self.font.name, self.font.size,   self.font.color

        bold, italic, shadow = self.font.bold, self.font.italic, self.font.shadow

        # Tempor�re Variablen erstellen

        tstr = (str.is_a?(String) ? str : str.to_s) + "n";  tc = '';  tx = 0

        begin

          lasttstr = tstr.clone

          tstr = convert_special_characters(tstr)

        end until tstr == lasttstr

        while (!(c = tstr.slice!(/./m)).nil?)

          case c

          when "x01"  # C[n]

            tstr.sub!(/[([0-9]+)]/, "")

            tcolor = $1.to_i

            self.font.color = text_color(tcolor) if tcolor >= 0 && tcolor <= 31

          when "x02"  # C[n]

            tstr.sub!(/[([0-2]+)]/, "")

            align = $1.to_i        

          when "x83"  # IC[n]

            tstr.sub!(/[([0-9]+)]/, "")

            icon_index = $1.to_i

            draw_icon(icon_index, x, y)

            tx += 24

          when "x84"  # FN[*]

            tstr.sub!(/[(.*?)]/, "")

            self.font.name = $1.to_s

          when "x85"  # FS[n]

            tstr.sub!(/[([0-9]+)]/, "")

            self.font.size = $1.to_i

          when "x88"  # BO

            self.font.bold = !self.font.bold

          when "x89"  # IT

            self.font.italic = !self.font.italic

          when "x93"  # SH

            self.font.shadow = !self.font.shadow

          when "n"    # Neue Zeile

            if align == 1     # Zentriert

              tx = width - tx

              tx = tx / 2

              erzvx_draw_text((x + tx), y, (width - tx), height, tc)

            elsif align == 2  # Rechts

              tx = width - tx

              erzvx_draw_text((x + tx), y, (width - tx), height, tc)

            end

            # Tempor�re Variablen zur�cksetzen

            tc = tstr = '';  tx = 0

          else         # Normal text character

            # Ausrichtungsabfrage (Links)

            if align == 0

              erzvx_draw_text((x + tx), y, width, height, c, align)

              tx += text_size(c).width

            else

              tc += c

              tx += text_size(c).width

            end

          end

        end

        # Standardeigenschaften wiederherstellen

        self.font.name, self.font.size,   self.font.color  = name, size,   color

        self.font.bold, self.font.italic, self.font.shadow = bold, italic, shadow

      end

      #--------------------------------------------------------------------------

      # * Convert Special Characters

      #--------------------------------------------------------------------------

      def convert_special_characters(str)

        # Mit Wert einer Variable ersetzen

        str.gsub!(/\V[([0-9]+)]/i) { $game_variables[$1.to_i] }

        # Mit Namen eines Heldens ersetzen

        str.gsub!(/\N[([0-9]+)]/i) { $game_actors[$1.to_i].name }

        # Nachfolgenden Text in anderer Farbe anzeigen

        str.gsub!(/\C[([0-9]+)]/i) { "x01[#{$1}]" }

        # Mit dem aktuellen Goldbetrag ersetzen

        str.gsub!(/\G/) { $game_party.gold.to_s }

        # Backslash anzeigen

        str.gsub!(/\\/) { "\" }

        # Ausrichtung �ndern

        str.gsub!(/\AL[([0-2]+)]/i) { "x02[#{$1}]" }

        # Woratana's :: Map Name

        str.gsub!(/\MAP/i) { get_map_name }

        # Woratana's :: Actor Class Name

        str.gsub!(/\NC[([0-9]+)]/i) { 

          $data_classes[$data_actors[$1.to_i].class_id].name }

        # Woratana's :: Party Actor Name

        str.gsub!(/\NP[([0-9]+)]/i) { $game_party.members[($1.to_i - 1)].name }

        # Woratana's :: Monster Name

        str.gsub!(/\NM[([0-9]+)]/i) { $data_enemies[$1.to_i].name }

        # Woratana's :: Troop Name

        str.gsub!(/\NT[([0-9]+)]/i) { $data_troops[$1.to_i].name }

        # Woratana's :: Item Name

        str.gsub!(/\NI[([0-9]+)]/i) { $data_items[$1.to_i].name }

        # Woratana's :: Weapon Name

        str.gsub!(/\NW[([0-9]+)]/i) { $data_weapons[$1.to_i].name }

        # Woratana's :: Armor Name

        str.gsub!(/\NA[([0-9]+)]/i) { $data_armors[$1.to_i].name }

        # Woratana's :: Skill Name

        str.gsub!(/\NS[([0-9]+)]/i) { $data_skills[$1.to_i].name }

        # Woratana's :: Item Price

        str.gsub!(/\PRICE[([0-9]+)]/i) { $data_items[$1.to_i].price.to_s }

        # Woratana's :: Draw Icon

        str.gsub!(/\IC[([0-9]+)]/i) { "x83[#{$1}]" }

        # Woratana's :: Draw Weapon Name + Icon

        str.gsub!(/\DW[([0-9]+)]/i) { 

          "x83[#{$data_weapons[$1.to_i].icon_index}]\NW[#{$1.to_i}]" }

        # Woratana's :: Draw Item Name + Icon

        str.gsub!(/\DI[([0-9]+)]/i) { 

          "x83[#{$data_items[$1.to_i].icon_index}]\NI[#{$1.to_i}]" }

        # Woratana's :: Draw Armor Name + Icon

        str.gsub!(/\DA[([0-9]+)]/i) { 

          "x83[#{$data_armors[$1.to_i].icon_index}]\NA[#{$1.to_i}]" }

        # Woratana's :: Draw Skill Name + Icon

        str.gsub!(/\DS[([0-9]+)]/i) { 

          "x83[#{$data_skills[$1.to_i].icon_index}]\ns[#{$1.to_i}]" }

        # Woratana's :: Font Name Change

        str.gsub!(/\FN[(.*?)]/i) { "x84[#{$1}]" }

        # Woratana's :: Font Size Change

        str.gsub!(/\FS[([0-9]+)]/i) { "x85[#{$1}]" }

        # Woratana's :: BOLD Text

        str.gsub!(/\BO/i) { "x88" }

        # Woratana's :: ITALIC Text

        str.gsub!(/\IT/i) { "x89" }

        # Woratana's :: SHADOW Text

        str.gsub!(/\SH/i) { "x93" }

        return str

      end

      #--------------------------------------------------------------------------

      # * Get Text Color

      #--------------------------------------------------------------------------

      def text_color(n)

        x = 64 + (n % 8) * 8

        y = 96 + (n / 8) * 8

        windowskin = Cache.system('Window')

        return windowskin.get_pixel(x, y)

      end

      #--------------------------------------------------------------------------

      # * Get Map Name

      #--------------------------------------------------------------------------

      def get_map_name

        $data_mapinfos = load_data('Data/MapInfos.rvdata') if $data_mapinfos.nil?

        map_id = $game_map.map_id

        return $data_mapinfos[map_id].name

      end

      #--------------------------------------------------------------------------

      # * Draw Icon

      #--------------------------------------------------------------------------

      def draw_icon(icon_index, x, y)

        bitmap = Cache.system('Iconset')

        rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)

        self.blt(x, y, bitmap, rect)

      end

    end


List of Articles
종류 분류 제목 글쓴이 날짜 조회 수
공지 묻고 답하기 가이드 습작 2014.06.14 12391
RMVXA 캐릭터 설명 길이를 늘리고 싶습니다. 2 크레페 2013.07.22 669
기본툴 사용법 RMMV 캐릭터 설정을 하고 싶은데 어떻게 해야하는지 몰라서 질문 드립니다. 3 file YOGU 2019.03.22 197
RMXP 캐릭터 소재 적용방법 1 uns33567194 2014.05.31 613
턴제 전투 RMMV 캐릭터 스킬 하나로 적한테 데미지 주고 자기한테 버프 걸게 할수있을까요? 4 Kokodd 2021.04.06 95
RMVXA 캐릭터 스타팅 포인트 설정 이벤트 안됩니다. 2 file 비백 2015.06.13 235
기본툴 사용법 RMVXA 캐릭터 스탠딩(BIG페이스칩)을 넣고 싶어요! 3 빨간토끼 2021.01.13 576
기본툴 사용법 RMMV 캐릭터 스테이터스 2 쌩촙제작자 2023.01.31 65
에러 해결 RMVXA 캐릭터 시야에 벗어나면 이벤트가 쫒아오질 않아요 2 Wolfclaw 2020.03.07 95
RMVX 캐릭터 시작장소 지정 방법이 뭔가요?? 3 겜초 2011.07.05 1077
이벤트 작성 RMMV 캐릭터 시체 투명해집니다. 3 file Hyeonwoo 2024.04.06 90
RMMV 캐릭터 아이템 설정 법 질문 2 JoonFX 2018.02.04 263
RMVXA 캐릭터 안움직이는것 2 은듕 2017.01.21 200
RMVX 캐릭터 애니메이션 효과 2 행복해 2013.09.13 1006
RMVX 캐릭터 애니메이션.. 2 file 하네 2013.10.10 1061
RMMV 캐릭터 액터 3-1, 3-2, 3-3, 3-4의 사이드뷰 배틀러가 없습니다. 저만 그런가요..? 5 file 하응가 2016.02.09 335
RMVX 캐릭터 얼굴 그래픽을 설정하는데 3 악익이 2014.01.23 633
기본툴 사용법 RMMV 캐릭터 얼굴 이미지 적용법 4 지원_ 2020.10.04 570
RMVX 캐릭터 여러명 같이 다니는거 어떻게 하나요 3 file helena 2015.08.14 195
RMVX 캐릭터 오류 2 file 비둘디 2013.05.04 745
맵배치 RMMV 캐릭터 오브젝트 아래로 보이게하기 1 file 소용돌이은하에서사는자 2020.08.20 157
Board Pagination Prev 1 ... 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 ... 516 Next
/ 516