查看: 1752|回复: 1

[已经过期] 事件向事件移动,当目标消失后就报错

[复制链接]
梦石
0
星屑
12161
在线时间
4435 小时
注册时间
2014-4-11
回帖
5616

开拓者

发表于 2016-2-13 02:19:20 | 显示全部楼层 |阅读模式

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

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

×
我的队友是事件,我的敌人使用事件向事件移动脚本来索定队友。
我按M可以切换到队友,自己变身事件队友
我死亡后会自动切换成队友。
我被打死后,切换到队友了,然后就报错说X没有定义。



队友切换脚本[pre lang="ruby"]#=============================================================================#
#                          ■ BFS - SwitchLeader
#-----------------------------------------------------------------------------#
#                              切换队友
#                             可以修改27行
#=============================================================================#
class Game_Party
  def switch_leader
    if not @actors_alive.size == 1
      loop do
        leading_actor_info = @actors[0]
        @actors.delete_at(0)
        @actors.push(leading_actor_info)
        break unless @actors[0].dead? == true        
      end
      friend_party_update
      $scene.hud_update
      exchange_event
      exchange_position
      $game_player.kds
      lead_id = $game_system.friend_event_id[0]
      $game_system.friend_event_id.delete_at(0)
      $game_system.friend_event_id.push(lead_id)
      $scene.spriteset.dispose
      $scene.spriteset = Spriteset_Map.new
      BFS_Friends.weapon_recheck
      $game_player.indicator_setup = true

    else
#      $game_player.pop_damage_text("没有可替换的队友")
    end
  end
  def friend_party_update
    temp = []
    temp = @actors.clone
    temp.delete_at(0)
    @friends = temp.clone
    temp = []
    @friends_alive = -1
    @actors_alive = []
    for i in @actors
      @actors_alive.push(i) unless i.dead?
      @friends_alive += 1 unless i.dead?
    end
  end
  def exchange_position
    temp = $game_map.events[$game_system.friend_event_id[0]]
    x, y = $game_player.x, $game_player.y
    $game_player.movekds(temp.x, temp.y)
    $game_map.events[$game_system.friend_event_id[0]].moveto(x, y)
    temp, x, y = ""
  end
  def exchange_event
    id = @actors[@actors.size - 1].id
    temp = $game_map.events[$game_system.friend_event_id[0]]
    $game_map.events[$game_system.friend_event_id[0]] = \
    Game_Friend.new($game_system.friend_event_id[0], \
    BFS_Friends.get_event_to(id, temp.x, temp.y))
  end
end
class Scene_Map
  def hud_update
    if @acthud != nil
    @acthud.dispose
    @acthud = Active_Hud.new(@viewport)
    end
  end
end
[/pre]



事件向事件移动脚本
点击展开/收起def move_toward_event(event_id)
  if event_id == nil
          return
    end

    # 指定自身的情况下不执行动作
    if event_id == self.id
      return
    end
    # 求得与队友事件的坐标差
    sx = @x - $game_map.events[event_id].x
    sy = @y - $game_map.events[event_id].y
    # 坐标相等情况下
    if sx == 0 and sy == 0
      return
    end
        # 求得差的绝对值
    abs_sx = sx > 0 ? sx : -sx
    abs_sy = sy > 0 ? sy : -sy
            # 横距离与纵距离相等的情况下
    if abs_sx == abs_sy
      # 随机将边数增加 1
      rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
    end
    # 求得与主角坐标的差
    ax = (@x - $game_player.x).abs
    ay = (@y - $game_player.y).abs
    #向近的目标移动(主角和队友)
    if (abs_sx + abs_sy) <= (ax + ay)
               #向事件移动
    # 横侧距离长的情况下
    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
  else
                      #向主角移动
         move_toward_player
  end
  #当离主角近时
    if ax <= 1 and ay <= 1
      #普通攻击开
      shoot(176)
            @wait_count = 30
          end
            #当离事件近时
    if abs_sx <= 1 and abs_sy <= 1
      #普通攻击开
             shoot(176)
            @wait_count = 30
end
end
梦石
0
星屑
39236
在线时间
11155 小时
注册时间
2009-3-15
回帖
4768
发表于 2016-2-13 10:10:55 | 显示全部楼层
本帖最后由 soulsaga 于 2016-2-13 16:34 编辑

那个...用事件事向事件移动脚本解決无视队友的问题不太好吧..这个好像只能指定走向指定的事件ID.吧? 队友事件ID每次离开当前地图再进就会各自+1..即从2000,2001,2002,变成2001,2002,2003所以追队友指定事件ID最后一定会出问题的

我也自己解決了无视队友问题..是根据论坛的大神给的答案我再自己修改了下得来的..
Game_Character3的def move_toward_player
  1.   # ● 接近主角
  2.   #--------------------------------------------------------------------------
  3.   def move_toward_player
  4.     # 求得與主角的座標差值
  5.     sx = @x - $game_player.x
  6.     sy = @y - $game_player.y
  7.     friendarray = []
  8.     friendAX = []
  9.     friendAY = []
  10. #$game_system.friend_event_id保存了所有队友事件ID的数组
  11.     if $game_system.friend_event_id != []
  12.     for i in $game_system.friend_event_id
  13.       friend = $game_map.events[i]
  14.       #返回坐标绝对值
  15.       friendxy = (@x - friend.x).abs + (@y - friend.y).abs
  16.       #往数组尾加入计算后的怪物与队友间的距离
  17.       friendarray.push(friendxy)
  18.       #数组记录所有队友的XY座标
  19.       friendAX.push(friend.x)
  20.       friendAY.push(friend.y)
  21.       end
  22.       #取得距离数组的最小值
  23.       friendmin = friendarray.min
  24.       #如果最小值与I号队友距离相等则靠近
  25.       for i in 0..$game_system.friend_event_id.size - 1
  26.       if friendmin == friendarray[i]
  27.       friendx = friendAX[i]
  28.       friendy = friendAY[i]
  29.     end
  30.     end
  31.    
  32.     if sx.abs + sy.abs > (@x-friendx).abs + (@y - friendy).abs
  33.       sx = @x-friendx
  34.       sy = @y - friendy
  35.     end
  36.     end

  37.     # 座標相等情況下
  38.     if sx == 0 and sy == 0
  39.       return
  40.     end
  41.     # 求得差值的絕對值
  42.     abs_sx = sx.abs
  43.     abs_sy = sy.abs
  44.     # 橫距離與縱距離相等的情況下
  45.     if abs_sx == abs_sy
  46.       # 隨機將邊數增加 1
  47.       rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
  48.     end
  49.     # 橫側距離長的情況下
  50.     if abs_sx > abs_sy
  51.       # 左右方向優先。向主角移動
  52.       sx > 0 ? move_left : move_right
  53.       if not moving? and sy != 0
  54.         sy > 0 ? move_up : move_down
  55.       end
  56.     # 豎側距離長的情況下
  57.     else
  58.       # 上下方向優先。向主角移動
  59.       sy > 0 ? move_up : move_down
  60.       if not moving? and sx != 0
  61.         sx > 0 ? move_left : move_right
  62.       end
  63.     end
  64.   end
复制代码
另外加入重复角色不是只要在人物仓库脚本的def add_actor(actor_id)那里把判断角色去掉不就可以了么..
r.jpg

点评

重复队友不好用。一个死了全都死了。他是按照数据库ID一对一的。修改要改很多地方  发表于 2016-2-13 20:53
不是,无视队友还要改其他的。我这个是这个问题  发表于 2016-2-13 20:52
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部