本帖最后由 芯☆淡茹水 于 2017-12-13 21:18 编辑
这个效果有点233,
随手改造了一下:
#============================================================================== class Game_Event < Game_Character #变量ID VAR_ID = 1 #变量值(大于或等于:停止) VAR_NUM = 3 #-------------------------------------------------------------------------- def is_bird? return false if @list.nil? || @list[0].code != 108 return @list[0].parameters[0].match(/<Location:(\S+)>/) != nil end #-------------------------------------------------------------------------- def target_location return [0,0] if @list.nil? || @list[0].code != 108 return [0,0] if !@list[0].parameters[0].match(/<Location:(\S+)>/) data = $1.split(",") return [data[0].to_i,data[1].to_i] end #-------------------------------------------------------------------------- def land? return is_bird? && $game_variables[VAR_ID] >= VAR_NUM end end #============================================================================== class Game_Character #-------------------------------------------------------------------------- alias xrdata_move_type_random move_type_random def move_type_random if self.is_a?(Game_Event) && land? moveto_target return end xrdata_move_type_random end #-------------------------------------------------------------------------- def moveto_target sx = @x - target_location[0] sy = @y - target_location[1] # 坐标相等情况下 if sx == 0 and sy == 0 key = [$game_map.map_id, @id, "A"] $game_self_switches[key] = $game_map.need_refresh = true return end # 求得差的绝对值 abs_sx = sx.abs abs_sy = sy.abs # 横距离与纵距离相等的情况下 if abs_sx == abs_sy # 随机将边数增加 1 rand(2) == 0 ? abs_sx += 1 : abs_sy += 1 end # 横侧距离长的情况下 if abs_sx > abs_sy # 左右方向优先。向主角移动 sx > 0 ? move_left : move_right if not moving? and sy != 0 sy > 0 ? move_up : move_down end # 竖侧距离长的情况下 else # 上下方向优先。向主角移动 sy > 0 ? move_up : move_down if not moving? and sx != 0 sx > 0 ? move_left : move_right end end end end #==============================================================================
#==============================================================================
class Game_Event < Game_Character
#变量ID
VAR_ID = 1
#变量值(大于或等于:停止)
VAR_NUM = 3
#--------------------------------------------------------------------------
def is_bird?
return false if @list.nil? || @list[0].code != 108
return @list[0].parameters[0].match(/<Location:(\S+)>/) != nil
end
#--------------------------------------------------------------------------
def target_location
return [0,0] if @list.nil? || @list[0].code != 108
return [0,0] if !@list[0].parameters[0].match(/<Location:(\S+)>/)
data = $1.split(",")
return [data[0].to_i,data[1].to_i]
end
#--------------------------------------------------------------------------
def land?
return is_bird? && $game_variables[VAR_ID] >= VAR_NUM
end
end
#==============================================================================
class Game_Character
#--------------------------------------------------------------------------
alias xrdata_move_type_random move_type_random
def move_type_random
if self.is_a?(Game_Event) && land?
moveto_target
return
end
xrdata_move_type_random
end
#--------------------------------------------------------------------------
def moveto_target
sx = @x - target_location[0]
sy = @y - target_location[1]
# 坐标相等情况下
if sx == 0 and sy == 0
key = [$game_map.map_id, @id, "A"]
$game_self_switches[key] = $game_map.need_refresh = true
return
end
# 求得差的绝对值
abs_sx = sx.abs
abs_sy = sy.abs
# 横距离与纵距离相等的情况下
if abs_sx == abs_sy
# 随机将边数增加 1
rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
end
# 横侧距离长的情况下
if abs_sx > abs_sy
# 左右方向优先。向主角移动
sx > 0 ? move_left : move_right
if not moving? and sy != 0
sy > 0 ? move_up : move_down
end
# 竖侧距离长的情况下
else
# 上下方向优先。向主角移动
sy > 0 ? move_up : move_down
if not moving? and sx != 0
sx > 0 ? move_left : move_right
end
end
end
end
#==============================================================================
需要在飞行事件的飞行状态那一页,事件第一行注释:<Location:x,y>
表示需要停止时飞向的坐标(没注释就不能停止飞)。飞到目标自动打开独立开关A。
然后两个事件页设置如下(注意停止时需要 并行处理)
|