[XP] Blizz ABS Smart Auto Targeting

Started by LiTTleDRAgo, February 25, 2011, 10:21:24 pm

Previous topic - Next topic

LiTTleDRAgo

February 25, 2011, 10:21:24 pm Last Edit: March 07, 2011, 07:08:30 pm by LiTTleDRAgo
Blizz ABS Smart Auto Targeting
Authors: LiTTleDRAgo
Version: 1.05
Type: Blizz-ABS Plugin
Key Term: Blizz-ABS Plugin



Introduction

It's just basically edit from Blizzard's Auto Targeting Script


Features


  • Remove selection screen when player is near an enemy

  • Automatically target nearest enemy at screen




Screenshots

---


Demo

---


Script

Spoiler: ShowHide

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

module LiTTleDRAgo

  TARGET_ANIMATION_ID = nil # 141
  TARGET_CHANGE_KEY   = Input::Key['W']
  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




Instructions

Put Below Blizz ABS


Compatibility

Needs Blizz ABS
Not Compatible with Blizzard Auto Targeting


Credits and Thanks


  • LiTTleDRAgo

  • Blizzard

  • Aqua




Author's Notes

Known Bugs :

1. Player can't select target when you want to use skill/item to party member,
The character will chose the target himself
2. Selection screen still appear on charged skill

Enjoy ~

Shalaren

February 25, 2011, 11:19:57 pm #1 Last Edit: February 25, 2011, 11:28:26 pm by shalaren metropolis
I like how in your note you besically say
"theres a bug that will totally screw it up! enjoy!"  :P
imma test it on my game and Ill edit with some feedback <3

Edit: mmkay its pretty sweet o:, altough, another way it should know how to target is the enemies your faced to,
lets say there is a monster up, and a monster down, it should target depending on what direction your facing, otherwise
battle will be real hard against more then 1 enemy. targeting the enemies your faced to is the only thing I could find missing,

but in general i find it real helpful, lvl up*

LiTTleDRAgo

oh, you want to be like that?
there you go, as requested

Shalaren

 :up: totally using this :B

another suggestion though, now that u did the facing target it works really nice, except it might target far enemies when there is enemies real close to you from that same direction, the suggestion is to target to closest enemy from that direction.

Zexion

February 26, 2011, 01:49:32 pm #4 Last Edit: February 26, 2011, 01:56:46 pm by Zexion
I tried this becuase i need this too, but if you face up or down the thing goes psycho!
EDIT: Actually, if you face in a direction that there is no enemy then it goes psycho!

Aqua

Maybe you should have to check a skill's/item's scope to do the targeting?
That way things can be used on allies too xD

Shalaren

Quote from: Zexion on February 26, 2011, 01:49:32 pm
I tried this becuase i need this too, but if you face up or down the thing goes psycho!
EDIT: Actually, if you face in a direction that there is no enemy then it goes psycho!


you mean ur facing down and it attacks the monster up? thats because there is no monster downwards then o-o.
thats the idea of the script lol.

Zexion

February 26, 2011, 03:12:42 pm #7 Last Edit: February 26, 2011, 03:57:06 pm by Zexion
no i mean if im facing away from an enemy the target thing starts shifting through all the enemys on the screen untill i face an enemy. I'm gonna fix it by only making it target when u press the button, and press another to take it off, but yeah its a bug i think let me make a vid.

Edit: Actually, it wont let me upload it for some reason the page wont load, so here is a gif.
Spoiler: ShowHide

That is exactly what happens when i'm not facing enemies.

Shalaren

Quote from: Zexion on February 26, 2011, 03:12:42 pm
no i mean if im facing away from an enemy the target thing starts shifting through all the enemys on the screen untill i face an enemy. I'm gonna fix it by only making it target when u press the button, and press another to take it off, but yeah its a bug i think let me make a vid.
you should o-o, I havent got into that bug yet.

Zexion


Shalaren

Wieeerd, doesn thappen to me o-o

LiTTleDRAgo

Quote from: Zexion on February 26, 2011, 03:12:42 pm
no i mean if im facing away from an enemy the target thing starts shifting through all the enemys on the screen untill i face an enemy. I'm gonna fix it by only making it target when u press the button, and press another to take it off, but yeah its a bug i think let me make a vid.

Edit: Actually, it wont let me upload it for some reason the page wont load, so here is a gif.
Spoiler: ShowHide

That is exactly what happens when i'm not facing enemies.


fixed

Zexion

hmm your fix is like the proper way, but i did a simple edit and it fixed it :P I dunno if it will cause more errors for someone else, but doesn't cause any for me.

changed this:
Spoiler: ShowHide
 if  (target_dir != nil && $game_player.direction != target_dir)
        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

to this:
Spoiler: ShowHide
 if  (target_dir = nil && $game_player.direction != target_dir)
        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

note the simple != nil to = nil change.
I honestly was just messing around and it worked :P

Wizered67

Actually, in conditionals you use == and not =.

LiTTleDRAgo

if you didn't want auto change target that much just simply delete this line

Quotealias initer_update update
  def update
    initer_update
    changetarget
  end


update 1.03, added option to remove auto change target

Shalaren

Quote from: shalaren metropolis on February 26, 2011, 10:12:12 am
it might target far enemies when there is enemies real close to you from that same direction, the suggestion is to target the closest enemy from that direction.

Zexion

the thing is, if i took that one out, then when enemies die the targeter would just stay there, and not move at all, but it's ok I managed to get it working with pressing a button turns it on, pressing it again switches the targets, and pressing another button removes it.

LiTTleDRAgo

Quote from: shalaren metropolis on February 27, 2011, 02:57:28 am
Quote from: shalaren metropolis on February 26, 2011, 10:12:12 am
it might target far enemies when there is enemies real close to you from that same direction, the suggestion is to target the closest enemy from that direction.



unfortunately, I still didn't know how to do that (to check nearest enemies),
could someone help?

Quote from: Zexion on February 27, 2011, 05:15:13 am
the thing is, if i took that one out, then when enemies die the targeter would just stay there, and not move at all, but it's ok I managed to get it working with pressing a button turns it on, pressing it again switches the targets, and pressing another button removes it.


is that so?
I'll check it later at home

Aqua

Quote from: LiTTleDRAgo on February 27, 2011, 07:51:35 pm
Quote from: shalaren metropolis on February 27, 2011, 02:57:28 am
Quote from: shalaren metropolis on February 26, 2011, 10:12:12 am
it might target far enemies when there is enemies real close to you from that same direction, the suggestion is to target the closest enemy from that direction.



unfortunately, I still didn't know how to do that (to check nearest enemies),
could someone help?


Use the distance formula to figure out which is the closest.
In coding terms... it's...

VAR = Math.hypot((x1 - x2).abs, (y1 - y2).abs)


LiTTleDRAgo

Quote from: shalaren metropolis on February 27, 2011, 02:57:28 am
Quote from: shalaren metropolis on February 26, 2011, 10:12:12 am
it might target far enemies when there is enemies real close to you from that same direction, the suggestion is to target the closest enemy from that direction.



done

Quote from: Aqua on February 27, 2011, 08:07:50 pm
Use the distance formula to figure out which is the closest.
In coding terms... it's...

VAR = Math.hypot((x1 - x2).abs, (y1 - y2).abs)




thanks Aqua
I'll put you in the credit