Project1

标题: VX中NPC头上显示名字 [打印本页]

作者: lqn619    时间: 2008-7-21 17:39
标题: VX中NPC头上显示名字
求VX中NPC头上显示名字的脚本
我有急用
谢谢 [LINE]1,#dddddd[/LINE]版务信息:本贴由楼主自主结贴~
作者: 火鸡三毛老大    时间: 2008-7-21 17:52
  1. class Game_Event < Game_Character
  2. #——————————————————————————————————————
  3. # 用来返回名称
  4. #——————————————————————————————————————
  5. def name
  6.    return @event.name
  7. end  
  8. def name=(newname)
  9.    @event.name = newname
  10. end
  11. end
  12. #==============================================================================
  13. # ■ Sprite_Character
  14. #------------------------------------------------------------------------------
  15. #  角色显示用脚本。监视 Game_Character 类的实例、
  16. # 自动变化脚本状态。
  17. #==============================================================================
  18. $flyname = "Vehicle"
  19. class Sprite_Character < Sprite_Base
  20.   #--------------------------------------------------------------------------
  21.   # ● 定量
  22.   #--------------------------------------------------------------------------
  23.   BALLOON_WAIT = 12                  # 表情最后帧的等待时间
  24. #--------------------------------------------------------------------------
  25. # ● 定义实例变量
  26. #--------------------------------------------------------------------------
  27. attr_accessor :character                # 角色
  28. #--------------------------------------------------------------------------
  29. # ● 初始化对像
  30. #     viewport  : 查看端口
  31. #     character : 角色 (Game_Character)
  32. #--------------------------------------------------------------------------
  33. def initialize(viewport, character = nil)
  34.    if character.character_name != $flyname
  35.    name = character.name
  36.    end
  37.    super(viewport)
  38.    @character = character
  39.    @namesprite = Sprite.new
  40.    @namesprite.bitmap = Bitmap.new(160, 48)
  41.    @namesprite.bitmap.font.name = "黑体"
  42.    @namesprite.bitmap.font.size = 16
  43.    @namesprite.bitmap.font.color.set(255, 255, 255)
  44.    @evname = name
  45.    if character.character_name != $flyname
  46.    @evname_split = name.split(/,/)[0]
  47. else
  48.    @evname_split = nil
  49. end
  50. if character.character_name != $flyname
  51.    if name[0, 2]=="EV" or character.character_name == $flyname
  52.      @evname_split = " "
  53.    end
  54. end
  55. if character.character_name != $flyname
  56.    if name.split(/,/)[1] != nil
  57.      case name.split(/,/)[1]
  58.      when "0"
  59.        @namesprite.bitmap.font.color.set(255, 255, 255)
  60.      when "1"
  61.        @namesprite.bitmap.font.color.set(128, 128, 255)
  62.      when "2"
  63.        @namesprite.bitmap.font.color.set(255, 128, 128)
  64.      when "3"
  65.        @namesprite.bitmap.font.color.set(128, 255, 128)
  66.      when "4"
  67.        @namesprite.bitmap.font.color.set(128, 255, 255)
  68.      when "5"
  69.        @namesprite.bitmap.font.color.set(255, 128, 255)
  70.      when "6"
  71.        @namesprite.bitmap.font.color.set(255, 255, 128)
  72.      when "7"
  73.        @namesprite.bitmap.font.color.set(192, 192, 192)
  74.      else
  75.        @namesprite.bitmap.font.color.set(255, 255, 255)
  76.      end
  77.    end
  78. end
  79.    if @evname_split != "" and @evname_split != nil
  80.      @namesprite.bitmap.draw_text(0, 0, 160, 36, @evname_split, 1)
  81.    end
  82.     @character = character
  83.     @balloon_duration = 0
  84.    update
  85. end
  86. #--------------------------------------------------------------------------
  87. # ● 释放
  88. #--------------------------------------------------------------------------
  89. def dispose
  90.    dispose_balloon
  91.    @namesprite.bitmap.dispose
  92.    @namesprite.dispose
  93.    super
  94. end
  95. #--------------------------------------------------------------------------
  96. # ● 更新画面
  97. #--------------------------------------------------------------------------
  98. def update
  99.     super
  100.     update_bitmap
  101.     self.visible = (not @character.transparent)
  102.     update_src_rect
  103.     self.x = @character.screen_x
  104.     self.y = @character.screen_y
  105.     self.z = @character.screen_z
  106.     self.opacity = @character.opacity
  107.     self.blend_type = @character.blend_type
  108.     self.bush_depth = @character.bush_depth
  109.     update_balloon
  110.     if @character.animation_id != 0
  111.       animation = $data_animations[@character.animation_id]
  112.       start_animation(animation)
  113.       @character.animation_id = 0
  114.     end
  115.     if @character.balloon_id != 0
  116.       @balloon_id = @character.balloon_id
  117.       start_balloon
  118.       @character.balloon_id = 0
  119.     end

  120.     if character.character_name != $flyname
  121.    if @evname != @character.name
  122.      @namesprite.bitmap.clear
  123.      @evname = @character.name
  124.      @evname_split = @character.name.split(/,/)[0]
  125.      if @character.name.split(/,/)[1] != nil
  126.        case @character.name.split(/,/)[1]
  127.        when "0"
  128.          @namesprite.bitmap.font.color.set(255, 255, 255)
  129.        when "1"
  130.          @namesprite.bitmap.font.color.set(128, 128, 255)
  131.        when "2"
  132.          @namesprite.bitmap.font.color.set(255, 128, 128)
  133.        when "3"
  134.          @namesprite.bitmap.font.color.set(128, 255, 128)
  135.        when "4"
  136.          @namesprite.bitmap.font.color.set(128, 255, 255)
  137.        when "5"
  138.          @namesprite.bitmap.font.color.set(255, 128, 255)
  139.        when "6"
  140.          @namesprite.bitmap.font.color.set(255, 255, 128)
  141.        when "7"
  142.          @namesprite.bitmap.font.color.set(192, 192, 192)
  143.        else
  144.          @namesprite.bitmap.font.color.set(255, 255, 255)
  145.        end
  146.      end
  147.      if @evname_split != "" and @evname_split != nil
  148.        @namesprite.bitmap.draw_text(0, 0, 160, 36, @evname_split, 1)
  149.      end
  150.    end
  151.    @namesprite.x = self.x-80
  152.    @namesprite.y = self.y-self.oy-24
  153.    #@namesprite.visible = $game_switches[39]
  154.    end
  155. end
  156.   #--------------------------------------------------------------------------
  157.   # ● 获取图块图像的指定图块
  158.   #     tile_id : 图块 ID
  159.   #--------------------------------------------------------------------------
  160.   def tileset_bitmap(tile_id)
  161.     set_number = tile_id / 256
  162.     return Cache.system("TileB") if set_number == 0
  163.     return Cache.system("TileC") if set_number == 1
  164.     return Cache.system("TileD") if set_number == 2
  165.     return Cache.system("TileE") if set_number == 3
  166.     return nil
  167.   end
  168.   #--------------------------------------------------------------------------
  169.   # ● 刷新传送的位图数据
  170.   #--------------------------------------------------------------------------
  171.   def update_bitmap
  172.     if @tile_id != @character.tile_id or
  173.        @character_name != @character.character_name or
  174.        @character_index != @character.character_index
  175.       @tile_id = @character.tile_id
  176.       @character_name = @character.character_name
  177.       @character_index = @character.character_index
  178.       if @tile_id > 0
  179.         sx = (@tile_id / 128 % 2 * 8 + @tile_id % 8) * 32;
  180.         sy = @tile_id % 256 / 8 % 16 * 32;
  181.         self.bitmap = tileset_bitmap(@tile_id)
  182.         self.src_rect.set(sx, sy, 32, 32)
  183.         self.ox = 16
  184.         self.oy = 32
  185.       else
  186.         self.bitmap = Cache.character(@character_name)
  187.         sign = @character_name[/^[\!\$]./]
  188.         if sign != nil and sign.include?('$')
  189.           @cw = bitmap.width / 3
  190.           @ch = bitmap.height / 4
  191.         else
  192.           @cw = bitmap.width / 12
  193.           @ch = bitmap.height / 8
  194.         end
  195.         self.ox = @cw / 2
  196.         self.oy = @ch
  197.       end
  198.     end
  199.   end
  200.   #--------------------------------------------------------------------------
  201.   # ● 刷新传送的矩形数据
  202.   #--------------------------------------------------------------------------
  203.   def update_src_rect
  204.     if @tile_id == 0
  205.       index = @character.character_index
  206.       pattern = @character.pattern < 3 ? @character.pattern : 1
  207.       sx = (index % 4 * 3 + pattern) * @cw
  208.       sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch
  209.       self.src_rect.set(sx, sy, @cw, @ch)
  210.     end
  211.   end
  212.   #--------------------------------------------------------------------------
  213.   # ● 开始显示表情图标
  214.   #--------------------------------------------------------------------------
  215.   def start_balloon
  216.     dispose_balloon
  217.     @balloon_duration = 8 * 8 + BALLOON_WAIT
  218.     @balloon_sprite = ::Sprite.new(viewport)
  219.     @balloon_sprite.bitmap = Cache.system("Balloon")
  220.     @balloon_sprite.ox = 16
  221.     @balloon_sprite.oy = 32
  222.     update_balloon
  223.   end
  224.   #--------------------------------------------------------------------------
  225.   # ● 刷新表情图标
  226.   #--------------------------------------------------------------------------
  227.   def update_balloon
  228.     if @balloon_duration > 0
  229.       @balloon_duration -= 1
  230.       if @balloon_duration == 0
  231.         dispose_balloon
  232.       else
  233.         @balloon_sprite.x = x
  234.         @balloon_sprite.y = y - height
  235.         @balloon_sprite.z = z + 200
  236.         if @balloon_duration < BALLOON_WAIT
  237.           sx = 7 * 32
  238.         else
  239.           sx = (7 - (@balloon_duration - BALLOON_WAIT) / 8) * 32
  240.         end
  241.         sy = (@balloon_id - 1) * 32
  242.         @balloon_sprite.src_rect.set(sx, sy, 32, 32)
  243.       end
  244.     end
  245.   end
  246.   #--------------------------------------------------------------------------
  247.   # ● 释放表情图标
  248.   #--------------------------------------------------------------------------
  249.   def dispose_balloon
  250.     if @balloon_sprite != nil
  251.       @balloon_sprite.dispose
  252.       @balloon_sprite = nil
  253.     end
  254.   end
  255. end
  256. class Game_Player < Game_Character
  257. def name
  258.    return ""
  259. end
  260. end
复制代码

yangff脚本
源地址:http://rpg.blue/viewthread.php?tid=72741 [LINE]1,#dddddd[/LINE]系统信息:本贴由楼主认可为正确答案,66RPG感谢您的热情解答~




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