Target Any Add-On for Yanfly's Target Manager
by Racheal
Introduction
This is a Add-On for Yanfly's Target Manager which allows you to set skills that can target friend OR foe.
Features
- Press Up/Down to switch between Ally and Enemy targeting for select skills.
- Targeting defaults to whatever the scope in the editor is set to.
- Works with Attack and Items too!
How to Use
- Insert in the materials section of the script editor.
- Insert <targets: any> in the notetag of any skill or item you want to be able to select a single ally or enemy for.
- Insert <targets: any all> in the notetag of any skill or item you want to be able to select all allies or all enemies for.
- Make sure to set the scope in the editor to set which group it defaults to selecting first!
Script
#==============================================================================# Target Any Add-On for Yanfly's Target Manager# by: Racheal# Version 1.0# Created: 22/11/2013#==============================================================================# Allows for skills that can target enemy or ally.#==============================================================================# Instructions:# * Insert in the Materials section under Target Manager## -----------------------------------------------------------------------------# Skill / Item Notetags - These notetags go in the skills notebox in the database.# -----------------------------------------------------------------------------# <targets: any># Sets the targeting scope to hit either enemy or ally## <targets: any all># Sets the targeting scope to hit either all enemies or all allies#==============================================================================# ▼ Compatibility# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=# This script is made strictly for RPG Maker VX Ace. It is highly unlikely that# it will run with RPG Maker VX without adjusting.## This scripts requires Yanfly Ace Battle Engine and Yanfly Target Manager.# It is highly unlikely to without both of those scripts.#==============================================================================#==============================================================================# DataManager#==============================================================================module DataManager #-------------------------------------------------------------------------- # alias method: load_database #-------------------------------------------------------------------------- class <<self; alias load_database_any_target load_database; end def self.load_database load_database_any_target load_notetags_any_target end #-------------------------------------------------------------------------- # new method: load_notetags_target #-------------------------------------------------------------------------- def self.load_notetags_any_target groups = [$data_skills, $data_items] for group in groups for obj in group next if obj.nil? obj.load_notetags_any_target end end end end # DataManager#==============================================================================# RPG::UsableItem#==============================================================================class RPG::UsableItem < RPG::BaseItem #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_reader :default_for_friend #-------------------------------------------------------------------------- # common cache: load_notetags_any_target #-------------------------------------------------------------------------- def load_notetags_any_target @default_for_friend = for_friend? self.note.split(/[\r\n]+/).each { |line| case line when YEA::REGEXP::USABLEITEM::TARGETS case $1 when /ANY ALL/i @scope = :target_any_all when /ANY/i @scope = :target_any end end } # self.note.split #--- end #-------------------------------------------------------------------------- # alias method: for_opponent? #-------------------------------------------------------------------------- alias rpg_usableitem_for_opponent_target_any for_opponent? def for_opponent? return true if @scope == :target_any_all return true if @scope == :target_any return rpg_usableitem_for_opponent_target_any end #-------------------------------------------------------------------------- # alias method: for_friend? #-------------------------------------------------------------------------- alias rpg_usableitem_for_friend_target_any for_friend? def for_friend? return true if @scope == :target_any_all return true if @scope == :target_any return rpg_usableitem_for_friend_target_any end #-------------------------------------------------------------------------- # alias method: for_all? #-------------------------------------------------------------------------- alias rpg_usableitem_for_all_target_any for_all? def for_all? return true if @scope == :target_any_all rpg_usableitem_for_all_target_any end #-------------------------------------------------------------------------- # alias method: need_selection? #-------------------------------------------------------------------------- alias rpg_usableitem_need_selection_target_any need_selection? def need_selection? return true if @scope == :target_any return rpg_usableitem_need_selection_target_any end #-------------------------------------------------------------------------- # new method: for_any_all? #-------------------------------------------------------------------------- def for_any_all? return @scope == :target_any_all end #-------------------------------------------------------------------------- # new method: for_any? #-------------------------------------------------------------------------- def for_any? return @scope == :target_any endend#==============================================================================# Window_BattleHelp#==============================================================================class Window_BattleHelp < Window_Help #-------------------------------------------------------------------------- # alias method: refresh_special_case #-------------------------------------------------------------------------- alias window_battlehelp_refresh_special_case_target_any refresh_special_case def refresh_special_case(battler) if $game_temp.battle_aid.for_any_all? if BattleManager.actor.input.ally text = YEA::BATTLE::HELP_TEXT_ALL_ALLIES else text = YEA::BATTLE::HELP_TEXT_ALL_FOES end return if text == @text @text = text contents.clear reset_font_settings draw_text(0, 0, contents.width, line_height*2, @text, 1) else window_battlehelp_refresh_special_case_target_any(battler) end endend#==============================================================================# Game_Action#==============================================================================class Game_Action #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :ally #-------------------------------------------------------------------------- # alias method: clear #-------------------------------------------------------------------------- alias game_action_clear_target_any clear def clear game_action_clear_target_any @ally = false end #-------------------------------------------------------------------------- # alias method: set_skill #-------------------------------------------------------------------------- alias game_action_set_skill_targets_any set_skill def set_skill(skill_id) game_action_set_skill_targets_any(skill_id) @ally = self.item.default_for_friend self end #-------------------------------------------------------------------------- # alias method: set_item #-------------------------------------------------------------------------- alias game_action_set_item_targets_any set_item def set_item(item_id) game_action_set_item_targets_any(item_id) @ally = self.item.default_for_friend self end #-------------------------------------------------------------------------- # alias method: make_custom_targets #-------------------------------------------------------------------------- alias game_action_make_custom_targets_target_any make_custom_targets def make_custom_targets array = game_action_make_custom_targets_target_any if item.for_any? if @ally array += [friends_unit.smooth_target(@target_index)] else array += [opponents_unit.smooth_target(@target_index)] end elsif item.for_any_all? if @ally array |= friends_unit.alive_members else array |= opponents_unit.alive_members end end return array endend # Game_Action#==============================================================================# Window_BattleActor#==============================================================================class Window_BattleActor < Window_BattleStatus #-------------------------------------------------------------------------- # overwrite method: process_handling #-------------------------------------------------------------------------- def process_handling return unless open? && active return process_dir8 if Input.repeat?(:UP) return super end #-------------------------------------------------------------------------- # new method: process_dir4 #-------------------------------------------------------------------------- def process_dir8 Sound.play_cursor Input.update deactivate call_handler(:dir8) end end # Window_BattleActor#==============================================================================# Window_BattleActor#==============================================================================class Window_BattleEnemy < Window_Selectable #-------------------------------------------------------------------------- # overwrite method: process_handling #-------------------------------------------------------------------------- def process_handling return unless open? && active return process_dir2 if Input.repeat?(:DOWN) return super end #-------------------------------------------------------------------------- # new method: process_dir4 #-------------------------------------------------------------------------- def process_dir2 Sound.play_cursor Input.update deactivate call_handler(:dir2) end end # Window_BattleActor#==============================================================================# Scene_Battle#==============================================================================class Scene_Battle < Scene_Base #-------------------------------------------------------------------------- # * alias: create_actor_window #-------------------------------------------------------------------------- alias scene_battle_create_actor_window_target_any create_actor_window def create_actor_window scene_battle_create_actor_window_target_any @actor_window.set_handler(:dir8, method(:on_target_change)) end #-------------------------------------------------------------------------- # * alias: create_enemy_window #-------------------------------------------------------------------------- alias scene_battle_create_enemy_window_target_any create_enemy_window def create_enemy_window scene_battle_create_enemy_window_target_any @enemy_window.set_handler(:dir2, method(:on_target_change)) end #-------------------------------------------------------------------------- # alias method: on_actor_cancel #-------------------------------------------------------------------------- alias scene_battle_on_actor_cancel_target_any on_actor_cancel def on_actor_cancel scene_battle_on_actor_cancel_target_any case @actor_command_window.current_symbol when :attack @status_window.show @actor_command_window.activate @help_window.hide end end #-------------------------------------------------------------------------- # overwrite method: on_skill_ok #-------------------------------------------------------------------------- def on_skill_ok @skill = @skill_window.item $game_temp.battle_aid = @skill BattleManager.actor.input.set_skill(@skill.id) BattleManager.actor.last_skill.object = @skill if @skill.default_for_friend select_actor_selection elsif @skill.for_opponent? select_enemy_selection elsif @skill.for_friend? select_actor_selection else @skill_window.hide next_command $game_temp.battle_aid = nil end end #-------------------------------------------------------------------------- # overwrite method: on_item_ok #-------------------------------------------------------------------------- def on_item_ok @item = @item_window.item $game_temp.battle_aid = @item BattleManager.actor.input.set_item(@item.id) if @item.default_for_friend select_actor_selection elsif @item.for_opponent? select_enemy_selection elsif @item.for_friend? select_actor_selection else @item_window.hide next_command $game_temp.battle_aid = nil end $game_party.last_item.object = @item end #-------------------------------------------------------------------------- # new method: on_target_change #-------------------------------------------------------------------------- def on_target_change unless $game_temp.battle_aid.for_any? or $game_temp.battle_aid.for_any_all? if @enemy_window.visible @enemy_window.activate else @actor_window.activate end return end if @enemy_window.visible @enemy_window.hide select_actor_selection BattleManager.actor.input.ally = true else @actor_window.hide case @actor_command_window.current_symbol when :attack @status_window.show when :skill @skill_window.show when :item @item_window.show end select_enemy_selection BattleManager.actor.input.ally = false end endend
Credit and Thanks
Racheal
Yanfly
Author's Notes
This script requires Yanfly's Ace Battle Engine and Yanfly's Target Manager. This is mostly due to how you switch between targets, at least for the battle engine part. No additional versions are planned at this time.