Project1

标题: 求装备栏文字颜色变化脚本 [打印本页]

作者: 空の翼    时间: 2011-11-17 00:40
标题: 求装备栏文字颜色变化脚本
本帖最后由 空の翼 于 2011-11-17 00:40 编辑

偶然设想到的情况,比如说装备一套套装时候,如果能有装备名字颜色会变化的效果应该还不错。
所以想请教一下用事件来改变装备栏文字颜色的脚本~!求高手指点~!{:nm_4:} dsu_plus_rewardpost_czw
作者: 咚小黑    时间: 2011-11-17 01:43
00:00
善用搜索:http://rpg.blue/forum.php?mod=viewthread&tid=80167
作者: 空の翼    时间: 2011-11-17 08:18
本帖最后由 空の翼 于 2011-11-17 08:49 编辑
咚小黑 发表于 2011-11-17 01:43
00:00
善用搜索:http://rpg.blue/forum.php?mod=viewthread&tid=80167


这个脚本是修改了之后颜色没办法改回来,在下想要的效果是用事件呼出脚本来替换颜色。
不过也是个不错的脚本呢~虽然会和其他读取备注的脚本冲突是个麻烦的问题......
求高手帮忙改改~!{:nm_4:}
作者: 月夜神音    时间: 2011-11-24 10:07
  1. #==============================================================================
  2. # ** [ERZVX] Enhanced Bitmap#draw_text (by ERZENGEL at 27-April-2008 at 19:53)
  3. #------------------------------------------------------------------------------
  4. #  Bitmap#draw_text is able to convert control characters.
  5. #==============================================================================
  6. =begin
  7. ###############################################################################

  8. Default control characters:

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

  14. Control characters from woratanas NMS (v2.52):

  15. \MAP      Replaced by the current map name.
  16. \NC[n]    Replaced by the class of actor n (n = ID of an actor).
  17. \NP[n]    Replaced by the name of actor n in the party (n = integer between 1 and 4).
  18. \NM[n]    Replaced by the name of enemy n (n = ID of an enemy).
  19. \NT[n]    Replaced by the name of troop n (n = ID of a troop).
  20. \NI[n]    Replaced by the name of item n (n = ID of an item).
  21. \NW[n]    Replaced by the name of weapon n (n = ID of a weapon).
  22. \NA[n]    Replaced by the name of armor n (n = ID of an armor).
  23. \NS[n]    Replaced by the name of skill n (n = ID of a skill).
  24. \PRICE[n] Replaced by the price of the item n (n = ID of an item).
  25. \IC[n]    Replaced by the icon with the index n (n = Index of icon in the Iconset).
  26. \DW[n]    Replaced by the icon and name of weapon n (n = ID of a weapon).
  27. \DI[n]    Replaced by the icon and name of item n (n = ID of an item).
  28. \DA[n]    Replaced by the icon and name of armor n (n = ID of an armor).
  29. \DS[n]    Replaced by the icon and name of skill n (n = ID of a skill).
  30. \FN[str]  Following text is in font str (str = name of a font).
  31. \FS[n]    Following text is in fontsize n (n = integer. Standard is 20).

  32. Other control characters:

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

  37. ###############################################################################
  38. =end
  39. #==============================================================================
  40. # ** Bitmap
  41. #==============================================================================
  42. class Bitmap
  43.   #--------------------------------------------------------------------------
  44.   # * Draw text
  45.   #--------------------------------------------------------------------------
  46.   alias :erzvx_draw_text :draw_text unless $@
  47.   def draw_text(*args)
  48.     # Falls erstes Argument ein Rectobjekt ist
  49.     if args[0].is_a?(Rect)
  50.       if args.size > 3 then raise(ArgumentError) end
  51.       x, y, width, height = args[0].x, args[0].y, args[0].width, args[0].height
  52.       str = args[1]
  53.       align = args[2]
  54.     else
  55.       if args.size > 6 then raise(ArgumentError) end
  56.       x, y, width, height, str, align = args[0..5]
  57.     end
  58.     # Links ausrichten, falls Wert von align nil oder gr��er als 2 ist
  59.     align = 0 if align.nil? || align > 2
  60.     # Standardeigenschaften in Variablen speichern
  61.     name, size,   color  = self.font.name, self.font.size,   self.font.color
  62.     bold, italic, shadow = self.font.bold, self.font.italic, self.font.shadow
  63.     # Tempor�re Variablen erstellen
  64.     tstr = (str.is_a?(String) ? str : str.to_s) + "\n";  tc = '';  tx = 0
  65.     begin
  66.       lasttstr = tstr.clone
  67.       tstr = convert_special_characters(tstr)
  68.     end until tstr == lasttstr
  69.     while (!(c = tstr.slice!(/./m)).nil?)
  70.       case c
  71.       when "\x01"  # \C[n]
  72.         tstr.sub!(/\[([0-9]+)\]/, "")
  73.         tcolor = $1.to_i
  74.         self.font.color = text_color(tcolor) if tcolor >= 0 && tcolor <= 31
  75.       when "\x02"  # \C[n]
  76.         tstr.sub!(/\[([0-2]+)\]/, "")
  77.         align = $1.to_i        
  78.       when "\x83"  # \IC[n]
  79.         tstr.sub!(/\[([0-9]+)\]/, "")
  80.         icon_index = $1.to_i
  81.         draw_icon(icon_index, x, y)
  82.         tx += 24
  83.       when "\x84"  # \FN[*]
  84.         tstr.sub!(/\[(.*?)\]/, "")
  85.         self.font.name = $1.to_s
  86.       when "\x85"  # \FS[n]
  87.         tstr.sub!(/\[([0-9]+)\]/, "")
  88.         self.font.size = $1.to_i
  89.       when "\x88"  # \BO
  90.         self.font.bold = !self.font.bold
  91.       when "\x89"  # \IT
  92.         self.font.italic = !self.font.italic
  93.       when "\x93"  # \SH
  94.         self.font.shadow = !self.font.shadow
  95.       when "\n"    # Neue Zeile
  96.         if align == 1     # Zentriert
  97.           tx = width - tx
  98.           tx = tx / 2
  99.           erzvx_draw_text((x + tx), y, (width - tx), height, tc)
  100.         elsif align == 2  # Rechts
  101.           tx = width - tx
  102.           erzvx_draw_text((x + tx), y, (width - tx), height, tc)
  103.         end
  104.         # Tempor�re Variablen zur�cksetzen
  105.         tc = tstr = '';  tx = 0
  106.       else         # Normal text character
  107.         # Ausrichtungsabfrage (Links)
  108.         if align == 0
  109.           erzvx_draw_text((x + tx), y, width, height, c, align)
  110.           tx += text_size(c).width
  111.         else
  112.           tc += c
  113.           tx += text_size(c).width
  114.         end
  115.       end
  116.     end
  117.     # Standardeigenschaften wiederherstellen
  118.     self.font.name, self.font.size,   self.font.color  = name, size,   color
  119.     self.font.bold, self.font.italic, self.font.shadow = bold, italic, shadow
  120.   end
  121.   #--------------------------------------------------------------------------
  122.   # * Convert Special Characters
  123.   #--------------------------------------------------------------------------
  124.   def convert_special_characters(str)
  125.     # Mit Wert einer Variable ersetzen
  126.     str.gsub!(/\\V\[([0-9]+)\]/i) { $game_variables[$1.to_i] }
  127.     # Mit Namen eines Heldens ersetzen
  128.     str.gsub!(/\\N\[([0-9]+)\]/i) { $game_actors[$1.to_i].name }
  129.     # Nachfolgenden Text in anderer Farbe anzeigen
  130.     str.gsub!(/\\C\[([0-9]+)\]/i) { "\x01[#{$1}]" }
  131.     # Mit dem aktuellen Goldbetrag ersetzen
  132.     str.gsub!(/\\G/) { $game_party.gold.to_s }
  133.     # Backslash anzeigen
  134.     str.gsub!(/\\\\/) { "\\" }
  135.     # Ausrichtung �ndern
  136.     str.gsub!(/\\AL\[([0-2]+)\]/i) { "\x02[#{$1}]" }
  137.     # Woratana's :: Map Name
  138.     str.gsub!(/\\MAP/i) { get_map_name }
  139.     # Woratana's :: Actor Class Name
  140.     str.gsub!(/\\NC\[([0-9]+)\]/i) {
  141.       $data_classes[$data_actors[$1.to_i].class_id].name }
  142.     # Woratana's :: Party Actor Name
  143.     str.gsub!(/\\NP\[([0-9]+)\]/i) { $game_party.members[($1.to_i - 1)].name }
  144.     # Woratana's :: Monster Name
  145.     str.gsub!(/\\NM\[([0-9]+)\]/i) { $data_enemies[$1.to_i].name }
  146.     # Woratana's :: Troop Name
  147.     str.gsub!(/\\NT\[([0-9]+)\]/i) { $data_troops[$1.to_i].name }
  148.     # Woratana's :: Item Name
  149.     str.gsub!(/\\NI\[([0-9]+)\]/i) { $data_items[$1.to_i].name }
  150.     # Woratana's :: Weapon Name
  151.     str.gsub!(/\\NW\[([0-9]+)\]/i) { $data_weapons[$1.to_i].name }
  152.     # Woratana's :: Armor Name
  153.     str.gsub!(/\\NA\[([0-9]+)\]/i) { $data_armors[$1.to_i].name }
  154.     # Woratana's :: Skill Name
  155.     str.gsub!(/\\NS\[([0-9]+)\]/i) { $data_skills[$1.to_i].name }
  156.     # Woratana's :: Item Price
  157.     str.gsub!(/\\PRICE\[([0-9]+)\]/i) { $data_items[$1.to_i].price.to_s }
  158.     # Woratana's :: Draw Icon
  159.     str.gsub!(/\\IC\[([0-9]+)\]/i) { "\x83[#{$1}]" }
  160.     # Woratana's :: Draw Weapon Name + Icon
  161.     str.gsub!(/\\DW\[([0-9]+)\]/i) {
  162.       "\x83[#{$data_weapons[$1.to_i].icon_index}]\\NW[#{$1.to_i}]" }
  163.     # Woratana's :: Draw Item Name + Icon
  164.     str.gsub!(/\\DI\[([0-9]+)\]/i) {
  165.       "\x83[#{$data_items[$1.to_i].icon_index}]\\NI[#{$1.to_i}]" }
  166.     # Woratana's :: Draw Armor Name + Icon
  167.     str.gsub!(/\\DA\[([0-9]+)\]/i) {
  168.       "\x83[#{$data_armors[$1.to_i].icon_index}]\\NA[#{$1.to_i}]" }
  169.     # Woratana's :: Draw Skill Name + Icon
  170.     str.gsub!(/\\DS\[([0-9]+)\]/i) {
  171.       "\x83[#{$data_skills[$1.to_i].icon_index}]\\ns[#{$1.to_i}]" }
  172.     # Woratana's :: Font Name Change
  173.     str.gsub!(/\\FN\[(.*?)\]/i) { "\x84[#{$1}]" }
  174.     # Woratana's :: Font Size Change
  175.     str.gsub!(/\\FS\[([0-9]+)\]/i) { "\x85[#{$1}]" }
  176.     # Woratana's :: BOLD Text
  177.     str.gsub!(/\\BO/i) { "\x88" }
  178.     # Woratana's :: ITALIC Text
  179.     str.gsub!(/\\IT/i) { "\x89" }
  180.     # Woratana's :: SHADOW Text
  181.     str.gsub!(/\\SH/i) { "\x93" }
  182.     return str
  183.   end
  184.   #--------------------------------------------------------------------------
  185.   # * Get Text Color
  186.   #--------------------------------------------------------------------------
  187.   def text_color(n)
  188.     x = 64 + (n % 8) * 8
  189.     y = 96 + (n / 8) * 8
  190.     windowskin = Cache.system('Window')
  191.     return windowskin.get_pixel(x, y)
  192.   end
  193.   #--------------------------------------------------------------------------
  194.   # * Get Map Name
  195.   #--------------------------------------------------------------------------
  196.   def get_map_name
  197.     $data_mapinfos = load_data('Data/MapInfos.rvdata') if $data_mapinfos.nil?
  198.     map_id = $game_map.map_id
  199.     return $data_mapinfos[map_id].name
  200.   end
  201.   #--------------------------------------------------------------------------
  202.   # * Draw Icon
  203.   #--------------------------------------------------------------------------
  204.   def draw_icon(icon_index, x, y)
  205.     bitmap = Cache.system('Iconset')
  206.     rect = Rect.new(icon_index % 16 * 24, icon_index / 16 * 24, 24, 24)
  207.     self.blt(x, y, bitmap, rect)
  208.   end
  209. end
