[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

Shalaren


Zexion

okay the new version is so awesome! but now i get an error during the fight. for some reason it only happens when 1 enemy is alive, and I'm facing up.
Script 'Auto Target' line 178: NoMethodError occurred.
undefined method x for nil:NilClass


I copied exactly whats in the script, no mods were made to this one yet.

Shalaren

Quote from: Zexion on February 28, 2011, 07:29:25 pm
okay the new version is so awesome! but now i get an error during the fight. for some reason it only happens when 1 enemy is alive, and I'm facing up.
Script 'Auto Target' line 178: NoMethodError occurred.
undefined method x for nil:NilClass


I copied exactly whats in the script, no mods were made to this one yet.


Yep I just got that too, its like it gets confused for its target and crashes.

anyway BUG REPORT!

LiTTleDRAgo


Shalaren

Flaw!
if u use charge for skills, when the charge stops, it puts the targetting screen S:.

LiTTleDRAgo

could you upload a demo? since I didn't use charged attack/charged skill

Shalaren

uploading is not something i can do in this computer ><"
besides it takes longer uploading a demo then actually putting charge on a skill.

LiTTleDRAgo

March 01, 2011, 02:28:24 am #27 Last Edit: March 01, 2011, 03:00:10 am by LiTTleDRAgo
I didn't understand how to make charged skill because it's seem "weird" in my game
empty project with your blizz abs configuration, auto target script, and graphic needed will do


edit : nevermind, I think I got it

Zexion

oh as long as this one is fixed I don't care :P I don't use charge anyway lol

Shalaren

Quote from: LiTTleDRAgo on March 01, 2011, 02:28:24 am
I didn't understand how to make charged skill because it's seem "weird" in my game
empty project with your blizz abs configuration, auto target script, and graphic needed will do


edit : nevermind, I think I got it

so did you get charge fixed? o:

LiTTleDRAgo

Quote from: Shalaren on March 06, 2011, 04:11:28 pm
so did you get charge fixed? o:


not yet


edit : I don't think I'll be able to fix that, because it seemed create a massive bug in blizz abs if I editing charged function, sorry

Shalaren

S: then add
"Not Compatible with Babs Charging"

LiTTleDRAgo

yeah, I already add the note in author's notes yesterday

Aqua

When a skill is forced to be used as part of a combo, the selection window comes up. D:

Tazero

Other than the 'Nearest enemy thing' Wondering could you maybe assign a button to DE target and enemy or turn targeting back on? like this http://www.youtube.com/watch?v=dMb4rmKLO78 Skip to about 20 seconds in :3

And a switch target like Lock on to next nearest but not the one I just targeted sorta thing?

I mean that would be amazing and I would use this hands down :)

I'll prolly use it anyways but thats just a suggestion ;D


If you were a fish...

Felix0

Quote from: Aqua on March 13, 2011, 04:51:57 pm
When a skill is forced to be used as part of a combo, the selection window comes up. D:

Yes I am getting this problem, Although I am using it as a common event, and a combo.
Really would love for this to be fixed <3

Kiwa

Just for future reference for anyone using this script....or someone wants to fix the bug.

Here are the symptoms.

1. Target is locked on something and my damn fire ball is shooting things off in the distance im NOT targeting!!!
2. I have to spam the living crap out of my HotKey to get the damn spell to work!!!


I shared your despair until just a moment ago when i decided it was time to look into my games targeting system.

here is the problem....
Your skill is set "Freeze on Charge" or "Move on Charge" or "Trigger after Charge"

If you set your skill to "No Charge" the world is beautiful.

**further note that may help if someone has the know how and desire to fix this. if the skill is set to "Charge" and the charge is short (under 40 frames or so) it can be spammed like MAD and it will/may shoot the fireball. if the charge is 40-80 frames (2 seconds or so?)..  i had no such luck spamming the key like a champion.

Sylphe

May 03, 2015, 01:15:49 pm #37 Last Edit: May 03, 2015, 05:25:22 pm by Sylphe
Hey ... I didn't know where to post that ... I thought it was in script troubleshooting but Blizzard rules said "If there is a topic related to your script in script database then post in this topic"  so here I am ...

I think it is a very good script and I decided to use it in my game, but I don't have good animation to show a "target" for now so ... I decided to add a little something :
show the targeting graphic with a picture. And it works, but I just have one issue.

When I teleport my hero from a map to another, then an automatic event run but ...  the graphic is still here ! And it targets an empty place I don't know why xD (even when I put wait at the first line of the event).

I think it is not really related to this script in particular but to every scripts that use pictures, I'm not a very good scripter I think so here is the part I changed ( "labelled" with Stanley's add) :

Spoiler: ShowHide


#==============================================================================
# Sprite_Targeter
#==============================================================================

class Sprite_Targeter < RPG::Sprite
 
  attr_accessor :character
 
  def initialize(viewport, character = nil)
    super(viewport)
    # stanley's add : if else
    if LiTTleDRAgo::TARGET_ANIMATION_ID == nil
      self.bitmap = RPG::Cache.picture("Curseur ennemi") # the name of the picture
      self.src_rect = Rect.new(0, 0, 32, 32)
      self.visible = false
    else
      self.bitmap = Bitmap.new(1, 1)
    end
    @character = character
    update
  end
 
  # STANLEY'S ADD : method dispose
  def dispose
    if self.bitmap != nil
      self.bitmap.dispose
    end
    self.visible = false
    super
  end
 
  def update
    @character = $BlizzABS.autotarget
    if @character == nil
      @loop_animation_id = 0
      loop_animation(nil)
      return
    end
    super
    # stanley's add : if
    if LiTTleDRAgo::TARGET_ANIMATION_ID == nil
      self.visible = true
      self.src_rect.x += 32 if Graphics.frame_count % 5 == 0
      self.src_rect.x %= 128
      self.src_rect.y = 0 # or 32 for blue one
      if $BlizzABS.autotarget == nil 
        self.visible = false
      else
        self.x = @character.screen_x - 16
        self.y = @character.screen_y - 23
        self.z = @character.screen_z(0)
      end
     
    elsif @loop_animation_id == 0
      @loop_animation_id = LiTTleDRAgo::TARGET_ANIMATION_ID
      loop_animation($data_animations[@loop_animation_id])
     
      self.x = @character.screen_x
      self.y = @character.screen_y
      self.z = @character.screen_z(0)
    end
 
  end
 
end

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

class Spriteset_Map
 
  alias init_autotarget_later initialize
  def initialize
    #Stanley's add : we check in the class Sprite_Targeter if it is set to nil
   # if LiTTleDRAgo::TARGET_ANIMATION_ID != nil
     @autotarget = Sprite_Targeter.new(@viewport1)
  # end
   $game_temp.target_cursor_sprite = @target_cursor_sprite
    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


Also I tried to see if it entered in the Sprite_Targeter "dispose" method when changing map, and yes. So I added this "visible = false" in the dispose method, but it doesn't changed anything :/

EDIT : Waiting for a better idea I made a global variable that I set to false to temporarily desactivate the cursor
blindly follow his heart can lead to the loss

Sylphe, descendant of Zoldik Family.
Quote from: TedBearTRY KEEP UP