加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 淡月流萤 于 2025-7-16 19:18 编辑
最近开始重温以前的老游戏,在刮痧过程中,总想着要是有一键攻击就好了。刚好前段时间RPG Maker喜加一了,研究了几天,连蒙带猜,整了个脚本,大致达到了预期的效果。
在战斗中选指令时,按 A 对应的键(键盘上默认是 Z),就开启自动普攻,选择下一个行动的敌人为目标(适用于CP战斗);
如果角色血量百分比低于指定值,就停止自动普攻。
class Scene_Battle STOP_AUTO_HP = 10 #-------------------------------------------------------------------------- # ● 刷新画面 (角色命令回合 : 基本命令) #-------------------------------------------------------------------------- alias super_update_phase3_basic_command update_phase3_basic_command def update_phase3_basic_command # 按下 A 键的情况下 if Input.trigger?(Input::A) # 演奏确定 SE $game_system.se_play($data_system.decision_se) # 设置默认攻击目标,启用自动普攻 @auto_enemy_index = 0 auto return end super_update_phase3_basic_command end #-------------------------------------------------------------------------- # ● 设置角色指令窗口 #-------------------------------------------------------------------------- alias super_phase3_setup_command_window phase3_setup_command_window def phase3_setup_command_window # 如果启用自动普攻 if @auto_enemy_index != nil auto return end super_phase3_setup_command_window end ########################## def auto # 如果角色的血量小于指定比例, 停止自动普攻 for actor in $game_party.actors if actor.hp * 100.0 / actor.maxhp <= STOP_AUTO_HP # 演奏取消 SE $game_system.se_play($data_system.cancel_se) @auto_enemy_index = nil # 设置角色的命令窗口 phase3_setup_command_window return end end # 找下个行动的敌人,作为攻击目标(如果不是CP战斗,可以删掉这段) fast = nil for enemy in $game_troop.enemies if enemy.exist? if fast == nil fast = enemy elsif fast.cp < enemy.cp fast = enemy end end end @auto_enemy_index = fast.index # 普攻行动 @active_battler.current_action.kind = 0 @active_battler.current_action.basic = 0 # 选择敌人 @active_battler.current_action.target_index = @auto_enemy_index # 无效化角色指令窗口 @actor_command_window.active = false @actor_command_window.visible = false phase3_next_actor end end
class Scene_Battle
STOP_AUTO_HP = 10
#--------------------------------------------------------------------------
# ● 刷新画面 (角色命令回合 : 基本命令)
#--------------------------------------------------------------------------
alias super_update_phase3_basic_command update_phase3_basic_command
def update_phase3_basic_command
# 按下 A 键的情况下
if Input.trigger?(Input::A)
# 演奏确定 SE
$game_system.se_play($data_system.decision_se)
# 设置默认攻击目标,启用自动普攻
@auto_enemy_index = 0
auto
return
end
super_update_phase3_basic_command
end
#--------------------------------------------------------------------------
# ● 设置角色指令窗口
#--------------------------------------------------------------------------
alias super_phase3_setup_command_window phase3_setup_command_window
def phase3_setup_command_window
# 如果启用自动普攻
if @auto_enemy_index != nil
auto
return
end
super_phase3_setup_command_window
end
##########################
def auto
# 如果角色的血量小于指定比例, 停止自动普攻
for actor in $game_party.actors
if actor.hp * 100.0 / actor.maxhp <= STOP_AUTO_HP
# 演奏取消 SE
$game_system.se_play($data_system.cancel_se)
@auto_enemy_index = nil
# 设置角色的命令窗口
phase3_setup_command_window
return
end
end
# 找下个行动的敌人,作为攻击目标(如果不是CP战斗,可以删掉这段)
fast = nil
for enemy in $game_troop.enemies
if enemy.exist?
if fast == nil
fast = enemy
elsif fast.cp < enemy.cp
fast = enemy
end
end
end
@auto_enemy_index = fast.index
# 普攻行动
@active_battler.current_action.kind = 0
@active_battler.current_action.basic = 0
# 选择敌人
@active_battler.current_action.target_index = @auto_enemy_index
# 无效化角色指令窗口
@actor_command_window.active = false
@actor_command_window.visible = false
phase3_next_actor
end
end
本来想实现一键停止自动普攻,但好像需要用到多线程。额,我只是想玩游戏,并不想花太多时间学习脚本,所以就用了简单的自动停止。 |