查看: 1937|回复: 2

[已经解决] 求脚队伍角色重复存在的方法

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

开拓者

发表于 2016-1-30 21:10:59 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 yang1zhi 于 2016-1-30 22:25 编辑

主要来用做宠物。
使用的BFS系统有队友功能。
但是一个ID只是存在一个。
这样的话那一个宠物就只能存在一个了。
就不能同时带着3只史莱姆了。

BFS系统网盘
http://pan.baidu.com/s/1c0ZMN64

梦石
0
星屑
9716
在线时间
2775 小时
注册时间
2008-9-5
回帖
3458

开拓者短篇八RM组冠军短篇九导演组亚军白银编剧

发表于 2016-1-31 14:28:28 | 显示全部楼层
本帖最后由 cinderelmini 于 2016-1-31 16:17 编辑

楼层更新:
给每个角色都添加了队伍序列名字(不会显示在画面),
也就是说,队伍里没有相同角色的时候,这个名字是角色原本的名字,
如果有两个及以上相同角色的话,第二个开始,序列名字会变成“名字_1”,“名字_2”依次递加,
(注意:第一个角色的序列名字还是原来的名字,不会变动。)
所以如果没猜错的话,那个BFS系统是用事件名字来和队友名字对应的?
这样的话,第二个队员的事件名字就是“队员名字_1”这样设置了。
(窝这里缺素材什么的不能测试,单纯看了代码之后猜的,总之有问题再处理……)
(啊,这篇脚本要放在BFS系统的下面。)
点击展开/收起
  1. class Game_Party
  2.   #--------------------------------------------------------------------------
  3.   # ● 同伴最大数
  4.   #--------------------------------------------------------------------------
  5.   def member_size
  6.     return 6
  7.   end
  8.   #--------------------------------------------------------------------------
  9.   # ● 加入同伴
  10.   #     actor_id : 角色 ID
  11.   #--------------------------------------------------------------------------
  12.   def add_actor(actor_id)
  13.     # 获取角色
  14.     add_actor = $game_actors[actor_id].dup
  15.     # 设置队伍序列
  16.     party_index = 0
  17.     for actor in @actors
  18.       if actor.id == add_actor.id
  19.         party_index += 1
  20.       end
  21.     end
  22.     # 如果是第二个及以上的相同队员的话,这个队员的队伍名字会加上队伍序列号
  23.     if party_index > 0
  24.       add_actor.party_name = add_actor.name + "_" + party_index.to_s
  25.     end
  26.     # 同伴人数未满最大人数的话就加入角色
  27.     if @actors.size < member_size
  28.       # 添加角色
  29.       @actors.push(add_actor)
  30.       # 还原主角
  31.       $game_player.refresh
  32.     end
  33.   end
  34.   #--------------------------------------------------------------------------
  35.   # ● 角色离开
  36.   #     actor_id : 角色 ID
  37.   #--------------------------------------------------------------------------
  38.   def remove_actor(actor_id)
  39.     # 如果指定ID让角色离队的话只删除第一个同ID的队员。
  40.     leave_actor = nil
  41.     for actor in @actors
  42.       if actor.id == actor_id
  43.         leave_actor = actor
  44.         break
  45.       end
  46.     end
  47.     return if leave_actor.nil?
  48.     @actors.delete_at(@actors.index(leave_actor))
  49.     # 还原主角
  50.     $game_player.refresh
  51.   end
  52. end

  53. class Game_Actor < Game_Battler
  54.   attr_accessor   :party_name  # 队伍序列名字
  55.   
  56.   alias sn_160131_setup setup
  57.   def setup(actor_id)
  58.     sn_160131_setup(actor_id)
  59.     @party_name = @name
  60.   end
  61. end


  62. class Game_Friend < Game_Event
  63.   alias sn_160131_party_id party_id
  64.   def party_id
  65.     for i in $game_party.actors
  66.       # 改成用队员的队伍序列名字做判定
  67.       if self.name == i.party_name
  68.         return i.index.to_i
  69.         break
  70.       end
  71.     end
  72.   end
  73. end
