查看: 2780|回复: 6

[已经解决] 足迹脚本如何通过按键来控制显示

[复制链接]
梦石
0
星屑
145
在线时间
190 小时
注册时间
2014-1-18
回帖
232
发表于 2016-10-17 12:45:12 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
脚本:
[pre lang="ruby"]class RPG::Tileset
  #--------------------------------------------------------------------------
  # ● 獲取腳印類型
  #--------------------------------------------------------------------------
  def get_footprint_type(tag_id)
    return false unless tag_id.is_a?(Integer)
    self.note.split(/[\r\n]+/).each { |line|
      if line =~ /\[fp_type #{tag_id} (\S+)\]/
        return $1.to_sym
      end
    }
    return :none
  end
  #--------------------------------------------------------------------------
  # ● 獲取腳印音效
  #--------------------------------------------------------------------------
  def get_footprint_sound(tag_id)
    return false unless tag_id.is_a?(Integer)
    self.note.split(/[\r\n]+/).each { |line|
      if line =~ /\[fp_sound #{tag_id} (\S+)\]/
        return $1
      end
    }
    return ""
  end
  #--------------------------------------------------------------------------
  # ● 獲取腳印淡出速度
  #--------------------------------------------------------------------------
  def get_footprint_fade
    self.note.split(/[\r\n]+/).each { |line|
      if line =~ /\[fp_fade (\d+)\]/
        return $1.to_i
      end
    }
    return 5
  end
end
class Game_Footprint < Game_CharacterBase
  attr_reader :type
  attr_accessor :pattern
  attr_accessor :character_name
  attr_accessor :direction
  attr_accessor :direction_fix
  #--------------------------------------------------------------------------
  # ● 初始化
  #--------------------------------------------------------------------------
  def initialize(t)
    super()
    return unless $game_player
    @direction = $game_player.direction
    self.type = t
    @move_speed = 4
    @move_frequency = 6
    @priority_type = 0
    @through = true
    @transparent = true
    moveto($game_player.x, $game_player.y)
  end
  #--------------------------------------------------------------------------
  # ● 設置類型
  #--------------------------------------------------------------------------
  def type=(t)
    @type = t
    @character_name = "$footprint"
    if @type != :normal
      @character_name += "_" + @type.to_s
    end
    case @type
    when :ripple
      @step_anime = true
      @stop_count = 8
    end
  end
  #--------------------------------------------------------------------------
  # ● 腳印更新
  #--------------------------------------------------------------------------
  def update
    super
    return if pos?($game_player.x, $game_player.y)
    fadespeed = $game_map.tileset.get_footprint_fade
    return if fadespeed == 0
    if Graphics.frame_count % fadespeed == 0
      @opacity -= 10
    end
  end
end
class Game_Footprints
  #--------------------------------------------------------------------------
  # ● 初始化
  #--------------------------------------------------------------------------
  def initialize
    @data = []
  end
  #--------------------------------------------------------------------------
  # ● 加入腳印
  #--------------------------------------------------------------------------
  def push_fp(t=:normal)
    footp = Game_Footprint.new(t)
    footp.moveto($game_player.x, $game_player.y)
    footp.set_direction($game_player.direction)
    @data.push(footp)
  end
  #--------------------------------------------------------------------------
  # ● 設置類型
  #--------------------------------------------------------------------------
  def type=(t)
    @data.each{ |ft|
      ft.type = t
    }
  end
  attr_reader :data
end
class Game_Player < Game_Character
  #--------------------------------------------------------------------------
  # ● 清除移動資訊
  #--------------------------------------------------------------------------
  alias footprint_clear_transfer_info clear_transfer_info
  def clear_transfer_info
    footprint_clear_transfer_info
    @footprint = Game_Footprints.new
  end
  #--------------------------------------------------------------------------
  # ● 返回腳印列表
  #--------------------------------------------------------------------------
  def footprints
    return @footprint.data
  end
  #alias footprint_moveto moveto
  #def moveto(x, y)
  #  footprint_moveto(x, y)
    #push_footprint
  #end
  #--------------------------------------------------------------------------
  # ● 直線移動
  #--------------------------------------------------------------------------
  alias footprint_move_straight move_straight
  def move_straight(d, turn_ok = true)
    previous_direction = @direction
    footprint_move_straight(d, turn_ok)
    if @move_succeed
      push_footprint(previous_direction)
    end
  end
  #--------------------------------------------------------------------------
  # ● 新增腳印
  #--------------------------------------------------------------------------
  def push_footprint(prev_dir=2)
    return unless SceneManager.scene_is?(Scene_Map)
    if @footprint.data.size > 0
      adjust_diagonal_footprint(prev_dir, $game_player.direction)
      @footprint.data[-1].transparent = false
    end
    type = check_terrain?
    return unless type
    @footprint.push_fp(type)
    SceneManager.scene.add_footprint_sprite(@footprint.data[-1])
  end
  def adjust_diagonal_footprint(last_dir, curr_dir)
    return if last_dir == curr_dir
    footprint = @footprint.data[-1]
    name = footprint.character_name + "_dia"
    return unless FileTest.exist?("Graphics/Characters/#{name}.png")
    footprint.character_name = name
    case last_dir+curr_dir
    when 6
      footprint.direction = 8
    when 8
      footprint.direction = 4
    when 12
      footprint.direction = 6
    when 14
      footprint.direction = 2
    end
  end
  #--------------------------------------------------------------------------
  # ● 檢查地形
  #--------------------------------------------------------------------------
  def check_terrain?
    terrain = $game_map.terrain_tag($game_player.x, $game_player.y)
    type  = $game_map.tileset.get_footprint_type(terrain)
    sound = $game_map.tileset.get_footprint_sound(terrain)
    RPG::SE.new(sound).play if sound != ""
    if type == :none
      return false
    else
      return type
    end
  end
end
class Spriteset_Map
  #--------------------------------------------------------------------------
  # ● 增加腳印精靈
  #--------------------------------------------------------------------------
  def add_footprint(footprint)
    @character_sprites.push(Sprite_Character.new(@viewport1, footprint))
  end
  #--------------------------------------------------------------------------
  # ● 更新角色精靈
  #--------------------------------------------------------------------------
  alias footprint_update_characters update_characters
  def update_characters
    footprint_update_characters # 調用原有方法
    update_footsteps # 更新腳印
  end
  #--------------------------------------------------------------------------
  # ● 更新腳印精靈
  #--------------------------------------------------------------------------
  def update_footsteps
    @character_sprites.each {|sprite|
      if sprite.character.is_a?(Game_Footprint)
        sprite.character.update
        if sprite.opacity <= 0 # 不透明度為0時
          @character_sprites.delete(sprite) # 移除精靈
          sprite.dispose # 釋放腳印精靈
        end
      end
    }
  end
end
class Scene_Map < Scene_Base
  #--------------------------------------------------------------------------
  # ● 加入腳印精靈
  #--------------------------------------------------------------------------
  def add_footprint_sprite(footprint)
    @spriteset.add_footprint(footprint)
  end
  #--------------------------------------------------------------------------
  # ● 創建地圖精靈組
  #--------------------------------------------------------------------------
  alias footprint_create_spriteset create_spriteset
  def create_spriteset
    footprint_create_spriteset
    $game_player.push_footprint
  end
end[/pre]

就是我想通过这个配合shift冲刺,做出残影的效果,
但是试了很多方法都不清楚怎么让这个脚本只有在shift按下的情况才显示足迹
梦石
0
星屑
6891
在线时间
7027 小时
注册时间
2013-11-2
回帖
1263

开拓者剧作品鉴家

发表于 2016-10-17 15:12:29 | 显示全部楼层
[pre lang="ruby"]  #--------------------------------------------------------------------------
  # ● 新增腳印
  #--------------------------------------------------------------------------
  def push_footprint(prev_dir=2)
    return unless SceneManager.scene_is?(Scene_Map)
    return if !dash?
    if @footprint.data.size > 0
      adjust_diagonal_footprint(prev_dir, $game_player.direction)
      @footprint.data[-1].transparent = false
    end
    type = check_terrain?
    return unless type
    @footprint.push_fp(type)
    SceneManager.scene.add_footprint_sprite(@footprint.data[-1])
  end[/pre]

第144行的方法改成这样。重点是 return if !dash? 非冲刺状态则不新增脚印。

评分

参与人数 1星屑 +15 收起 理由
xingmot + 15 虽然我XAS的系统还是不行,但是谢谢你了,.

查看全部评分

回复

使用道具 举报

梦石
0
星屑
145
在线时间
190 小时
注册时间
2014-1-18
回帖
232
 楼主| 发表于 2016-10-17 19:45:25 | 显示全部楼层
稍微改一点点脚本就崩溃,还说未定义方法= =
XAS改系统的东西太多了
回复

使用道具 举报

梦石
0
星屑
145
在线时间
190 小时
注册时间
2014-1-18
回帖
232
 楼主| 发表于 2016-10-18 10:45:00 | 显示全部楼层
原本的足迹范例完全没问题,但是XAS里好像改过很多行走图方面的东西,好像判断冲刺的那里被改过了,似乎有一句
alias x_dash dash?
那是不是把dash?换成x_dash就行了?

点评

然后就NameError了= =  发表于 2016-10-18 10:50
回复

使用道具 举报

梦石
0
星屑
6891
在线时间
7027 小时
注册时间
2013-11-2
回帖
1263

开拓者剧作品鉴家

发表于 2016-10-18 11:04:00 | 显示全部楼层
[pre lang="ruby"]  def dash_x?
    return false if @move_route_forcing
    return false if $game_map.disable_dash?
    return false if vehicle
    return Input.press?(:A)
  end[/pre]

在足迹脚本里面添加这一段(在push_footprint的上方)
然后把push_footprint里面的return if !dash? 换成 return if !dash_x?

我不确定这个会不会造成更多问题,但是还是报错的话(尤其是dash_x?里面的上面三行return_false),尝试注释它们,最后剩下的会是
[pre lang="ruby"]  def dash_x?
    return Input.press?(:A)
  end[/pre]

虽然还是不理想(就算是自动事件正常行动或者在不可冲刺的地图,按了冲刺键还是会产生脚步)

评分

参与人数 1星屑 +250 梦石 +1 收起 理由
怪蜀黍 + 250 + 1 楼主认可的解答

查看全部评分

回复

使用道具 举报

梦石
0
星屑
145
在线时间
190 小时
注册时间
2014-1-18
回帖
232
 楼主| 发表于 2016-10-18 11:43:23 | 显示全部楼层
我感觉应该也没问题,但是XAS系统莫名奇妙其他地方会出问题= =
一按shift就崩溃
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部