07-11-2012, 02:21 AM
Hello,
I am having a bit of a problem modifying the Advanced Individual Battle Commands script by Trickster. I want instead of the battle commands being set up by actor_id, I want them set up by class_id. So, if 2 different actors, have the same exact class id, they will be able to have the exact same battle commands. I've tried replacing "actor_id" to "class_id" in several places with no success. I wouldn't think it should be that difficult, but I can't figure it out. Could anyone point me in the right direction, or help me, I would be much appreciated. Thanks.
Here are the scripts that make up the Advanced Individual Battle Commands:
Setup:
Data Structure:
Windows:
Class Modifications
Load/Save Data:
I am having a bit of a problem modifying the Advanced Individual Battle Commands script by Trickster. I want instead of the battle commands being set up by actor_id, I want them set up by class_id. So, if 2 different actors, have the same exact class id, they will be able to have the exact same battle commands. I've tried replacing "actor_id" to "class_id" in several places with no success. I wouldn't think it should be that difficult, but I can't figure it out. Could anyone point me in the right direction, or help me, I would be much appreciated. Thanks.
Here are the scripts that make up the Advanced Individual Battle Commands:
Setup:
Code:
#==============================================================================
# ** Advanced Individual Battle Commands
#------------------------------------------------------------------------------
# Trickster (tricksterguy@hotmail.com)
# Version: 4.3 (Requires SDK I-IV)
# Date: 8/21/07
#==============================================================================
#--------------------------------------------------------------------------
# Begin SDK Log
#--------------------------------------------------------------------------
SDK.log('Advanced Individual Battle Commands', 'Trickster', 4.3, '8/21/07')
#--------------------------------------------------------------------------
# Begin SDK Requirement Check
#--------------------------------------------------------------------------
SDK.check_requirements(2.3, [1, 2, 3, 4])
#--------------------------------------------------------------------------
# Begin SDK Enabled Check
#--------------------------------------------------------------------------
if SDK.enabled?('Advanced Individual Battle Commands')
module Battle_Command_Setup
#--------------------------------------------------------------------------
# * Beginning Commands for Actors
# - syntax: actor_id => array of command ids
#--------------------------------------------------------------------------
Commands = {
1 => [1,2,3,4,5,12],
2 => [1,2,3,4,7,12],
7 => [1,2,3,4,8,12],
8 => [1,2,3,4,6,10,12]
}
#--------------------------------------------------------------------------
# * Default Commands (Attack, Skill, Item, and Defend)
#--------------------------------------------------------------------------
Commands.default = [1,2,3,4]
#--------------------------------------------------------------------------
# * Save Data
# - Set to True Run Project at least once then turn this option off
# if you want to encrypt your project (this will prevent a file not found
# error found if you encrypt your project w/o using this option)
# - Note: This option will create a file that can be loaded used load_data
# which can be read in encrypted projects (Commands.rxdata)
#--------------------------------------------------------------------------
Save_Data = false
#--------------------------------------------------------------------------
# * Do Not Touch...
#--------------------------------------------------------------------------
Line = %w( id name name_set kind type rating icon_name skill_id
common_event_id animation_id weapon_ids armor_ids skill_set skills ammo
ammo_refill class_level actor_level description help_text special_learn
hidden script parameters next_method )
end
#--------------------------------------------------------------------------
# End SDK Enabled Check
#--------------------------------------------------------------------------
end
Data Structure:
Code:
#--------------------------------------------------------------------------
# Begin SDK Enabled Check
#--------------------------------------------------------------------------
if SDK.enabled?('Advanced Individual Battle Commands')
class RPG::BattleCommand
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :id # The battle command's id
attr_accessor :name # The battle command's name
attr_accessor :name_set # The battle command's other names (aliases)
attr_accessor :kind # The battle command's kind
attr_accessor :type # The battle command's type
attr_accessor :rating # The battle commands's rating
attr_accessor :icon_name # The icon next to the battle command
attr_accessor :skill_id # The skill id for the battle command
attr_accessor :common_event_id # The common event the battle commmand executes
attr_accessor :animation_id # Animation played when used (custom)
attr_accessor :weapon_ids # Weapon ids that make the actor learn this
attr_accessor :armor_ids # Armor ids that make the actor learn this
attr_accessor :skill_set # The skill selectable set for this command
attr_accessor :skills # The skills the battle command contains
attr_accessor :ammo # Ammo Flag for points / item
attr_accessor :ammo_refill # Ammo Refill flags
attr_accessor :class_level # Level in which class learns this
attr_accessor :actor_level # Level in which actor learns this
attr_accessor :description # The description of the battle command
attr_accessor :help_text # Help window display text (custom)
attr_accessor :special_learn # Special conditions for learning this
attr_accessor :hidden # If the battle command is hidden
attr_accessor :script # The script activated when command is used
attr_accessor :parameters # Special Effects
attr_accessor :next_method # The next method that is executed
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(hash_args)
# Setup Default Parameters
@name_set = [[]]
@kind = 0
@type = 0
@rating = 10
@icon_name = ''
@skill_id = 0
@common_event_id = 0
@animation_id = 0
@weapon_ids = []
@armor_ids = []
@skill_set = ''
@skills = []
@ammo = {}
@ammo_refill = {}
@class_level = {}
@actor_level = {}
@description = ''
@help_text = ''
@special_learn = 'false'
@hidden = false
@script = ''
@parameters = {}
@next_method = 'phase3_next_actor'
# Run through each defined key
hash_args.each {|key, value| instance_eval("@#{key} = value")}
# Set the defaults for hashes
@class_level.default = 0
@actor_level.default = 0
end
end
class Game_BattleCommand
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :id
attr_accessor :disabled
attr_accessor :sp
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(id)
@id = id
@disabled = false
@sp = maxsp
end
#--------------------------------------------------------------------------
# * Name
#--------------------------------------------------------------------------
def name
return $data_commands[id].name
end
#--------------------------------------------------------------------------
# * Name Set
#--------------------------------------------------------------------------
def name_set
return $data_commands[id].name_set
end
#--------------------------------------------------------------------------
# * Kind
#--------------------------------------------------------------------------
def kind
return $data_commands[id].kind
end
#--------------------------------------------------------------------------
# * Type
#--------------------------------------------------------------------------
def type
return $data_commands[id].type
end
#--------------------------------------------------------------------------
# * Rating
#--------------------------------------------------------------------------
def rating
return $data_commands[id].rating
end
#--------------------------------------------------------------------------
# * Icon Name
#--------------------------------------------------------------------------
def icon_name
return $data_commands[id].icon_name
end
#--------------------------------------------------------------------------
# * Skill Id
#--------------------------------------------------------------------------
def skill_id
return $data_commands[id].skill_id
end
#--------------------------------------------------------------------------
# * Common Event Id
#--------------------------------------------------------------------------
def common_event_id
return $data_commands[id].common_event_id
end
#--------------------------------------------------------------------------
# * Animation Id
#--------------------------------------------------------------------------
def animation_id
return $data_commands[id].animation_id
end
#--------------------------------------------------------------------------
# * Weapon Ids
#--------------------------------------------------------------------------
def weapon_ids
return $data_commands[id].weapon_ids
end
#--------------------------------------------------------------------------
# * Armor Ids
#--------------------------------------------------------------------------
def armor_ids
return $data_commands[id].armor_ids
end
#--------------------------------------------------------------------------
# * Skill Set
#--------------------------------------------------------------------------
def skill_set
return $data_commands[id].skill_set
end
#--------------------------------------------------------------------------
# * Skills
#--------------------------------------------------------------------------
def skills
return $data_commands[id].skills
end
#--------------------------------------------------------------------------
# * Ammo
#--------------------------------------------------------------------------
def ammo
return $data_commands[id].ammo
end
#--------------------------------------------------------------------------
# * Ammo Refill
#--------------------------------------------------------------------------
def ammo_refill
return $data_commands[id].ammo_refill
end
#--------------------------------------------------------------------------
# * Class Level
#--------------------------------------------------------------------------
def class_level
return $data_commands[id].class_level
end
#--------------------------------------------------------------------------
# * Actor Level
#--------------------------------------------------------------------------
def actor_level
return $data_commands[id].actor_level
end
#--------------------------------------------------------------------------
# * Description
#--------------------------------------------------------------------------
def description
return $data_commands[id].description
end
#--------------------------------------------------------------------------
# * Help Text
#--------------------------------------------------------------------------
def help_text
return $data_commands[id].help_text
end
#--------------------------------------------------------------------------
# * Special Learn
#--------------------------------------------------------------------------
def special_learn
return $data_commands[id].special_learn
end
#--------------------------------------------------------------------------
# * Hidden
#--------------------------------------------------------------------------
def hidden
return $data_commands[id].hidden
end
#--------------------------------------------------------------------------
# * Script
#--------------------------------------------------------------------------
def script
return $data_commands[id].script
end
#--------------------------------------------------------------------------
# * Parameters
#--------------------------------------------------------------------------
def parameters
return $data_commands[id].parameters
end
#--------------------------------------------------------------------------
# * Next Method
#--------------------------------------------------------------------------
def next_method
return $data_commands[id].next_method
end
#--------------------------------------------------------------------------
# * Get Sp
#--------------------------------------------------------------------------
def sp
return ammo_type == 'sp' ? [[@sp, maxsp].min, 0].max : maxsp
end
#--------------------------------------------------------------------------
# * Change SP
#--------------------------------------------------------------------------
def sp=(sp)
@sp = [[sp, maxsp].min, 0].max
end
#--------------------------------------------------------------------------
# * Max Sp
#--------------------------------------------------------------------------
def maxsp
return self.ammo['sp'] if self.ammo.has_key?('sp')
return if not self.ammo.has_key?('item')
return $game_party.item_number(self.ammo['item'])
end
#--------------------------------------------------------------------------
# * Ammo Type
#--------------------------------------------------------------------------
def ammo_type
return self.ammo.keys.sort.reverse[0]
end
#--------------------------------------------------------------------------
# * Refill
#--------------------------------------------------------------------------
def refill(type, id = 0)
# Return if refrill type not specified
return if not self.ammo_refill.has_key?(type)
# Get Refill amount and percentage
amount, percentage = self.ammo_refill[type][0..1] if id == 0
amount, percentage = self.ammo_refill[type][id] if id != 0
# Set Heal Flag
heal = false
# Branch By Type
case type
when 'defend', 'wait', 'full_heal', 'level up', 'battle', 'skill', 'item'
# Set Heal Flag
heal = true
when 'turns'
# Get all Turns
turns = self.ammo_refill[type][2...self.ammo_refill[type].size]
# Set Heal Flag if turns are included
heal = turns.include?($game_temp.battle_turn)
when 'turn'
# Get A and B
a, b = self.ammo_refill[type][2..3]
# If Turn falls on the line a + bx
heal = $game_temp.battle_turn.linear?(a, b, false)
end
# Return if not healing or not sp ammot type
return if not heal || self.ammo_type == 'item'
# Increase Sp by amount
self.sp += amount + percentage * maxsp / 100
end
#--------------------------------------------------------------------------
# * Comparision Equals
#--------------------------------------------------------------------------
def ==(other)
return self.id == other.id
end
end
#==============================================================================
# ** Game_BattleCommands
#------------------------------------------------------------------------------
# This class handles the commands array. Refer to "$game_commands" for each
# instance of this class.
#==============================================================================
class Game_BattleCommands
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize
@data = []
end
#--------------------------------------------------------------------------
# * Get Command
# id : command ID
# actor : Game_Actor
# extra : RPG::(Armor/Skill/Weapon) Defaults to nil
#--------------------------------------------------------------------------
def [](id, actor, extra = nil)
# Return nil if Referencing an invalid object or 0 or negative index
return nil if id > $data_commands.size or id <= 0
# If Data For Id not Setup then Setup
@data[id] = {} if @data[id] == nil
# If Data for Actor not Setup then Setup
@data[id][actor] = {} if @data[id][actor] == nil
# If no extra and no Default
if extra == nil and @data[id][actor].default == nil
# Create Data
@data[id][actor].default = Game_BattleCommand.new(id)
end
# If Extra and data not setup
if extra != nil and @data[id][actor][extra] == nil
# Create Data
@data[id][actor][extra] = Game_BattleCommand.new(id)
end
# Return Data for Command Id, Actor and Extra
return @data[id][actor][extra]
end
end
#--------------------------------------------------------------------------
# End SDK Enabled Check
#--------------------------------------------------------------------------
end
Windows:
Code:
#--------------------------------------------------------------------------
# Begin SDK Enabled Check
#--------------------------------------------------------------------------
if SDK.enabled?('Advanced Individual Battle Commands')
class Window_BattleCommand < Window_SelectableCommand
#--------------------------------------------------------------------------
# * Maximum Commands shown per page
#--------------------------------------------------------------------------
Page = 4
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def initialize(width)
super(width, [nil])
# Initialize Help Window
@help_window = nil
# Setup Cursor Height
@cursor_height = 32
# Setup Actor
@actor = nil
# Setup Contents
self.contents = Bitmap.new(width - 32, height - 32)
end
#--------------------------------------------------------------------------
# * Set Actor
#--------------------------------------------------------------------------
def actor=(actor)
# Return if same actor and same commands
return if @actor == actor and @commands == actor.battle_commands
# Set Actor
@actor = actor
# Refresh
refresh
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
def refresh
# Return if actor is nil
return if @actor == nil
# Get Commands
@commands = @actor.battle_commands
# Sort Commands
@commands.sort_by! {|command| [command.rating, command.id]}
# If Height Changed
if self.contents.height != @commands.size * @cursor_height
# Dispose Contents
self.contents.dispose
# Setup Hieght
self.height = [Page, @commands.size].min * @cursor_height + 32
# Setup Contents
self.contents = Bitmap.new(width - 32, @commands.size * @cursor_height)
# Setup Y Coordinate
self.y = 288 - [Page, @commands.size].min * @cursor_height
end
# Clear Contents
self.contents.clear
# Get Item Max
@item_max = @commands.size
# Draw Item
@item_max.times {|i| draw_item(i)}
end
#--------------------------------------------------------------------------
# * Draw Item
#--------------------------------------------------------------------------
def draw_item(index)
# Set Color to Normal Color
self.contents.font.color = normal_color
# Set Font Size
self.contents.font.size = 22
# Get Command
command = @commands[index]
# Set Font Color if disabled
self.contents.font.color = command.disabled ? disabled_color : normal_color
# Set Font Color if out of ammo
self.contents.font.color = command.sp == 0 ? disabled_color : normal_color
# Setup Rectangle
rect = Rect.new(4, @cursor_height * index, self.contents.width - 16,
@cursor_height)
# Clears Contents at Rectangle
self.contents.fill_rect(rect, Color.new(0, 0, 0, 0))
# If Commands Icon Name is Defined
if not command.icon_name.empty?
# Get Bitmap
bitmap = RPG::Cache.icon(command.icon_name)
# Setup Opacity
opacity = self.contents.font.color == normal_color ? 255 : 128
# Call Block Transfer
self.contents.blt(rect.x, rect.y + 4, bitmap, Rect.new(0, 0, 24, 24), opacity)
# Increase X
rect.x += bitmap.width + 4
end
# Setup Name and Define New_Name
name, new_name = command.name, nil
# Initialize a hash
hash = {}
# Run Through Types Defined in Name_Set in Reverse Order
# Whatever is Defined First has the Highest Priority
command.name_set.of_index(0).each do |type|
# Setup Each Type
hash['actor'] = @actor.id
hash['class'] = @actor.class_id
hash['weapon'] = @actor.weapon_id
hash['shield'] = @actor.armor1_id
hash['helmet'] = @actor.armor2_id
hash['body'] = @actor.armor3_id
hash['accessory'] = @actor.armor4_id
hash['level'] = @actor.level
# Get Array from Array of Arrays
array = command.name_set.assoc(type)
# Get Name From Array of Arrays
new_name = array[1][hash[type]] if array != nil
# if new_name is not nil
if new_name != nil
# Set Name
name = new_name
# Break
break
end
end
# Draw Text
self.contents.draw_text(rect, name)
# Return if no ammo type
return if command.ammo_type == nil
# Set Color to Normal Color
self.contents.font.color = normal_color
# Set Font Size
self.contents.font.size = 16
# Setup Ammo Text
text = "#{command.sp} / #{command.maxsp}" if command.ammo_type == 'sp'
text = "#{command.sp}" if command.ammo_type == 'item'
# Draw Ammo Text
self.contents.draw_text(4, @cursor_height * index, self.contents.width - 8,
@cursor_height, text, 2)
end
#--------------------------------------------------------------------------
# * Update Help Window Text and Visibility
#--------------------------------------------------------------------------
def update_help
# Return if Help Window is nil
return if @help_window == nil
# Set Text To Description
@help_window.set_text(self.command.description, 1)
# Set To Visible if has text
@help_window.visible = !self.command.description.empty?
end
end
class Window_Skill
#--------------------------------------------------------------------------
# * Object Initialization
# actor : actor
#--------------------------------------------------------------------------
alias_method :trick_aibc_skill_initialize, :initialize
def initialize(actor)
# Get Current Command
@command = actor.current_action.command if $game_temp.in_battle
# Setup Data
@data = []
# The Usual
trick_aibc_skill_initialize(actor)
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
alias_method :trick_aibc_skill_refresh, :refresh
def refresh
# The Usual
trick_aibc_skill_refresh
# Return if additions are not needed
return if (not $game_temp.in_battle or
(@command.skills.empty? and @command.skill_set.empty?))
# Dispose the contents and reset
self.contents.dispose
# Reset Data
@data.clear
# If Skills Parameter is not used
if @command.skills.empty?
# Run Through Each Skill
@actor.skills.each do |skill_id|
# Get Corresponding RPG::Skill Object
skill = $data_skills[skill_id]
# Add Skill if skill is valid and skill_set evaluates to true
@data << skill if skill != nil and eval(@command.skill_set)
end
# If an Array of Skill Ids were given
elsif @command.skills.is_a?(Array)
# Add Each RPG::Skill Object onto data
@command.skills.each {|skill_id| @data << $data_skills[skill_id]}
# If an Condition String was given
elsif @command.skills.is_a?(String)
$data_skills.each_with_index do |skill, index|
# Next Index is 0 or Skill is nil
next if index == 0 or skill == nil
# Push RPG::Skill object onto data if @command.skills evaluates to true
@data << skill if eval(@command.skills)
end
# If a Hash Given (Advanced)
elsif @command.skills.is_a?(Hash)
# Call Each With Index
$data_skills.each_with_index do |skill, index|
# Next if Index is 0 or Skill id is not included in hash or skill is nil
next if index == 0 or not @command.skills.keys.include?(index) or skill == nil
# If an Array of Level, Actor Id Pairs Was Given
if @command.skills[index].is_a?(Array)
# Get Level and Actor Id
level, actor_id = @command.skills[index]
# Add to Data If Actor's level is at least the level and right actor id
@data << skill if @actor.level >= level and @actor.id == actor_id
# If A Condition String was Given
elsif @command.skills[index].is_a?(String)
# Add to Data if Condition evaluates to true
@data << skill if eval(@command.skills[index])
# If Level Was Given
elsif @command.skills[index].is_a?(Numeric)
# Add to Data if Level is at least the level given
@data << skill if @actor.level >= @command.skills[index]
end
end
end
# Sort All Items By Skill Id
@data.sort_by! {|skill| skill.id}
# Set Item Max
@item_max = @data.size
# If item count is not 0, make a bitmap and draw all items
if @item_max > 0
# Create Bitmap
self.contents = Bitmap.new(width - 32, row_max * 32)
# Draw Each Item
@item_max.times {|i| draw_item(i)}
end
end
end
class Window_Item
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias_method :trick_aibc_item_initialize, :initialize
def initialize
# Get Command
@command = $scene.active_battler.current_action.command if $game_temp.in_battle
# Setup Data
@data = []
# The Usual
trick_aibc_item_initialize
end
#--------------------------------------------------------------------------
# * Refresh
#--------------------------------------------------------------------------
alias_method :trick_aibc_item_refresh, :refresh
def refresh
# The Usual
trick_aibc_item_refresh
# Return if additions are not needed
return if not $game_temp.in_battle or @command.skill_set.empty?
# Dispose the contents and reset
self.contents.dispose
# Reset Data
@data.clear
# Run Through All Items
$data_items.each_with_index do |item, index|
# If has item and Item Set (Skill Set) evaluates to true
cond = $game_party.item_number(index) > 0 and eval(@command.skill_set)
# Add item is condition is true
@data << item if cond
end
# Get Item Count
@item_max = @data.size
# If item count is not 0, make a bit map and draw all items
if @item_max > 0
# Setup Bitmap
self.contents = Bitmap.new(width - 32, row_max * 32)
# Draw Each Item
@item_max.times {|i| draw_item(i)}
end
end
end
#--------------------------------------------------------------------------
# End SDK Enabled Check
#--------------------------------------------------------------------------
end
Class Modifications
Code:
#--------------------------------------------------------------------------
# Begin SDK Enabled Check
#--------------------------------------------------------------------------
if SDK.enabled?('Advanced Individual Battle Commands')
class Game_BattleAction
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :command #current battle command
#--------------------------------------------------------------------------
# * Clear
#--------------------------------------------------------------------------
alias_method :trick_aibc_battleaction_clear, :clear
def clear
# Reset command
@command = nil
# The Usual
trick_aibc_battleaction_clear
end
end
class Game_Actor
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :basic_commands
attr_reader :level_commands
attr_reader :equip_commands
attr_reader :learn_commands
attr_reader :special_commands
#--------------------------------------------------------------------------
# * Setup Battle Commands
#--------------------------------------------------------------------------
alias_method :trick_aibc_actor_setup, :setup
def setup(actor_id)
# The Usual
trick_aibc_actor_setup(actor_id)
# Initialize Types of Commands
@basic_commands = setup_commands(*Battle_Command_Setup::Commands[actor_id])
@level_commands = []
@equip_commands = []
@learn_commands = []
@special_commands = []
# Check for Initial Level Commands
check_level_commands
# Check for Initial Equip Commands
check_equip_commands
end
#--------------------------------------------------------------------------
# * Setup Commands
#--------------------------------------------------------------------------
def setup_commands(*commands)
commands.collect! {|command_id| $game_commands[command_id, self]}
return commands
end
#--------------------------------------------------------------------------
# * Get Battle Commands
#--------------------------------------------------------------------------
def battle_commands(hide_hidden = true)
# Get All Commands
commands = (@basic_commands + @level_commands + @equip_commands +
@learn_commands + @special_commands)
# If Hidden option is true then delete hidden commands
commands.delete_if {|command| command.hidden} if hide_hidden
return commands
end
#--------------------------------------------------------------------------
# * Check Level Commands
#--------------------------------------------------------------------------
def check_level_commands
# Clear Level commands
@level_commands.clear
# Run through all commands
$data_commands.each do |command|
# Next if nil
next if command == nil
# Setup Flag
flag = false
# Check if the command is not already included
@level_commands.each {|level| flag = true if level == command}
# Goto Next Command if already learned
next if flag
# Get Levels
class_lvl = command.class_level[@class_id]
actor_lvl = command.actor_level[@actor_id]
# If Level is Greater than or Equal to and defined then learn the command
if @level >= class_lvl and command.class_level.has_key?(@class_id)
@level_commands << $game_commands[command.id, self]
end
if @level >= actor_lvl and command.actor_level.has_key?(@actor_id)
@level_commands << $game_commands[command.id, self]
end
end
end
#--------------------------------------------------------------------------
# * Check Equip Commands
#--------------------------------------------------------------------------
def check_equip_commands
# Clear Equip Commands
@equip_commands.clear
# Run through all commands
$data_commands.each do |command|
# Next if nil
next if command == nil
# Setup Flag
flag = false
# Check if the command is not already included
@equip_commands.each {|equip| flag = true if equip == command}
# Goto Next Command if already learned
next if flag
# Run Through the Commands Learnable Weapons
command.weapon_ids.each do |weapon_id|
# If the actor is holding the weapon
if self.weapon_ids.include?(weapon_id)
# Get Corresponding RPG::Weapon object
weapon = $data_weapons[weapon_id]
# Learn the Command
@equip_commands << $game_commands[command.id, self, weapon]
end
end
# Check if the command is not already included
@equip_commands.each {|equip| flag = true if equip == command}
# Goto Next Command if already learned
next if flag
# Run Through The Commands Learnable Armors
command.armor_ids.each do |armor_id|
# If the actor has the armor equipped
if self.armor_ids.include?(armor_id)
# Get Corresponding RPG::Armor object
armor = $data_armors[armor_id]
# Learn the Command
@equip_commands << $game_commands[command.id, self, armor]
end
end
end
end
#--------------------------------------------------------------------------
# * Equip
#--------------------------------------------------------------------------
alias_method :trick_aibc_actor_equip, :equip
def equip(equip_type, id)
# The Usual
trick_aibc_actor_equip(equip_type, id)
# Recheck for Equip Commands
check_equip_commands
end
#--------------------------------------------------------------------------
# * Set Exp
#--------------------------------------------------------------------------
alias_method :trick_aibc_actor_exp=, :exp=
def exp=(exp)
# Get Current Level
last_level = @level
# The Usual
self.trick_aibc_actor_exp = exp
# Return if level hasn't changed
return if last_level == @level
# Recheck for Level Commands
check_level_commands
# Refill Command Level
refill_commands('level')
end
#--------------------------------------------------------------------------
# * Learn Command
#--------------------------------------------------------------------------
def learn_command(command_id)
# Return if Already Learned
@learn_commands.each {|learn| return if learn == command}
# Learn the Command
@learn_commands << $game_commands[command_id, self]
end
#--------------------------------------------------------------------------
# * Forget Command
#--------------------------------------------------------------------------
def forget_command(command_id)
# Run Through in reverse order
@learn_commands.reverse_each do |learn|
# If The Id of the command equals the number sent
if learn.id == command_id
# Delete the Command
@learn_commands.delete(learn)
# Command Deleted
return true
end
end
# Nothing Deleted
return false
end
#--------------------------------------------------------------------------
# * Learn Special Command
#--------------------------------------------------------------------------
def learn_special(command_id)
# Return if already learned
@special_commands.each {|special| return if command_id == special.id}
# Learn the Command
@special_commands << $game_commands[command_id, self]
end
#--------------------------------------------------------------------------
# * Forget Special Command
#--------------------------------------------------------------------------
def forget_special(command_id)
# Run Through in reverse order
@special_commands.reverse_each do |special|
# If the commands are the same
if special.id == command_id
# Then Forgot/Delete the command
@special_commands.delete(special)
# Command Deleted
return true
end
end
# Nothing Deleted
return false
end
#--------------------------------------------------------------------------
# * Skill Can Use?
#--------------------------------------------------------------------------
alias_method :trick_aibc_actor_skill_can_use?, :skill_can_use?
def skill_can_use?(skill_id)
# Get Flags
flag, flag2 = trick_aibc_actor_skill_can_use?(skill_id), false
# If in Scene_Battle
if $game_temp.in_battle
# If the Skills Parameter has been used
flag2 = !self.current_action.command.skills.empty?
# If the Skill Id Parameter equals the skill id sent
flag2 ||= self.current_action.command.skill_id == skill_id
# call Game_Battler skill_can_use?
flag2 &&= super
end
# Return flag
return flag || flag2
end
#--------------------------------------------------------------------------
# * Refill Commands
#--------------------------------------------------------------------------
def refill_commands(type, id = 0)
# Run Through each command and refill
battle_commands.each {|command| command.refill(type, id)}
end
#--------------------------------------------------------------------------
# * Recover All
#--------------------------------------------------------------------------
alias_method :trick_aibc_actor_recover_all, :recover_all
def recover_all
# The Usual
trick_aibc_actor_recover_all
# Refill Commands Full Heal
refill_commands('full_heal')
end
end
class Scene_Battle
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :active_battler
#--------------------------------------------------------------------------
# * Main Command Setup
#--------------------------------------------------------------------------
alias_method :trick_aibc_battle_main_window, :main_window
def main_window
# The Usual
trick_aibc_battle_main_window
# Dispose old Actor Command Window
@actor_command_window.dispose
# Create new Command Window
@actor_command_window = Window_BattleCommand.new(160)
@actor_command_window.back_opacity = 160
@actor_command_window.active = false
@actor_command_window.visible = false
end
#--------------------------------------------------------------------------
# * Start Phase 3
#--------------------------------------------------------------------------
alias_method :trick_aibc_battle_start_phase3, :start_phase3
def start_phase3
# Check Special Conditions for each actor
$game_party.actors.each do |actor|
# Run Through each command with the index
$data_commands.each_with_index do |command, id|
next if command == nil
# Evaluate Special Learn
flag = eval(command.special_learn)
# If Flag then learn command else forget the command
flag ? actor.learn_special(id) : actor.forget_special(id)
end
end
# The Usual
trick_aibc_battle_start_phase3
end
#--------------------------------------------------------------------------
# * Actor Command Window Setup
#--------------------------------------------------------------------------
alias_method(:trick_aibc_phase3_setup_command_window,
:phase3_setup_command_window)
def phase3_setup_command_window
# The Usual
trick_aibc_phase3_setup_command_window
# Set Actor
@actor_command_window.actor = @active_battler
end
#--------------------------------------------------------------------------
# * Phase 3 - Basic : Command Disabled? Test
#--------------------------------------------------------------------------
def phase3_basic_command_disabled?
# Loads Current Command
command = @actor_command_window.command
# Check if The Command is Disabled or ammo is 0
return command.disabled || (command.ammo_type != nil and command.sp == 0)
end
#--------------------------------------------------------------------------
# * Check Battle Commands
#--------------------------------------------------------------------------
def phase3_basic_command_input
# Play Decision SE
$game_system.se_play($data_system.decision_se)
# Loads Current Command
command = @actor_command_window.command
# Set Current Action Properties
@active_battler.current_action.kind = command.kind
@active_battler.current_action.basic = command.type
@active_battler.current_action.skill_id = command.skill_id
@active_battler.current_action.command = command
# If Skill Id Given and Next Method is Skill
if command.next_method.downcase == 'skill' and command.skill_id != 0
# Branch out According to the Command's Scope
case $data_skills[command.skill_id].scope
when 1
# Start Enemy Select if command's skill scope is one enemy
start_enemy_select
when 3,5
# Start Actor Select if command's skill scope is one actor
start_actor_select
else
# Go To Command Input for Next Actor
phase3_next_actor
end
else
# Evaluate Next Method Given
method(command.next_method).call
end
end
#-------------------------------------------------------------------------
# * End Enemy Selection
#-------------------------------------------------------------------------
alias_method :trick_aibc_battle_end_enemy_select, :end_enemy_select
def end_enemy_select
# The Usual
trick_aibc_battle_end_enemy_select
# Check If Command Has Next Method Start Enemy Select
flag = @actor_command_window.command.next_method == 'start_enemy_select'
# Enable/Disable actor command window depending on flag
@actor_command_window.active = flag
@actor_command_window.visible = flag
# Show/Hide help window depending on flag
@help_window.visible = !flag
end
#-------------------------------------------------------------------------
# * Start Making Actions
#-------------------------------------------------------------------------
alias_method :trick_aibc_battle_update_phase4_step2, :update_phase4_step2
def update_phase4_step2
# Set Actor (For Script Option)
actor = @active_battler
# Get Command
command = @active_battler.current_action.command
# If Battle is a Game_Actor
if actor.is_a?(Game_Actor)
# Refill command turns
actor.refill_commands('turns')
# Refill command turn
actor.refill_commands('turn')
end
# If Current Battler is a Game_Actor and Current Action's Command is Defined
if actor.is_a?(Game_Actor) and command != nil
# if sp type
if command.ammo_type == 'sp'
# If Not Enough Sp
if command.sp <= 0
# Clear Battlers Action
@active_battler.current_action.clear
# Reset Battle Command (No effects will happen)
command = nil
else
# Decrease Sp
command.sp -= 1
end
# Lose Item if item type
elsif command.ammo_type == 'item'
# Get Item Id
item_id = command.ammo['item']
# If party does not have item
if $game_party.item_number(item_id) == 0
# Clear Battlers Action
@active_battler.current_action.clear
# Reset Battle Command (No effects will happen)
command = nil
else
# Lose Item
$game_party.lose_item(item_id)
end
end
# If Command is not nil
if command != nil
# Execute Command Script
eval(command.script.to_s)
# Set Help Window Text if defined
@help_window.set_text(command.help_text, 1) if command.help_text != ''
# Set Animation
actor.animation_id = command.animation_id
end
end
# The Usual
trick_aibc_battle_update_phase4_step2
# If Common Event Id was given and command given
if command != nil and command.common_event_id != 0
# Set Common Event Id
@common_event_id = command.common_event_id
end
# Set Damaged Flag
damaged = @target_battlers.size == 0 ? true : false
# Run through target battlers
@target_battlers.each {|target| damage = true if target.damage != 'Miss'}
# Skip if not damaged
return unless damaged
# If Current Battler is a Game_Actor and Current Action's Command is Defined
if actor.is_a?(Game_Actor) and command != nil
# If used a skill
if actor.current_action.is_a_skill?
# Refill Command Skill
actor.refill_commands('skill', actor.current_action.skill_id)
# If used an item
elsif actor.current_action.is_a_item?
# Refill Command Item
actor.refill_commands('item', actor.current_action.item_id)
# If Defending
elsif actor.current_action.is_a_defend?
# Refill Command Defend
actor.refill_commands('defend')
# If Waiting
elsif actor.current_action.is_a_wait?
# Refill Command Wait
actor.refill_commands('wait')
end
end
end
#-------------------------------------------------------------------------
# * Battle End
#-------------------------------------------------------------------------
alias_method :trick_aibc_battle_battle_end, :battle_end
def battle_end(result)
# The Usual
trick_aibc_battle_battle_end(result)
# Refill Commands Each Actor Battle
$game_party.actors.each {|actor| actor.refill_commands('battle')}
end
end
#--------------------------------------------------------------------------
# End SDK Enabled Check
#--------------------------------------------------------------------------
end
Load/Save Data:
Code:
#--------------------------------------------------------------------------
# Begin SDK Enabled Check
#--------------------------------------------------------------------------
if SDK.enabled?('Advanced Individual Battle Commands')
class Scene_Title
#--------------------------------------------------------------------------
# * Main Database
#--------------------------------------------------------------------------
alias_method :trick_aibc_title_main_database, :main_database
def main_database
# The Usual
trick_aibc_title_main_database
# Load Level Data
load_command_data
end
#--------------------------------------------------------------------------
# * Main Database
#--------------------------------------------------------------------------
alias_method :trick_aibc_title_battletest_database, :battletest_database
def battletest_database
# The Usual
trick_aibc_title_battletest_database
# Load Level Data
load_command_data
end
#--------------------------------------------------------------------------
# * Battle Test
#--------------------------------------------------------------------------
def load_command_data
# Setup Load Commands Flag
load_commands = true
# Setup Data Commands
$data_commands = []
# Begin Exception Capture
begin
# Get Data from Text File
data = Trickster.load_data_from_txt("Data\\BattleCommands.rxdata",
Battle_Command_Setup::Line, [0,1,3], [], 2)
# Run Through data loaded
data.each_with_index do |command_data, index|
# Create RPG::BattleCommand Object sending loaded hash as an argument
$data_commands[index+1] = RPG::BattleCommand.new(command_data)
end
# File not found
rescue Errno::ENOENT
# project is encrypted or file not found
load_commands = false
end
# If Load Commands Flag
if load_commands
# IF Save Data Option
if Battle_Command_Setup::Save_Data
# Save a copy
save_data($data_commands, "Data/Commands.rxdata")
end
# Project Encrypted
else
# Load from Data Commands
$data_commands = load_data("Data/Commands.rxdata")
end
end
#--------------------------------------------------------------------------
# * Command: New Game
#--------------------------------------------------------------------------
alias_method :trick_aibc_commandnewgame_gamedata, :commandnewgame_gamedata
def commandnewgame_gamedata
# The Usual
trick_aibc_commandnewgame_gamedata
# Create Game_BattleCommands object
$game_commands = Game_BattleCommands.new
end
end
class Scene_Save
#--------------------------------------------------------------------------
# * Write Save Data
#--------------------------------------------------------------------------
alias_method :trick_aibc_save_write_data, :write_data
def write_data(file)
# The Usual
trick_aibc_save_write_data(file)
# Dump Commands
Marshal.dump($game_commands, file)
end
end
class Scene_Load
#--------------------------------------------------------------------------
# * Write Save Data
#--------------------------------------------------------------------------
alias_method :trick_aibc_load_read_data, :read_data
def read_data(file)
# The Usual
trick_aibc_load_read_data(file)
# Load Commands
$game_commands = Marshal.load(file)
end
end
#--------------------------------------------------------------------------
# End SDK Enabled Check
#--------------------------------------------------------------------------
end