复制代码

点评

地图界面上队友的图标有出现了。不过队友的事件没出现  发表于 2016-1-31 18:00

评分

参与人数 1星屑 +100 收起 理由
RyanBern + 100 塞糖

查看全部评分

回复

使用道具 举报

梦石
0
星屑
12161
在线时间
4435 小时
注册时间
2014-4-11
回帖
5616

开拓者

 楼主| 发表于 2016-1-31 15:21:50 | 显示全部楼层
cinderelmini 发表于 2016-1-31 14:28
稍微写了个也许大概可行的……用法Main前……
可以自己设定队伍最大人数,如果在别的地方设置了最大人数的 ...

默认系统可以。
BFS系统使用后,菜单里是有重复人物了,不过地图上并没有出现队友。
BFS地图上的队友是读取第158张地图上设置的事件来实现的。


[pre lang="ruby"]#=============================================================================#
#                          ■ BFS - FriendDefine
#-----------------------------------------------------------------------------#
#                      对于队友事件、图像的核心定义
#=============================================================================#
class Friend_Sprite < Sprite_Character
  attr_accessor :character
  attr_accessor :friend_party_id
  attr_accessor :actor_database_id
  def initialize(viewport, character = nil)
    super(viewport, character)
    @character = character
    @indicator = Sprite.new(viewport)
    @indicator.opacity = 0
    @indicator.bitmap = RPG::Cache.windowskin("Player2_Cursor")
    @indicator.z = 5000
    for i in $game_party.actors
      if @character.name == i.name
        @friend_party_id = (i.index - 1).to_i
        break
      end
    end
    for i in 1..$game_actors.size
      if @character.name == $game_actors.name
        @actor_database_id = $game_actors.id
        break
      end
    end
    @hpsprite = Sprite.new(viewport)
    @hpsprite.z = 0
    ox = BFS_DataBase::HP_BAR_OX[@actor_database_id]
    oy = BFS_DataBase::HP_BAR_OY[@actor_database_id]
    @hpsprite.bitmap = Bitmap.new(ox + 75, oy + 50)
    black = Color.new(0, 0, 0)
    @hpsprite.bitmap.fill_rect(ox, oy, 26, 1, black) #上
    @hpsprite.bitmap.fill_rect(ox, oy + 8, 26, 1, black) #下
    @hpsprite.bitmap.fill_rect(ox, oy, 1, 9, black) #左
    @hpsprite.bitmap.fill_rect(ox + 25, oy, 1, 9, black) #右
    @hpsprite.bitmap.fill_rect(ox, oy + 4, 26, 1, black) #中
    hp = ($game_party.friends[@friend_party_id].hp).to_f
    hp_w = ((hp / $game_party.friends[@friend_party_id].maxhp) * 24)
    sp = ($game_party.friends[@friend_party_id].sp).to_f
    sp_w = ((sp / $game_party.friends[@friend_party_id].maxsp) * 24)
    @hpsprite.bitmap.fill_rect(ox + 1, oy + 1, hp_w, 3, Color.new(255, 0, 0))
    @hpsprite.bitmap.fill_rect(ox + 1, oy + 5, sp_w, 3, Color.new(0, 255, 255))
  end
  def update
    super
    if @character.battler.tactics_type == 2
      @indicator.opacity = 225
      @indicator.x = self.x - 18
      @indicator.y = self.y - 108
    else
      @indicator.opacity = 0
    end
    @hpsprite.opacity = self.opacity
    self.opacity = 0 if $game_party.friends[@friend_party_id].dead?
    @hpsprite.bitmap.clear
    ox = BFS_DataBase::HP_BAR_OX[@actor_database_id]
    oy = BFS_DataBase::HP_BAR_OY[@actor_database_id]
    black = Color.new(0, 0, 0)
    @hpsprite.bitmap.fill_rect(ox, oy, 26, 1, black) #上
    @hpsprite.bitmap.fill_rect(ox, oy + 8, 26, 1, black) #下
    @hpsprite.bitmap.fill_rect(ox, oy, 1, 9, black) #左
    @hpsprite.bitmap.fill_rect(ox + 25, oy, 1, 9, black) #右
    @hpsprite.bitmap.fill_rect(ox, oy + 4, 26, 1, black) #中
    hp = ($game_party.friends[@friend_party_id].hp).to_f
    hp_w = ((hp / $game_party.friends[@friend_party_id].maxhp) * 24)
    sp = ($game_party.friends[@friend_party_id].sp).to_f
    sp_w = ((sp / $game_party.friends[@friend_party_id].maxsp) * 24)
    @hpsprite.bitmap.fill_rect(ox + 1, oy + 1, hp_w, 3, Color.new(255, 0, 0))
    @hpsprite.bitmap.fill_rect(ox + 1, oy + 5, sp_w, 3, Color.new(0, 255, 255))
    @hpsprite.x = self.x - self.ox
    @hpsprite.y = self.y
  end
