【新人求助】关于队员替换问题
rmxp吧
全部回复
仅看楼主
level 1
游戏到中期的时候,队伍里面变成了五个可用角色,怎样能让玩家在菜单栏中自由选择登场角色?求各位大神帮帮咱!
2015年12月02日 03点12分 1
level 9
你可以用一下队伍脚本,由于脚本太长你自己整理吧~
先定义块
#============================================================
module RB
end
module RB::Party
Words_Swap = "换人"
# 替补队员是否能在战斗胜利后获得 EXP 奖励,设置为 true 时可以获得奖励,设置
# 为 false 时则不能。
Get_Exp_Reserve = false
# 角色阵亡时,是否自动切换替补队员,设置为 true 则开启此功能。
Auto_Swap = false
end
#============================================================
# 后面的不怕冲突的话只要改一下基本脚本,当然最好就组合在一起,方便修改。
#============================================================
class Game_Temp
attr_accessor :gain_exp_flag
end
class Game_Party
attr_reader :battle_actors
alias old_ini initialize
def initialize
@leader_id = 0
@battle_actors = []
old_ini
end
def leader
return @leader_id == 0 ? nil : $game_actors[@leader_id]
end
def set_leader(actor_id)
@leader_id = actor_id
$game_player.refresh
$game_map.need_refresh = true
end
def actors
all_flag = !$game_temp.in_battle || (RB::Party::Get_Exp_Reserve && $game_temp.gain_exp_flag)
return all_flag ? @actors : @battle_actors
end
def all_actors
return @actors
end
def reserved_actors
return @actors - @battle_actors
end
#--------------------------------------------------------------------------
# ● 加入同伴
# actor_id : 角色 ID
#--------------------------------------------------------------------------
def add_actor(actor_id)
# 获取角色
actor = $game_actors[actor_id]
# 同伴人数未满 4 人、本角色不在队伍中的情况下
unless @actors.include?(actor)
# 添加角色
@actors.push(actor)
@battle_actors.push(actor) if @battle_actors.size < 4
self.set_leader(actor.id) if self.leader.nil?
# 还原主角
$game_player.refresh
end
end
#--------------------------------------------------------------------------
# ● 角色离开
# actor_id : 角色 ID
#--------------------------------------------------------------------------
def remove_actor(actor_id)
actor = $game_actors[actor_id]
# 删除角色
@actors.delete(actor)
@battle_actors.delete(actor)
self.set_leader(self.actors[0].id) if self.leader == actor
# 还原主角
$game_player.refresh
end
#--------------------------------------------------------------------------
# ● 设置初期同伴
#--------------------------------------------------------------------------
def setup_starting_members
@actors = []
@battle_actors = []
for i in $data_system.party_members
@actors.push($game_actors[i])
@battle_actors.push($game_actors[i]) if @battle_actors.size < 4
end
self.set_leader(@actors[0].id) unless @actors.empty?
end
#--------------------------------------------------------------------------
# ● 设置战斗测试用同伴
#--------------------------------------------------------------------------
def setup_battle_test_members
@actors = []
@battle_actors = []
for battler in $data_system.test_battlers
actor = $game_actors[battler.actor_id]
actor.level = battler.level
gain_weapon(battler.weapon_id, 1)
gain_armor(battler.armor1_id, 1)
gain_armor(battler.armor2_id, 1)
gain_armor(battler.armor3_id, 1)
gain_armor(battler.armor4_id, 1)
actor.equip(0, battler.weapon_id)
actor.equip(1, battler.armor1_id)
actor.equip(2, battler.armor2_id)
actor.equip(3, battler.armor3_id)
actor.equip(4, battler.armor4_id)
actor.recover_all
@actors.push(actor)
@battle_actors.push(actor)
end
@items = {}
for i in 1...$data_items.size
if $data_items[i].name != ""
occasion = $data_items[i].occasion
if occasion == 0 or occasion == 1
@items[i] = 99
end
end
end
end
#--------------------------------------------------------------------------
# ● 同伴成员的还原
#--------------------------------------------------------------------------
def refresh
# 游戏数据载入后角色对像直接从 $game_actors
# 分离。
# 回避由于载入造成的角色再设置的问题。
new_actors = []
new_battle_actors = []
@actors.each do |actor|
if $data_actors[actor.id] != nil
new_actors.push($game_actors[actor.id])
end
end
@battle_actors.each do |actor|
if $data_actors[actor.id] != nil
new_battle_actors.push($game_actors[actor.id])
end
end
@actors = new_actors
@battle_actors = new_battle_actors
end
#--------------------------------------------------------------------------
# ● 全灭判定
#--------------------------------------------------------------------------
def all_dead?
# 同伴人数为 0 的情况下
if self.actors.size == 0
return false
end
# 同伴中无人 HP 在 0 以上
for actor in self.actors
if actor.hp > 0
return false
end
end
# 全灭
return true
end
#--------------------------------------------------------------------------
# ● 对像角色的随机确定
# hp0 : 限制为 HP 0 的角色
#--------------------------------------------------------------------------
def random_target_actor(hp0 = false)
# 初始化轮流
roulette = []
# 循环
for actor in @battle_actors
# 符合条件的场合
if (not hp0 and actor.exist?) or (hp0 and actor.hp0?)
# 获取角色职业的位置 [位置]
position = $data_classes[actor.class_id].position
# 前卫的话 n = 4、中卫的话 n = 3、后卫的话 n = 2
n = 4 - position
# 添加角色的轮流 n 回
n.times do
roulette.push(actor)
end
end
end
# 轮流大小为 0 的情况
if roulette.size == 0
return nil
end
# 转轮盘赌,决定角色
return roulette[rand(roulette.size)]
end
#--------------------------------------------------------------------------
# ● 对像角色的顺序确定
# actor_index : 角色索引
#--------------------------------------------------------------------------
def smooth_target_actor(actor_index)
# 取得对像
actor = @battle_actors[actor_index]
# 对像存在的情况下
if actor != nil and actor.exist?
return actor
end
# 循环
for actor in @actors
# 对像存在的情况下
if actor.exist?
return actor
end
end
end
end
class Game_Actor
attr_reader :battle_disabled
def leader?
return self == $game_party.leader
end
def active
return $game_party.battle_actors.include?(self)
end
def battle_disabled=(bool)
@battle_disabled = bool
$game_party.battle_actors.delete(self) if bool
end
end
class Game_Player
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def refresh
# 同伴人数为 0 的情况下
if $game_party.actors.size == 0 or $game_party.leader == nil
# 清除角色的文件名及对像
@character_name = ""
@character_hue = 0
# 分支结束
return
end
# 获取带头的角色
if $game_party.leader != nil
actor = $game_party.leader
# 设置角色的文件名及对像
@character_name = actor.character_name
@character_hue = actor.character_hue
# 初始化不透明度和合成方式子
@opacity = 255
@blend_type = 0
end
end
end
class Game_BattleAction
attr_accessor :reserved_actor_id
unless method_defined? :rb_clear_20150422
alias rb_clear_20150422 clear
def clear
rb_clear_20150422
@reserved_actor_id = 0
end
end
end
2015年12月04日 02点12分 2
level 9
# 以上是游戏类,接下来修改窗口。
#===============================================================================
class Window_Base < Window
def draw_actor_battle_position(actor, x, y)
if actor.leader?
if actor.active
text = "领队|出战"
else
text = "领队"
end
color = knockout_color
else
color = disabled_color
if actor.battle_disabled
text = "无法出战"
elsif actor.active
text = "出战"
color = normal_color
else
text = "待机"
end
end
self.contents.font.color = color
self.contents.draw_text(x, y, 120, 32, text)
end
end
#==============================================================================
# ■ Window_Selectable
#------------------------------------------------------------------------------
#  拥有光标的移动以及滚动功能的窗口类。
#==============================================================================
class Window_Selectable < Window_Base
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_accessor :row_height # 行高
#--------------------------------------------------------------------------
# ● 初始画对像
# x : 窗口的 X 坐标
# y : 窗口的 Y 坐标
# width : 窗口的宽
# height : 窗口的高
# row_height : 行高 默认是32
#--------------------------------------------------------------------------
alias rb_initialize_20150421 initialize
def initialize(x, y, width, height, row_height = 32)
@row_height = row_height
rb_initialize_20150421(x, y, width, height)
end
#--------------------------------------------------------------------------
# ● 获取开头行
#--------------------------------------------------------------------------
def top_row
# 将窗口内容的传送源 Y 坐标、1 行的高 @row_height 等分
return self.oy / @row_height
end
#--------------------------------------------------------------------------
# ● 设置开头行
# row : 显示开头的行
#--------------------------------------------------------------------------
def top_row=(row)
# row 未满 0 的场合更正为 0
if row < 0
row = 0
end
# row 超过 row_max - 1 的情况下更正为 row_max - 1
if row > row_max - 1
row = row_max - 1
end
# row 1 行高的 @row_height 倍、窗口内容的传送源 Y 坐标
self.oy = row * @row_height
end
#--------------------------------------------------------------------------
# ● 获取 1 页可以显示的行数
#--------------------------------------------------------------------------
def page_row_max
# 窗口的高度,设置画面的高度减去 32 ,除以 1 行的高度 @row_height
return (self.height - 32) / @row_height
end
#--------------------------------------------------------------------------
# ● 更新光标举行
#--------------------------------------------------------------------------
def update_cursor_rect
# 光标位置不满 0 的情况下
if @index < 0
self.cursor_rect.empty
return
end
# 获取当前的行
row = @index / @column_max
# 当前行被显示开头行前面的情况下
if row < self.top_row
# 从当前行向开头行滚动
self.top_row = row
end
# 当前行被显示末尾行之后的情况下
if row > self.top_row + (self.page_row_max - 1)
# 从当前行向末尾滚动
self.top_row = row - (self.page_row_max - 1)
end
# 计算光标的宽
cursor_width = self.width / @column_max - 32
# 计算光标坐标
x = @index % @column_max * (cursor_width + 32)
y = @index / @column_max * @row_height - self.oy
# 更新国标矩形
self.cursor_rect.set(x, y, cursor_width, @row_height)
end
end
class Window_MenuStatus
def initialize
super(0, 0, 480, 480, 112)
refresh
self.active = false
self.index = -1
end
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@item_max = $game_party.actors.size
self.contents = Bitmap.new(width - 32, @item_max == 0 ? 32 : @item_max * 112)
for i in 0...$game_party.actors.size
x = 64
y = i * 112
actor = $game_party.actors[i]
draw_actor_graphic(actor, x - 40, y + 80)
draw_actor_name(actor, x, y)
draw_actor_class(actor, x + 144, y)
draw_actor_level(actor, x, y + 32)
draw_actor_state(actor, x + 90, y + 32)
draw_actor_exp(actor, x, y + 64)
draw_actor_hp(actor, x + 236, y + 32)
draw_actor_sp(actor, x + 236, y + 64)
draw_actor_battle_position(actor, x + 236, y)
end
end
def update_cursor_rect
super
end
end
class Window_Target
def initialize
super(0, 0, 336, 480, 112)
self.z += 10
@item_max = $game_party.actors.size
self.contents = Bitmap.new(width - 32, @item_max == 0 ? 32 : @item_max * 112)
refresh
end
def update_cursor_rect
super
end
end
class Window_ReservedActors < Window_Selectable
def initialize
super(0, 64, 640, 256, 112)
self.opacity = 160
self.index = 0
self.active = true
@column_max = 2
refresh
end
def actor
return @data[self.index]
end
def refresh
if self.contents != nil
self.contents.dispose
self.contents = nil
end
@data = []
$game_party.all_actors.each do |actor|
@data << actor unless actor.active || actor.battle_disabled
end
@item_max = @data.size
if @item_max > 0
self.contents = Bitmap.new (width - 32, (@item_max + 1) / 2 * 128)
@data.each_with_index do |actor, index|
x = 4 + index % 2 * (288 + 32)
y = index / 2 * 112
draw_actor_graphic(actor, x + 16, y + 80)
draw_actor_hp(actor, x + 48, y + 20)
draw_actor_sp(actor, x + 48, y + 52)
end
end
end
def update_help
# 帮助窗口显示角色的状态
self.actor == nil ? @help_window.set_text("") : @help_window.set_actor(self.actor)
end
end
2015年12月04日 02点12分 3
level 9
噢噢不好意思~还有菜单类没给你。你把下面的复制到所有WINDOW类的下面,然后后面紧接着scene的battle,或者不要也可以。
class Scene_Menu
unless method_defined? :rb_update_command_20150421
alias rb_update_command_20150421 update_command
def update_command
if Input.trigger?(Input::X)
$game_system.se_play($data_system.decision_se)
@command_window.active = false
@status_window.active = true
@status_window.index = 0
@leader_adjust = true
return
end
if Input.trigger?(Input::Y)
$game_system.se_play($data_system.decision_se)
@command_window.active = false
@status_window.active = true
@status_window.index = 0
@battler_adjust = true
return
end
rb_update_command_20150421
end
end
unless method_defined? :rb_update_status_20150421
alias rb_update_status_20150421 update_status
def update_status
if @leader_adjust
update_leader
return
end
if @battler_adjust
update_battler
return
end
rb_update_status_20150421
end
end
def update_leader
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@leader_adjust = false
@status_window.active = false
@status_window.index = -1
@command_window.active = true
return
end
if Input.trigger?(Input::C)
if $game_party.actors.size == 0
$game_system.se_play($data_system.buzzer_se)
else
$game_system.se_play($data_system.decision_se)
$game_party.set_leader($game_party.actors[@status_window.index].id)
@status_window.refresh
end
end
end
def update_battler
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
@battler_adjust = false
@status_window.active = false
@status_window.index = -1
@command_window.active = true
return
end
if Input.trigger?(Input::C)
actor = $game_party.actors[@status_window.index]
if actor == nil || actor.battle_disabled ||
(actor.active && $game_party.battle_actors.size == 1) ||
(!actor.active && $game_party.battle_actors.size == 4)
$game_system.se_play($data_system.buzzer_se)
else
$game_system.se_play($data_system.decision_se)
actor.active ? $game_party.battle_actors.delete(actor) : $game_party.battle_actors.push(actor)
@status_window.refresh
end
end
end
end
2015年12月04日 09点12分 7
多谢大神相助!!已粉!
2015年12月04日 17点12分
@十六夜枫铭 咦竟然不能关注
2015年12月04日 17点12分
还是出错了,是不是我接的地方有问题,大神可以加Q么,
2015年12月04日 17点12分
@十六夜枫铭 1271902253。
2015年12月05日 02点12分
level 9
样板是按Z键替换队员
2016年01月28日 10点01分 8
1