[BABS] autotarget with force action

Started by sasofrass, April 16, 2012, 03:12:43 am

Previous topic - Next topic

sasofrass

I am using the autotargeting script by LiTTleDRAgo:

Spoiler: ShowHide
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Blizz ABS Smart Auto Targeting                                                 
# Version: 1.05
# Author : LiTTleDRAgo
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=

module LiTTleDRAgo

  TARGET_ANIMATION_ID = nil # 141
  TARGET_CHANGE_KEY   = Input::Key['U']
  AUTO_CHANGE_TARGET  = true


end


#==============================================================================
# BlizzABS::Controls
#==============================================================================

class BlizzABS::Controls
 
  alias update_attack_autotarget_later update_attack
  def update_attack

    if $BlizzABS.autotarget == nil
        targets = $game_map.battlers.find_all {|b| b.valid? && b.in_screen?}
        $BlizzABS.autotarget = targets[0] if targets.size > 0
    elsif Input.repeat?(LiTTleDRAgo::TARGET_CHANGE_KEY) 
      targets = $game_map.battlers.find_all {|b| b.valid? && b.in_screen?}
      index = targets.index($BlizzABS.autotarget)
      $BlizzABS.autotarget = targets[(index + 1) % targets.size] if index != nil
    end
    if $BlizzABS.autotarget != nil && (!$BlizzABS.autotarget.in_screen? ||
        !$BlizzABS.autotarget.valid?)
      $BlizzABS.autotarget = nil
    end
    return update_attack_autotarget_later
  end
 
  alias update_skill_autotarget_later update_skill
  def update_skill
    result = update_skill_autotarget_later
    if result && $BlizzABS.autotarget != nil && $game_temp.select_data != nil
      characters = []
      $game_temp.select_data[3].each {|s| characters.push(s.character)}
      if characters.include?($BlizzABS.autotarget)
        $game_player.ai.target = $BlizzABS.autotarget
        $game_player.use_skill($game_temp.select_data[0])
      else
        $BlizzABS.autotarget = nil
        update_skill
      end
      $game_temp.select_data = nil
    end
    return result
  end
 
  alias update_item_autotarget_later update_item
  def update_item
    result = update_item_autotarget_later
    if result && $BlizzABS.autotarget != nil && $game_temp.select_data != nil
      characters = []
      $game_temp.select_data[3].each {|s| characters.push(s.character)}
      if characters.include?($BlizzABS.autotarget)
        $game_player.ai.target = $BlizzABS.autotarget
        $game_player.use_item($game_temp.select_data[0])
      else
        $BlizzABS.autotarget = nil
        update_item
      end
      $game_temp.select_data = nil
    end
    return result
  end

end

#==============================================================================
# BlizzABS::Processor
#==============================================================================

class BlizzABS::Processor
 
  attr_accessor :autotarget
 
end

#==============================================================================
# Spriteset_Map
#==============================================================================

class Sprite_Targeter < RPG::Sprite
 
  attr_accessor :character
 
  def initialize(viewport, character = nil)
    super(viewport)
    self.bitmap = Bitmap.new(1, 1)
    @character = character
    update
  end
 
  def update
    @character = $BlizzABS.autotarget
    if @character == nil
      @loop_animation_id = 0
      loop_animation(nil)
      return
    end
    super
    if @loop_animation_id == 0
      @loop_animation_id = LiTTleDRAgo::TARGET_ANIMATION_ID
      loop_animation($data_animations[@loop_animation_id])
    end
    self.x = @character.screen_x
    self.y = @character.screen_y
    self.z = @character.screen_z(0)
  end
 
end

#==============================================================================
# Spriteset_Map
#==============================================================================

class Spriteset_Map
 
  alias init_autotarget_later initialize
  def initialize
    if LiTTleDRAgo::TARGET_ANIMATION_ID != nil
     @autotarget = Sprite_Targeter.new(@viewport1)
    end
    init_autotarget_later
  end
 
  alias update_autotarget_later update
  def update
    @autotarget.update if @autotarget != nil
    update_autotarget_later
  end
 
  alias dispose_autotarget_later dispose
  def dispose
    if @autotarget != nil
      @autotarget.dispose
      @autotarget = nil
    end
    dispose_autotarget_later
  end
 
end

#==============================================================================
# Scene_Map
#==============================================================================

class Scene_Map
 
  alias initer_update update
  def update
    initer_update
    changetarget if LiTTleDRAgo::AUTO_CHANGE_TARGET
  end

    def changetarget
    if $BlizzABS.autotarget != nil
      @char, char = $BlizzABS.autotarget, $game_player
      sx, sy = @char.x - $game_player.x, @char.y - $game_player.y
      return if sx == 0 and sy == 0
      dir = sx.abs > sy.abs ? sx > 0 ? 6 : 4 : sy > 0 ? 2 : 8
      if  (dir != nil && $game_player.direction != dir)
        targets, pix = $game_map.battlers.find_all {|b| b.valid? && b.in_screen?},
                       $BlizzABS.pixel
        targets.sort! {|a, b|
            Math.hypot(char.x / pix - a.x / pix, char.y / pix - a.y / pix) <=>
            Math.hypot(char.x / pix - b.x / pix, char.y / pix - b.y / pix)}
        if targets.size > 0
          sx, sy = targets[0].x - $game_player.x, targets[0].y - $game_player.y
          return if sx == 0 and sy == 0
          dir = sx.abs > sy.abs ? sx > 0 ? 6 : 4 : sy > 0 ? 2 : 8 
          if !(($game_player.direction == 6 && dir == 4) ||
               ($game_player.direction == 4 && dir == 6) ||
               ($game_player.direction == 2 && dir == 8) ||
               ($game_player.direction == 8 && dir == 2))
            $BlizzABS.autotarget = targets[0]
          end
        end
      end
    end
  end
end

$BlizzABS = BlizzABS::Processor.new


and I have a question about it. I am using this command:

$BlizzABS.actor_force_action(PARTY, ENEMIES, TROOP, SKILL, 50)


and the ability is set to do an AE attack of 4 spaces around the party members. It works, but the autotarget script isn't picking that up.

Is there anything I can change to do that?