end
class Game_Friend < Game_Event
  attr_accessor :enemy_in_range
  attr_accessor :aimovement_stand_by
  include XRXS_BreakActs
  def initialize(map_id, event)
    super(map_id, event)
    @last_dead = false
    @max_speed = @move_speed
    @aimovement_stand_by = false
    @collapse_done = $game_party.actors[self.party_id].dead?
  end
  def controllable?  
    return !(moving? or $game_system.map_interpreter.running? or
            @move_route_forcing or $game_temp.message_window_showing or
            self.action != nil or @attacking)
  end
  def party_id
    for i in $game_party.actors
      if self.name == i.name
        return i.index.to_i
        break
      end
    end   
  end
  def update
    super
    if @last_dead
      unless self.battler.dead?
        recover
      end
    end
    @last_dead = self.battler.dead?
  end
  def pop_damage_text(name)
    self.battler.damage = name
    self.battler.damage_pop = true
  end  
  def recover
    @collapse_done = false
    @through = @page.through
    @character_name = @page.graphic.character_name
    @opacity = 255
    $game_system.friend_event_id.insert(party_id ,id)
    BFS_Friends.refresh_map
    $game_party.friend_party_update
    self.battler_recheck
    @animation_id = BFS_Setting::ANI_RECOVER
  end
  def update_hp_sensor
    @low_hp_characters = 0
    for i in $game_party.actors
      @low_hp_characters += 1 if (i.hp < i.maxhp * 0.6)
    end
  end
   def update_sensor
     @enemy_in_range = nil
     for i in $game_map.events.values
       if i.battler != nil and i.battler.is_a?(Game_Enemy) and not
         BFS_Setting::NOT_ATTACK_ID.include?(i.enemy_id)
         distance = (i.x - self.x).abs + (i.y - self.y).abs
         @enemy_in_range = i.id if (distance <= BFS_Setting::SENSOR_RANGE)
         break
       end
     end
   end  