复制代码
这脚本如何?像显示文章那样的功能,在武器道具名字前面加入\c[1]就会显示蓝色之类的~

可以在事件中调用脚本如:
  1. $data_weapons[1].name = "\c[1]" + $data_weapons[1].name
复制代码
之类的来修改数据库资料~
作者: 空の翼    时间: 2011-11-24 12:38
本帖最后由 空の翼 于 2011-11-24 12:42 编辑
月夜神音 发表于 2011-11-24 10:07
这脚本如何?像显示文章那样的功能,在武器道具名字前面加入\c[1]就会显示蓝色之类的~

可以在事件中调用脚 ...




在事件里这写不行呢,装备字还是原来的颜色,我一开始认为是某些字体不识别某些符号的原因,结果换了字体还是一样。
应该是这个脚本先读取了颜色标记所以后面的名字还是原来的颜色。
作者: 月夜神音    时间: 2011-11-24 13:11
那就这样吧~游戏开始时事件脚本调用
  1. $orginal_wname = []
  2. for i in 0..$data_weapons.size
  3. $orginal_wname[i] = $data_weapons[i].name
  4. end
复制代码
然后更换武器颜色时
  1. $data_weapons[1].name = "\c[1]#{orginal_wname[1]}"
复制代码
试试看?话说你不点评我我是不会知道你的回复啊=-=
作者: 空の翼    时间: 2011-11-24 13:28
月夜神音 发表于 2011-11-24 13:11
那就这样吧~游戏开始时事件脚本调用然后更换武器颜色时试试看?话说你不点评我我是不会知道你的回复啊=-= ...


脚本执行错误了,不如大大你弄个范例工程吧。这样也好修改。
作者: 月夜神音    时间: 2011-11-24 13:49
附件在此: Project1.rar (240.44 KB, 下载次数: 559)
刚才弄错了些东西,已修复~




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1