+- Save-Point (https://www.save-point.org)
+-- Forum: Games Development (https://www.save-point.org/forum-4.html)
+--- Forum: Code Support (https://www.save-point.org/forum-20.html)
+--- Thread: Help with Computer controlled actors and AIBC (/thread-4723.html)
Help with Computer controlled actors and AIBC - ZeroSum - 07-06-2013
Hi there,
First off: Lovely forum you have here. The scripts and threads have inspired me to start my RPG maker hobby again.
Now for the reason I'm posting here. I've been putting together the scripts I want for my project, but I've run into a problem I can't seem to fix on my own.
I want to make use of 1 computer controlled ally. Found and tried to use two different scripts for that: Trickster's Ally AI and Claihm's Automatic Battle Actions.
They both work fine when using the normal ''Attack'', but as soon as the computer controlled char tries to use a skill I get a ''NoMethodError'' undefined method for 'skills' for nil:NilClass.
The script and line it refers to is part of the Advanced Individual Battle Commands by Trickster. (AIBC)
The part the system (error) reffers me to: (this is part of the Class Modification script from AIBC, full script listed bellow)
Code:
#--------------------------------------------------------------------------
# * 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? <<<<<< This line comes up in the error
# 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
I realise the problem comes from the AIBC script rewriting the way my Battle commands work. As I get the same error when using either Claimh'sor Trickster's script for computer controlled allies.
As I have very little script experience, I'd like to know if there is a solution to this while using the AIBC script, or if I should accept this as a compatibility issue and give up on using this combination of scripts. If it's the latter, does anyone have a suggestion to make use of a computer controlled ally script/event together with costumized Battle Commands? The comp contr. char only has to be able to use attack and 1 or 2 regular skills every now and then.
Not really sure which codes to link here for people to look at. I'll just paste the onesI think are relevant. I would preffer getting Claihm's system to work. Listed at bottom.
Sorry if I went overkill on information, thought I'd be as thorough is I could. Thank you!
#--------------------------------------------------------------------------
# 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 = {
3 => [1,2,3,4,13],
4 => [1,2,3,4,13],
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
Content Hidden
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:
Content Hidden
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 Modification: (part where the error occurs)
Content Hidden
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 and Save
Content Hidden
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
Automatic Battle Actions by Claimh
Content Hidden
Code:
#==============================================================================
# ** Automatic Battle Actions by Claimh
#------------------------------------------------------------------------------
# Automatic can only the character of specification act.
#------------------------------------------------------------------------------
# * You can modify the autorun feature of your actors in a [MAP EVENT] script
# command with the script call below:
# $game_actors[Actor ID].auto_play = true/nil
# true : Sets the actor to automatically perform battle actions
# nil : Cancels the automatic battle action feature
#
# NOTE by DERVVULFMAN:
# Formerly, the code was listed in the script as:
# $game_actors[Actor ID].auto_play = true/false
# ... but RGSS has a bug in itself that 'freezes' the system when turning
# switches to 'false' from map events. I checked it out and 'nil' works
# just fine.
#------------------------------------------------------------------------------
# * Changing automatic battle actions
# The PT_SW can be used to change an actor's list of defined actions from one
# set to another. If no battle pattern matches, it performs 'defend' actions.
#==============================================================================
#------------------------------------------------------------------------------
# ** Setting customization
#------------------------------------------------------------------------------
# Characters set to auto run (NPCs only, no player control at all)
# AUTO_PLAYER = [Actor ID, ...]
AUTO_PLAYER = [4]
# The HP Setting(%) that determines the Injured/Dying Condition
CRISIS = 25
#----------------------------------------------------------------------
# ** Automatic conduct pattern setting
# Here you may set the action patterns for your battlers. Behavior
# can be set to respond based on a 'rating' scale. You can set
# preferred conditions and is recommended to go no higher than 10.
#----------------------------------------------------------------------
# Constant name = [
# Rating (1 to 10),
# Priority (0: No Priority, 1: Ally injured, 2: Enemy dying),
# Action Type (0: Attack, 1: Defense, 2: Skill, 3: Item),
# Skill/Item (nil, or ID value used if not performing Attack or Defend),
# Target (0: Random, 1: Target w/ lowest HP, 2:Target w/ highest HP)
# ]
#
# In the following manner:
# [Rating, Priority, Action Type, Skill/Item ID, Target]
#---------Actor 1---------#
# Actor 1 / Pattern 0
AT_PATTERN_1_0 = [
[5, 0, 0, nil, 0], # Rating 5: No cond.: Normal attack: Random
[2, 0, 2, 57, 2], # Rating 2: No cond.: Skill: Cross Cut; Target w/ HP high
[1, 0, 1, nil, 0] # Rating 1: No cond.: Defense
]
# Actor 1 / Pattern 1
AT_PATTERN_1_1 = [
[2, 0, 0, nil, 0], # Rating 2: No cond.: Normal attack: Random
[5, 0, 2, nil, 0] # Rating 5: No cond.: Defense
]
#---------Actor 4---------#
# Actor 2 / Pattern 0
AT_PATTERN_2_0 = [
[5, 0, 0, nil, 0], # Rating 5: No cond.: Normal attack: Random
[1, 0, 0, nil, 1], # Rating 1: No cond.: Defense
[2, 0, 2, 7, 2] # Rating 2: No cond.: Skill: Fire; Target w/ highest HP
]
# Actor 2 / Pattern 1
AT_PATTERN_2_1 = [
[2, 0, 0, nil, 0], # Rating 2: No cond.: Normal attack: Random
[5, 0, 2, nil, 0] # Rating 5: No condition: Defense
]
#---------Actor 7---------#
# Actor 7 / Pattern 0
AT_PATTERN_7_0 = [
[5, 0, 0, nil, 1], # Rating 5: No cond.: Normal attack: Target w/ lowest HP
[2, 0, 1, nil, 0], # Rating 2: No cond.: Defense
[3, 1, 2, 1, 1] # Rating 3: Ally injured: Skill: Heal: Target w/ lowest HP
]
#---------Actor 8---------#
# Actor 8 / Pattern 0
AT_PATTERN_8_0 = [
[5, 0, 0, nil, 1], # Rating 5: No cond.: Normal attack: Target w/ lowest HP
[3, 2, 0, nil, 1], # Rating 2: Enemy dying : Normal attack: Target w/ lowest HP
[1, 0, 1, nil, 0] # Rating 1: No cond.: Defense
]
# Actor 8 / Pattern 1
AT_PATTERN_8_1 = [
[2, 0, 0, nil, 1], # Rating 2: No condition: Normal attack: Target w/ lowest HP
[5, 0, 2, nil, 0] # Rating 5: No condition: Defense
]
#-----------------------------------------------------------
# * Automatic conduct setting
# Setting of conduct pattern of each character
#-----------------------------------------------------------
# AUTO_MODE[Actor ID] = {
# PT_SW[Actor ID] => Action Pattern
# }
#
# This assigns a value in PT_SW to perform an action pattern. When the
# value is chosen, it plays out the pattern.
#
# Actor 1
AUTO_MODE[1] = {
0 => AT_PATTERN_1_0, # Actor 1: Pattern 0
1 => AT_PATTERN_1_1 # Actor 1: Pattern 1
}
# Actor 2
AUTO_MODE[4] = {
0 => AT_PATTERN_2_0, # Actor 2: Pattern 0
1 => AT_PATTERN_2_1 # Actor 2: Pattern 1
}
# Actor 7
AUTO_MODE[7] = {
0 => AT_PATTERN_7_0, # Actor 7: Pattern 0
1 => AT_PATTERN_7_1 # Actor 7: Pattern 1
}
# Actor 8
AUTO_MODE[8] = {
0 => AT_PATTERN_8_0, # Actor 8: Pattern 0
1 => AT_PATTERN_8_1 # Actor 8: Pattern 1
}
#------------------------------------------------------------------------------
end
#==============================================================================
# ** Scene_Battle
#==============================================================================
class Game_Actor < Game_Battler
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :auto_play # Automatic conduct
#--------------------------------------------------------------------------
# * Object Initialization
# actor_id : Actor ID
#--------------------------------------------------------------------------
alias init_auto_chara initialize
def initialize(actor_id)
init_auto_chara(actor_id)
@auto_play = AutoPlayer::AUTO_PLAYER.include?(actor_id)
end
#--------------------------------------------------------------------------
# * Determine if Command is Inputable
#--------------------------------------------------------------------------
def inputable?
ret = super
ret = false if @auto_play
return ret
end
end
#==============================================================================
# ** Scene_Battle
#==============================================================================
class Scene_Battle
#--------------------------------------------------------------------------
# * Frame Update (main phase step 2 : start action)
#--------------------------------------------------------------------------
alias update_phase4_step2_auto_player update_phase4_step2
def update_phase4_step2
# If battler set to 'Automatic'?
if @active_battler.is_a?(Game_Actor) and @active_battler.auto_play
make_auto_player_actions
end
update_phase4_step2_auto_player
end
#--------------------------------------------------------------------------
# * Make Auto Player Actions
#--------------------------------------------------------------------------
def make_auto_player_actions
# Obtain Conduct Pattern
action_motion = at_judge_auto_pattern?
return if action_motion.nil? # Return if no pattern
#
# A loop for the RETRY_TIME of an actor
for i in 0...AutoPlayer::RETRY_TIME
# Process conduct action
action = make_auto_play_pattern(action_motion)
# if no conduct pattern
if action.nil?
# Perform defend action
@active_battler.current_action.kind = 0
@active_battler.current_action.basic = 3
return
end
# Obtain the conduct action
ret = make_auto_play_motion(action)
return if ret # Return with the action
end
# Set the battler to 'defend' if no conduct selected
@active_battler.current_action.kind = 0
@active_battler.current_action.basic = 3
end
#--------------------------------------------------------------------------
# * Determine Automatic Action
#--------------------------------------------------------------------------
def at_judge_auto_pattern?
# If there is no pattern.
vari = $game_variables[AutoPlayer::PT_SW[@active_battler.id]]
if AutoPlayer::AUTO_MODE[@active_battler.id].nil? or vari.nil?
# Perform 'defend' action
@active_battler.current_action.kind = 0
@active_battler.current_action.basic = 3
return nil
end
action_motion = AutoPlayer::AUTO_MODE[@active_battler.id][vari]
# if there is no pattern
if action_motion.nil?
# Perform 'defend' action
@active_battler.current_action.kind = 0
@active_battler.current_action.basic = 3
return nil
end
return action_motion
end
#--------------------------------------------------------------------------
# * Determine if Fellow Party Member is Critical
#--------------------------------------------------------------------------
def at_judge_party_crisis?
for actor in $game_party.actors
# Dying state?
if actor.hp <= (actor.maxhp * AutoPlayer::CRISIS / 100)
return true
end
end
return false
end
#--------------------------------------------------------------------------
# * Determine if Fellow Troop Member is Critical
#--------------------------------------------------------------------------
def at_judge_enemy_crisis?
for enemy in $game_troop.enemies
# Dying state?
if enemy.hp <= (enemy.maxhp * AutoPlayer::CRISIS / 100)
return true
end
end
return false
end
#--------------------------------------------------------------------------
# * Make Auto Play Pattern
#--------------------------------------------------------------------------
def make_auto_play_pattern(action_pattern)
# Determine priority condition
pt_crisis = at_judge_party_crisis?
tr_crisis = at_judge_enemy_crisis?
# Rating total value
total_rating = 0
rating_box = []
for i in 0...action_pattern.size
rating_plus = 0
case action_pattern[i][1]
when 0 # No priority
when 1 # Friend injured
rating_plus = AutoPlayer::RATING_PLUS if pt_crisis
when 2 # Enemy injured
rating_plus = AutoPlayer::RATING_PLUS if tr_crisis
else
p "Conduct Pattern :: [Priority] Setting Error"
exit
end
rating_box[i] = action_pattern[i][0] + rating_plus
total_rating += rating_box[i]
end
# Select conduct with rating
rating_randam = rand(total_rating)
before_rating = 0
for i in 0...action_pattern.size
if rating_randam < (rating_box[i] + before_rating)
return action_pattern[i]
end
before_rating += rating_box[i]
end
return nil # Return if failed to perform action
end
#--------------------------------------------------------------------------
# * Make Auto Play Motion
#--------------------------------------------------------------------------
def make_auto_play_motion(action)
ret = true
case action[2]
when 0 # Normal Attack
@active_battler.current_action.kind = 0
@active_battler.current_action.basic = 0
ret = make_auto_play_target(action[4], 1)
when 1 # Defend
@active_battler.current_action.kind = 0
@active_battler.current_action.basic = 1
when 2 # Skill
@active_battler.current_action.kind = 1
@active_battler.current_action.skill_id = skill_id = action[3]
# Redo when you cannot use skill
return nil unless @active_battler.skill_can_use?(skill_id)
# Select Target
ret = make_auto_play_target(action[4], $data_skills[skill_id].scope)
when 3 # Item
@active_battler.current_action.kind = 2
@active_battler.current_action.item_id = item_id = action[3]
# Redo when you cannot use item
return nil if $game_party.item_number(item_id) == 0
# Select Target
ret = make_auto_play_target(action[4], $data_items[item_id].scope)
else
p "Conduct Pattern :: [Action Type] Setting Error"
exit
end
return ret
end
#--------------------------------------------------------------------------
# * Make Auto Play Target
# mode : mode of action
# scope : effect scope for action
#--------------------------------------------------------------------------
def make_auto_play_target(mode, scope)
case scope
when 0, 2, 4, 6, 7 # Multiple targets are chosen.
@active_battler.current_action.target_index = 0
else # Individual target is chosen.
# Target selection
case mode
when 0 # Chose random target
case scope
when 1 # Enemy
@active_battler.current_action.target_index = make_randum_target($game_troop.enemies)
when 3, 5 # Friend
@active_battler.current_action.target_index = make_randum_target($game_party.actors)
end
when 1 # Chose target with lowest HP
case scope
when 1 # Enemy
@active_battler.current_action.target_index = make_crisis_target($game_troop.enemies)
when 3 # Friend
@active_battler.current_action.target_index = make_crisis_target($game_party.actors)
when 5 # Friend(HP0)
target = make_dead_target
return nil if target.nil? # return if no decision made
@active_battler.current_action.target_index = target
end
when 2 # Chose target with highest HP
case scope
when 1 # Enemy
@active_battler.current_action.target_index = make_vigour_target($game_troop.enemies)
when 3 # Friend
@active_battler.current_action.target_index = make_vigour_target($game_party.actors)
when 5 # Enemy (HP0)
target = make_dead_target
return nil if target.nil? # return if no decision made
@active_battler.current_action.target_index = target
end
else
p "Conduct Pattern :: [Target] Setting Error"
exit
end
end
return true
end
#--------------------------------------------------------------------------
# * Make Random Target
#--------------------------------------------------------------------------
def make_randum_target(targets)
while 0
index = rand(targets.size)
if targets[index].exist?
return index
end
end
end
#--------------------------------------------------------------------------
# * Make Critical Target
#--------------------------------------------------------------------------
def make_crisis_target(targets)
target_hp = 1000000
target_index = make_randum_target(targets)
for index in 0...targets.size
if targets[index].hp < target_hp
target_hp = targets[index].hp
target_index = index
end
end
return target_index
end
#--------------------------------------------------------------------------
# * Make Vigourous Target
#--------------------------------------------------------------------------
def make_vigour_target(targets)
target_hp = 0
target_index = make_randum_target(targets)
for index in 0...targets.size
if targets[index].hp > target_hp
target_hp = targets[index].hp
target_index = index
end
end
return target_index
end
#--------------------------------------------------------------------------
# * Make Deat Target
#--------------------------------------------------------------------------
def make_dead_target
target_index = []
for index in 0...$game_party.actors.size
if $game_party.actors[index].dead?
target_index.push(index)
end
end
return nil if target_index.empty
return target_index[rand(target_index.size)]
end
end
RE: Help with Computer controlled actors and AIBC - MechanicalPen - 07-06-2013
I think I can see the probelm. When the AI selects a skill, it probably doesn't set the 'skills' bit because it didn't use the command list to pick it. try something like
RE: Help with Computer controlled actors and AIBC - ZeroSum - 07-06-2013
Thanks for the reply. I appreciate you thinking it over. I replaced the old code with yours but sadly it gave me the same error, same line.
Also did some testing in the Demo of AIBC, to eliminate any errors with other scripts my project uses or maybe some configure mistakes I made. But I get the same result. The AI character can use skills when the AI is turned off (regular manual skill selecting). But bugs out when the AI is turned on.
RE: Help with Computer controlled actors and AIBC - MechanicalPen - 07-07-2013
try flipping the order of your AI script and AIBC.
RE: Help with Computer controlled actors and AIBC - DerVVulfman - 07-07-2013
Yep... Just as MechanicalPen suggested, try changing the position of Trickster's AI and Battle Sction scripts. Sometimes script 'placement' makes a difference. At the same time, I do have to ask whether you are including the SDK (Standard Development Kit) that is in Trickster's demo within your game. It is pretty much a necessity with his later scripts, though you may have noticed that. I would 'assume' his scripts work together.
Oh, and I put the scripts you posted in the spoilers within their own [Code] bbcodes.
RE: Help with Computer controlled actors and AIBC - ZeroSum - 07-07-2013
Cheers for the feedback guys I've tried using different positions of the scripts before, but I tried it some more now with both AI scripts but no luck. Same error.
I did notice that the use of items (battle dmg items like bombs/vials etc) by the AI gives no issues. But when the Ai decides to use a skill (like a regular fire), it gives the error.
I am using the appropriate SDK, also the RSC and MACL from Tricksters Demo's.
RE: Help with Computer controlled actors and AIBC - MechanicalPen - 07-07-2013
Uh huh it is the "skill_can_use?" method messing up. You could always write a "skill_ai_can_use?" method that ignores all the individual battle command stuff, and use that method where ever the Ally AI script uses it.
EDIT: Or, you can just call Game_Battler's "skill_can_use?" If AIBC is BEFORE Ally AI, replace the [ skill_can_use? ] in the Ally AI script with [ trick_aibc_actor_skill_can_use? ]
RE: Help with Computer controlled actors and AIBC - ZeroSum - 07-07-2013
Hm, oke. I think understand the general idea of what you are suggesting. Adjusting the scripts to either replace or bypass the current skill_can_use? method within AIBC.
However I'm afraid my understanding of the ruby language isn't good enough yet to apply this. I wouldn't really know how to write a new method, or how to call Game_Battler's ''skill_can_use?'' like you suggested. Got any tips on how to approach this as a noobie? I dont mind learning.
RE: Help with Computer controlled actors and AIBC - MechanicalPen - 07-07-2013
it's super easy!
find (control+shift+F)
Code:
if $data_skills[skill_id].is_healing? && @actor.skill_can_use?(skill_id)
and replace it with
Code:
if $data_skills[skill_id].is_healing? && @actor.trick_aibc_actor_skill_can_use?(skill_id)
The naming is counter-intuitive. trick_aibc_actor_skill_can_use? is actually the old, unmodified skill_can_use? that was replaced with the one in AIBC. We call this aliasing.
RE: Help with Computer controlled actors and AIBC - DerVVulfman - 07-07-2013
You left an extra ] bracket in your replacement code before the 'if' (part of your [code] bbcode). I edited it out just now.
Posting this in case he tries pasting the replacement before the fix and was unaware about the ']' being present.