Individual Battle Commands
by RPG Advocate
saved from Phylomortis.Com
Introduction
This script changes the battle engine so that each character has individual battle commands, rather than be restricted to the four defined in the database. It also changes the engine so that battle commands are recognized by name rather than by position within the battle command menu. With the code provided here, each actor's default battle commands are still "Attack", "Skill", "Defend", and "Item". The code provided here is only a framework that makes it easy to add new commands, and still only supports the four basic commands. To add support for new commands, you will need to make the engine recognize them by adding to the case statement starting around line 380 in the script, and then adding the code to process the new command.
To change an actor's command through a script call, merely use:
$game_actors[n].battle_commands = ["Attack", "Skill", "Defend", "Item"]
where 'n' indicates the actor in your database... substituting the names of the commands in the array with your own.
Again... the engine recognizes the names of the battle commands rather than index positions. So if you do not add the new command(s) (by its name) to the engine, any added command(s) won't be recognized.
Script
"script"
Code:
# Individual Battle Commands
# by RPG Advocate
#==============================================================================
# ** Game_Actor
#------------------------------------------------------------------------------
# This class handles the actor. It's used within the Game_Actors class
# ($game_actors) and refers to the Game_Party class ($game_party).
#==============================================================================
class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :battle_commands # Array of battle commands
#--------------------------------------------------------------------------
# * Object Initialization
# actor_id : actor ID
#--------------------------------------------------------------------------
alias ibc_setup setup
def setup(actor_id)
ibc_setup(actor_id)
@battle_commands = ["Attack", "Skill", "Defend", "Item"]
end
end
#==============================================================================
# ** Window_BattleCommand
#------------------------------------------------------------------------------
# This window deals with battle command choices.
#==============================================================================
class Window_BattleCommand < Window_Selectable
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :commands # battle commands
#--------------------------------------------------------------------------
# * Object Initialization
# actor : actor
# width : command width
#--------------------------------------------------------------------------
def initialize(actor, width)
@actor = actor
super(0, 0, width, 160)
self.x = -9999
@column_max = 1
@item_max = @actor.battle_commands.size
@commands = @actor.battle_commands
if @commands == []
name = actor.name
print("Error: " + name + " must have at least one battle command.")
exit
end
self.contents = Bitmap.new(width - 32, @item_max * 32)
refresh
self.index = 0
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
self.contents.font.name = "Arial"
self.contents.font.size = 24
for i in 0...@item_max
draw_item(i, normal_color)
end
end
#--------------------------------------------------------------------------
# * Draw Item
# index : item number
# color : text color
#--------------------------------------------------------------------------
def draw_item(index, color)
self.contents.font.color = color
rect = Rect.new(4, 32 * index, self.contents.width - 8, 32)
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
self.contents.draw_text(rect, @commands[index])
end
#--------------------------------------------------------------------------
# * Disable Item
# index : item number
#--------------------------------------------------------------------------
def disable_item(index)
draw_item(index, disabled_color)
end
end
#==============================================================================
# ** Interpreter
#------------------------------------------------------------------------------
# This interpreter runs event commands. This class is used within the
# Game_System class and the Game_Event class.
#==============================================================================
class Interpreter
#--------------------------------------------------------------------------
# * Change Party Member
#--------------------------------------------------------------------------
def command_129
# Get actor
actor = $game_actors[@parameters[0]]
# If actor is valid
if actor != nil
# Branch with control
if @parameters[1] == 0
if @parameters[2] == 1
$game_actors[@parameters[0]].setup(@parameters[0])
end
$game_party.add_actor(@parameters[0])
if $game_temp.in_battle
$scene.setup_actor_command_windows
end
else
$game_party.remove_actor(@parameters[0])
if $game_temp.in_battle
$scene.setup_actor_command_windows
end
end
end
# Continue
return true
end
end
#==============================================================================
# ** Scene_Battle (part 1)
#------------------------------------------------------------------------------
# This class performs battle screen processing.
#==============================================================================
class Scene_Battle
# -----------------------------
def main
$game_temp.in_battle = true
$game_temp.battle_turn = 0
$game_temp.battle_event_flags.clear
$game_temp.battle_abort = false
$game_temp.battle_main_phase = false
$game_temp.battleback_name = $game_map.battleback_name
$game_temp.forcing_battler = nil
$game_system.battle_interpreter.setup(nil, 0)
@troop_id = $game_temp.battle_troop_id
$game_troop.setup(@troop_id)
@actor_command_windows = []
setup_actor_command_windows
@party_command_window = Window_PartyCommand.new
@help_window = Window_Help.new
@help_window.back_opacity = 160
@help_window.visible = false
@status_window = Window_BattleStatus.new
@message_window = Window_Message.new
@spriteset = Spriteset_Battle.new
@wait_count = 0
if $data_system.battle_transition == ""
Graphics.transition(20)
else
Graphics.transition(40, "Graphics/Transitions/" +
$data_system.battle_transition)
end
start_phase1
loop do
Graphics.update
Input.update
update
if $scene != self
break
end
end
$game_map.refresh
Graphics.freeze
for i in 0..$game_party.actors.size - 1
@actor_command_windows[i].dispose
end
@party_command_window.dispose
@help_window.dispose
@status_window.dispose
@message_window.dispose
if @skill_window != nil
@skill_window.dispose
end
if @item_window != nil
@item_window.dispose
end
if @result_window != nil
@result_window.dispose
end
@spriteset.dispose
if $scene.is_a?(Scene_Title)
Graphics.transition
Graphics.freeze
end
if $BTEST and not $scene.is_a?(Scene_Gameover)
$scene = nil
end
end
# -----------------------------
def update
if $game_system.battle_interpreter.running?
$game_system.battle_interpreter.update
if $game_temp.forcing_battler == nil
unless $game_system.battle_interpreter.running?
unless judge
setup_battle_event
end
end
if @phase != 5
@status_window.refresh
end
end
end
$game_system.update
$game_screen.update
if $game_system.timer_working and $game_system.timer == 0
$game_temp.battle_abort = true
end
@help_window.update
@party_command_window.update
for i in 0..$game_party.actors.size - 1
member = $game_party.actors[i]
if member.battle_commands != @actor_command_windows[i].commands
setup_actor_command_windows
end
if member != nil
@actor_command_windows[i].update
end
end
@status_window.update
@message_window.update
@spriteset.update
if $game_temp.transition_processing
$game_temp.transition_processing = false
if $game_temp.transition_name == ""
Graphics.transition(20)
else
Graphics.transition(40, "Graphics/Transitions/" +
$game_temp.transition_name)
end
end
if $game_temp.message_window_showing
return
end
if @spriteset.effect?
return
end
if $game_temp.gameover
$scene = Scene_Gameover.new
return
end
if $game_temp.to_title
$scene = Scene_Title.new
return
end
if $game_temp.battle_abort
$game_system.bgm_play($game_temp.map_bgm)
battle_end(1)
return
end
if @wait_count > 0
@wait_count -= 1
return
end
if $game_temp.forcing_battler == nil and
$game_system.battle_interpreter.running?
return
end
case @phase
when 1
update_phase1
when 2
update_phase2
when 3
update_phase3
when 4
update_phase4
when 5
update_phase5
end
end
# -----------------------------
def start_phase2
@phase = 2
@actor_index = -1
@active_battler = nil
@party_command_window.active = true
@party_command_window.visible = true
for i in 0..3
if $game_party.actors[i] != nil
@actor_command_windows[i].active = false
@actor_command_windows[i].visible = false
end
end
$game_temp.battle_main_phase = false
$game_party.clear_actions
unless $game_party.inputable?
start_phase4
end
end
# -----------------------------
def phase3_setup_command_window
@party_command_window.active = false
@party_command_window.visible = false
for i in 0..$game_party.actors.size - 1
if $game_party.actors[i] != nil
@actor_command_windows[i].active = false
@actor_command_windows[i].visible = false
end
end
@actor_command_windows[@actor_index].active = true
@actor_command_windows[@actor_index].visible = true
@actor_command_windows[@actor_index].index = 0
end
# -----------------------------
def update_phase3
if @enemy_arrow != nil
update_phase3_enemy_select
return
elsif @actor_arrow != nil
update_phase3_actor_select
return
elsif @skill_window != nil
update_phase3_skill_select
return
elsif @item_window != nil
update_phase3_item_select
return
end
for i in 0..$game_party.actors.size - 1
if @actor_command_windows[i].active
update_phase3_basic_command
return
end
end
end
# -----------------------------
def update_phase3_basic_command
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
phase3_prior_actor
return
end
if Input.trigger?(Input::C)
y = @active_battler.battle_commands
x = y[@actor_command_windows[@actor_index].index]
case x
when "Attack"
$game_system.se_play($data_system.decision_se)
@active_battler.current_action.kind = 0
@active_battler.current_action.basic = 0
start_enemy_select
when "Skill"
$game_system.se_play($data_system.decision_se)
@active_battler.current_action.kind = 1
start_skill_select
when "Defend"
$game_system.se_play($data_system.decision_se)
@active_battler.current_action.kind = 0
@active_battler.current_action.basic = 1
phase3_next_actor
when "Item"
$game_system.se_play($data_system.decision_se)
@active_battler.current_action.kind = 2
start_item_select
# when "Your Command Here"
# Place code for additional battle commands here.
#
# This is necessary, even if just giving a command a new name.
#
# Samples follow:
when "Slug"
$game_system.se_play($data_system.decision_se)
@active_battler.current_action.kind = 0
@active_battler.current_action.basic = 0
start_enemy_select
when "Magic"
$game_system.se_play($data_system.decision_se)
@active_battler.current_action.kind = 1
start_skill_select
when "Guard"
$game_system.se_play($data_system.decision_se)
@active_battler.current_action.kind = 0
@active_battler.current_action.basic = 1
phase3_next_actor
when "Use"
$game_system.se_play($data_system.decision_se)
@active_battler.current_action.kind = 2
start_item_select
# End of samples...
end
return
end
end
# -----------------------------
def start_enemy_select
@enemy_arrow = Arrow_Enemy.new(@spriteset.viewport1)
@enemy_arrow.help_window = @help_window
for i in 0..$game_party.actors.size - 1
if $game_party.actors[i] != nil
@actor_command_windows[i].active = false
@actor_command_windows[i].visible = false
end
end
end
# -----------------------------
def end_enemy_select
@enemy_arrow.dispose
@enemy_arrow = nil
y = @active_battler.battle_commands
x = y[@actor_command_windows[@actor_index].index]
if x == "Attack"
@actor_command_windows[@actor_index].active = true
@actor_command_windows[@actor_index].visible = true
@help_window.visible = false
end
end
# -----------------------------
def start_actor_select
@actor_arrow = Arrow_Actor.new(@spriteset.viewport2)
@actor_arrow.index = @actor_index
@actor_arrow.help_window = @help_window
for i in 0..$game_party.actors.size - 1
if $game_party.actors[i] != nil
@actor_command_windows[i].active = false
@actor_command_windows[i].visible = false
end
end
end
# -----------------------------
def start_skill_select
@skill_window = Window_Skill.new(@active_battler)
@skill_window.help_window = @help_window
for i in 0..$game_party.actors.size - 1
if $game_party.actors[i] != nil
@actor_command_windows[i].active = false
@actor_command_windows[i].visible = false
end
end
end
# -----------------------------
def end_skill_select
@skill_window.dispose
@skill_window = nil
@help_window.visible = false
@actor_command_windows[@actor_index].active = true
@actor_command_windows[@actor_index].visible = true
end
# -----------------------------
def start_item_select
@item_window = Window_Item.new
@item_window.help_window = @help_window
for i in 0..$game_party.actors.size - 1
if $game_party.actors[i] != nil
@actor_command_windows[i].active = false
@actor_command_windows[i].visible = false
end
end
end
# -----------------------------
def end_item_select
@item_window.dispose
@item_window = nil
@help_window.visible = false
@actor_command_windows[@actor_index].active = true
@actor_command_windows[@actor_index].visible = true
end
# -----------------------------
def start_phase4
@phase = 4
$game_temp.battle_turn += 1
for index in 0...$data_troops[@troop_id].pages.size
page = $data_troops[@troop_id].pages[index]
if page.span == 1
$game_temp.battle_event_flags[index] = false
end
end
@actor_index = -1
@active_battler = nil
@party_command_window.active = false
@party_command_window.visible = false
for i in 0..$game_party.actors.size - 1
if $game_party.actors[i] != nil
@actor_command_windows[i].active = false
@actor_command_windows[i].visible = false
end
end
$game_temp.battle_main_phase = true
for enemy in $game_troop.enemies
enemy.make_action
end
make_action_orders
@phase4_step = 1
end
# -----------------------------
def setup_actor_command_windows
if @actor_command_windows != []
for i in 0..@actor_command_windows.size - 1
@actor_command_windows[i].dispose
end
end
@actor_command_windows = []
for i in 0..$game_party.actors.size - 1
member = $game_party.actors[i]
if member != nil
@actor_command_windows[i] = Window_BattleCommand.new(member, 160)
@actor_command_windows[i].x = i * 160
@actor_command_windows[i].y = 160
@actor_command_windows[i].back_opacity = 160
@actor_command_windows[i].active = false
@actor_command_windows[i].visible = false
end
end
end
end
You can change the basic names of your Attack, Skill, Item, and like items in the SYSTEM database, but they are used globally throughout the game for all the actors. And I heard that RM2K3 allowed slight customization of names per actor, but it was a little limited. But this allows you to customize the individual names of every command for each actor.
RE: Individual Battle Commands - Taylor - 10-09-2011
RM2k3 allowed you to have varied number of commands of several types for each character or class.
I'm looking at this script and it seems not only poorly applied, but more limited than the RM2k3 version. Granted everything seems clunky to me when I see large swabs of default code pasted in.