end
module BFS_Friends
  def self.add(friend_id)
      map_id = BFS_Setting::FRIEND_MAP_ID
      return unless self.is_map?        
      map = load_data(sprintf("Data/Map%03d.rxdata", map_id))     
      temp = Marshal.load(Marshal.dump(map))      
      if !$game_system.map_events_number
         $game_system.map_events_number = {}
      end  
      sum = $game_system.map_events_number      
      m_id = $game_map.map_id      
      sum[m_id] == nil ? sum[m_id] = 2000 : sum[m_id] += 1
      new_event_id = sum[m_id]      
      temp.events[friend_id].id = new_event_id      
      temp.events[friend_id].x,temp.events[friend_id].y = $game_player.x, $game_player.y      
      $game_map.events[new_event_id] = Game_Friend.new(m_id,temp.events[friend_id])
      $BFS_temp = $game_map.events[new_event_id]
      $game_system.friend_event_id.push(new_event_id) unless $game_actors[friend_id].dead?
    end   
   def self.get_event_to(id, x, y)
      map = load_data(sprintf("Data/Map%03d.rxdata", BFS_Setting::FRIEND_MAP_ID))     
      temp = Marshal.load(Marshal.dump(map))      
      temp.events[id].x,temp.events[id].y = x,y      
      return temp.events[id]
  end   
  def self.refresh_map
  $scene.spriteset.dispose
  $scene.spriteset = Spriteset_Map.new
    end
  def self.is_map?
      (return true) if $scene.is_a?(Scene_Map)
      return false
    end
  def self.prepare_for_transferring
    $game_system.friend_event_id = []
    return if $game_party.friends == []
      for i in $game_party.friends
        add(i.id)
      end
    $game_party.friend_party_update
  end
  def self.prepare_for_loading
    $game_system.friend_event_id = []
    return if $game_party.friends == []
      for i in $game_party.friends
        add(i.id)
      end
    $game_party.friend_party_update
    m = 0
    for i in $game_system.friend_event_id
      c = $game_map.events
      x = $game_system.bfs_positions[m][0]
      y = $game_system.bfs_positions[m][1]
      direction = $game_system.bfs_positions[m][2]
      c.moveto(x,y)
      c.direction = direction
      m += 1
    end
  end
    def self.delete_all_friends
      for i in $game_system.friend_event_id
        $game_map.events.delete(i)
      end
    end
  def self.friend_defeat_process(friend_battler, id)
    $game_temp.ifw_text = friend_battler.name + "阵亡"
    $game_temp.ifw_active = true
    $game_system.friend_event_id.delete(id)
    $game_party.friend_party_update
  end
  def self.weapon_recheck
    for i in $game_party.actors
      i.slash_id = XAS_SKILL::WEAPON_ID_TOOL[i.weapon_id] if XAS_SKILL::WEAPON_ID_TOOL[i.weapon_id]
    end
  end
end  
class Game_System
  attr_accessor :map_events_number            
  attr_accessor :map_data            
end  
class Scene_Map
  attr_accessor :spriteset            
end
class Game_Event < Game_Character
  attr_reader   :event
  def name
   return @event.name
  end
end
module BFS_DataBase
  MAP_ID = []
  HP_BAR_OX = []
  HP_BAR_OY = []
end
class Sprite_Character < RPG::Sprite
  alias bfs_sp1_ini initialize
  def initialize(viewport, character = nil)
    bfs_sp1_ini(viewport, character)
    @player = character.is_a?(Game_Player)
    @indicator_step = 0
    if @player
      @indicator = Sprite.new(viewport)
      @indicator.opacity = 0
      @indicator.bitmap = RPG::Cache.windowskin("Player1_Cursor")
      @indicator.x = self.x - 18
      @indicator.y = self.y - 108
      @indicator.z = 5000
    end
  end
  alias bfs_sp1_update_old update
  def update
    bfs_sp1_update_old
    if @player
      if @character.indicator_setup
        @character.indicator_setup = false
        @indicator_step = 220
      end
      @indicator.x = self.x - 18
      @indicator.y = self.y - 108
      if @indicator_step > 0
        @indicator_step -= 1
        case @indicator_step
        when 1..20
          @indicator.opacity -= 15
        when 201..219
          @indicator.opacity += 15
        end
      end
    end
  end
end
[/pre]

点评

这个脚本很厉害的,能让XAS多人同时战斗  发表于 2016-1-31 18:01
上面楼层更新……  发表于 2016-1-31 16:17
这篇脚本看起来好麻烦的样子……不过应该是获取party_id那段的写法要改改……  发表于 2016-1-31 16:01
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部