03-03-2008, 06:07 AM
Single/All Target Switching
by RPG Advocate
saved from Phylomortis.Com
by RPG Advocate
saved from Phylomortis.Com
Introduction
This script allows you to create skills that can hit either a single target or the entire party or enemy group, depending on the wishes of the player. The player presses up and down at the targetting prompt to switch between single- and group-target modes. Note that this script makes use of the Element Tagging procedure. You will need to create an element to which switchable-range skills will be assigned and change the value of the TARGETTING_ELEMENT value with the ID number of that element.
Demo
>Click<
Script
Modified:
In the script, you can assign the ELEMENT (by ID) you will use to tag/flag your Target-Switching skills.
SingleAll Target Switching
Code:
# Single/All Target Switching
# by RPG Advocate
# Element to tag Target Switching skills
TARGETTING_ELEMENT = 17
#==============================================================================
# ** Game_Temp
#------------------------------------------------------------------------------
# This class handles temporary data that is not included with save data.
# Refer to "$game_temp" for the instance of this class.
#==============================================================================
class Game_Temp
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_accessor :all_target # targetting mode
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
alias sats_init initialize
def initialize
sats_init
@all_target = false # Put this where you want in the method.
end
end
#==============================================================================
# ** Arrow_Base
#------------------------------------------------------------------------------
# This sprite is used as an arrow cursor for the battle screen. This class
# is used as a superclass for the Arrow_Enemy and Arrow_Actor classes.
#==============================================================================
class Arrow_Base < Sprite
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :index # cursor position
attr_reader :help_window # help window
attr_reader :all # all
attr_reader :option # option
#--------------------------------------------------------------------------
# * Object Initialization
# viewport : viewport
# all : all (false as default)
# option : option (false as default)
#--------------------------------------------------------------------------
def initialize(viewport, all = false, option = false)
super(viewport)
self.bitmap = RPG::Cache.windowskin($game_system.windowskin_name)
self.ox = 16
self.oy = 64
self.z = 2500
@blink_count = 0
@index = 0
@help_window = nil
@all = all
@option = option
update
end
end
#==============================================================================
# ** Arrow_Actor
#------------------------------------------------------------------------------
# This arrow cursor is used to choose an actor. This class inherits from the
# Arrow_Base class.
#==============================================================================
class Arrow_Actor < Arrow_Base
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
if @all
if @blink_count % 2 == 0
@index += 1
@index %= $game_party.actors.size
end
end
unless @all
if Input.repeat?(Input::RIGHT)
$game_system.se_play($data_system.cursor_se)
@index += 1
@index %= $game_party.actors.size
end
if Input.repeat?(Input::LEFT)
$game_system.se_play($data_system.cursor_se)
@index += $game_party.actors.size - 1
@index %= $game_party.actors.size
end
end
if Input.repeat?(Input::UP) && option == true && @all == false
$game_system.se_play($data_system.cursor_se)
@all = true
$game_temp.all_target = true
@index = 0
end
if Input.repeat?(Input::DOWN) && option == true && @all == true
$game_system.se_play($data_system.cursor_se)
@all = false
$game_temp.all_target = false
@index = 0
end
if self.actor != nil
self.x = self.actor.screen_x
self.y = self.actor.screen_y
end
end
#--------------------------------------------------------------------------
# * Help Text Update
#--------------------------------------------------------------------------
def update_help
if @all
@help_window.set_text("All Allies", 1)
else
@help_window.set_enemy(self.actor)
end
end
end
#==============================================================================
# ** Arrow_Enemy
#------------------------------------------------------------------------------
# This arrow cursor is used to choose enemies. This class inherits from the
# Arrow_Base class.
#==============================================================================
class Arrow_Enemy < Arrow_Base
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
super
if @all
if @blink_count % 2 == 0
@index += 1
@index %= $game_troop.enemies.size
end
end
$game_troop.enemies.size.times do
break if self.enemy.exist?
@index += 1
@index %= $game_troop.enemies.size
end
unless @all
if Input.repeat?(Input::RIGHT)
$game_system.se_play($data_system.cursor_se)
$game_troop.enemies.size.times do
@index += 1
@index %= $game_troop.enemies.size
break if self.enemy.exist?
end
end
if Input.repeat?(Input::LEFT)
$game_system.se_play($data_system.cursor_se)
$game_troop.enemies.size.times do
@index += $game_troop.enemies.size - 1
@index %= $game_troop.enemies.size
break if self.enemy.exist?
end
end
end
if Input.repeat?(Input::UP) && option == true && @all == false
$game_system.se_play($data_system.cursor_se)
@all = true
$game_temp.all_target = true
@index = 0
end
if Input.repeat?(Input::DOWN) && option == true && @all == true
$game_system.se_play($data_system.cursor_se)
@all = false
$game_temp.all_target = false
@index = 0
end
if self.enemy != nil
self.x = self.enemy.screen_x
self.y = self.enemy.screen_y
end
end
#--------------------------------------------------------------------------
# * Help Text Update
#--------------------------------------------------------------------------
def update_help
if @all
@help_window.set_text("All Enemies", 1)
else
@help_window.set_enemy(self.enemy)
end
end
end
#==============================================================================
# ** Game_Battler (part 1)
#------------------------------------------------------------------------------
# This class deals with battlers. It's used as a superclass for the Game_Actor
# and Game_Enemy classes.
#==============================================================================
class Game_Battler
#--------------------------------------------------------------------------
# * Apply Skill Effects
# user : the one using skills (battler)
# skill : skill
# dilute : dilute
#--------------------------------------------------------------------------
def skill_effect(user, skill, dilute = 1)
self.critical = false
if ((skill.scope == 3 or skill.scope == 4) and self.hp == 0) or
((skill.scope == 5 or skill.scope == 6) and self.hp >= 1)
return false
end
effective = false
effective |= skill.common_event_id > 0
hit = skill.hit
if skill.atk_f > 0
hit *= user.hit / 100
end
hit_result = (rand(100) < hit)
effective |= hit < 100
if hit_result == true
if dilute == nil
dilute = 1
end
power = skill.power / dilute + user.atk * skill.atk_f / 100
if power > 0
power -= self.pdef * skill.pdef_f / 200
power -= self.mdef * skill.mdef_f / 200
power = [power, 0].max
end
rate = 20
rate += (user.str * skill.str_f / 100)
rate += (user.dex * skill.dex_f / 100)
rate += (user.agi * skill.agi_f / 100)
rate += (user.int * skill.int_f / 100)
self.damage = power * rate / 20
self.damage *= elements_correct(skill.element_set)
self.damage /= 100
if self.damage > 0
if self.guarding?
self.damage /= 2
end
end
if skill.variance > 0 and self.damage.abs > 0
amp = [self.damage.abs * skill.variance / 100, 1].max
self.damage += rand(amp+1) + rand(amp+1) - amp
end
eva = 8 * self.agi / user.dex + self.eva
hit = self.damage < 0 ? 100 : 100 - eva * skill.eva_f / 100
hit = self.cant_evade? ? 100 : hit
hit_result = (rand(100) < hit)
effective |= hit < 100
end
if hit_result == true
if skill.power != 0 and skill.atk_f > 0
remove_states_shock
effective = true
end
last_hp = self.hp
self.hp -= self.damage
effective |= self.hp != last_hp
@state_changed = false
effective |= states_plus(skill.plus_state_set)
effective |= states_minus(skill.minus_state_set)
if skill.power == 0
self.damage = ""
unless @state_changed
self.damage = "Miss"
end
end
else
self.damage = "Miss"
end
unless $game_temp.in_battle
self.damage = nil
end
return effective
end
end
#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
# This class performs battle screen processing.
#==============================================================================
class Scene_Battle
#--------------------------------------------------------------------------
# * Main Processing
#--------------------------------------------------------------------------
alias sats_main main
def main
# New
@alltarget = false
@rangeswitch = false
@switched = [false, false, false, false]
# Perform the original call
sats_main
end
#--------------------------------------------------------------------------
# * Start Party Command Phase
#--------------------------------------------------------------------------
alias sats_start_phase2 start_phase2
def start_phase2
for i in 0..3
@switched[i] = false
end
# Original call
sats_start_phase2
end
#--------------------------------------------------------------------------
# * Frame Update (actor command phase : skill selection)
#--------------------------------------------------------------------------
def update_phase3_skill_select
@skill_window.visible = true
@skill_window.update
if Input.trigger?(Input::B)
$game_system.se_play($data_system.cancel_se)
end_skill_select
return
end
if Input.trigger?(Input::C)
@skill = @skill_window.skill
if @skill == nil or not @active_battler.skill_can_use?(@skill.id)
$game_system.se_play($data_system.buzzer_se)
return
end
$game_system.se_play($data_system.decision_se)
@active_battler.current_action.skill_id = @skill.id
@skill_window.visible = false
if @skill.scope == 1
@alltarget = false
@rangeswitch = determine_range_switch(@skill)
start_enemy_select
elsif @skill.scope == 2
@alltarget = true
start_enemy_select
elsif @skill.scope == 3 or @skill.scope == 5
@alltarget = false
@rangeswitch = determine_range_switch(@skill)
start_actor_select
elsif @skill.scope == 4 or @skill.scope == 6
@alltarget = true
start_actor_select
else
end_skill_select
phase3_next_actor
end
return
end
end
#--------------------------------------------------------------------------
# * Start Enemy Selection
#--------------------------------------------------------------------------
def start_enemy_select
@enemy_arrow = Arrow_Enemy.new(@spriteset.viewport1, @alltarget, @rangeswitch)
@enemy_arrow.help_window = @help_window
@actor_command_window.active = false
@actor_command_window.visible = false
end
#--------------------------------------------------------------------------
# * End Enemy Selection
#--------------------------------------------------------------------------
alias sats_end_enemy_select end_enemy_select
def end_enemy_select
if $game_temp.all_target
@switched[@actor_index] = true
$game_temp.all_target = false
end
# Original call
sats_end_enemy_select
end
#--------------------------------------------------------------------------
# * Start Actor Selection
#--------------------------------------------------------------------------
def start_actor_select
@actor_arrow = Arrow_Actor.new(@spriteset.viewport2, @alltarget, @rangeswitch)
@actor_arrow.index = @actor_index
@actor_arrow.help_window = @help_window
@actor_command_window.active = false
@actor_command_window.visible = false
end
#--------------------------------------------------------------------------
# * End Actor Selection
#--------------------------------------------------------------------------
alias sats_end_actor_select end_actor_select
def end_actor_select
if $game_temp.all_target
@switched[@actor_index] = true
$game_temp.all_target = false
end
# Original call
sats_end_actor_select
end
#--------------------------------------------------------------------------
# * Determine Targetting Range Switch
#--------------------------------------------------------------------------
def determine_range_switch(skill)
if skill.element_set.include?(TARGETTING_ELEMENT)
return true
else
return false
end
end
#--------------------------------------------------------------------------
# * Make Skill Action Results
#--------------------------------------------------------------------------
def make_skill_action_result
@skill = $data_skills[@active_battler.current_action.skill_id]
unless @active_battler.current_action.forcing
unless @active_battler.skill_can_use?(@skill.id)
$game_temp.forcing_battler = nil
@phase4_step = 1
return
end
end
@active_battler.sp -= @skill.sp_cost
@status_window.refresh
@help_window.set_text(@skill.name, 1)
@animation1_id = @skill.animation1_id
@animation2_id = @skill.animation2_id
@common_event_id = @skill.common_event_id
skillmodify = @skill.clone
if @switched[@active_battler.index]
if @active_battler.is_a?(Game_Actor)
skillmodify.scope += 1
dilute_ratio = 0
if skillmodify.scope == 2
for i in $game_troop.enemies
if i.exist?
dilute_ratio += 1
end
end
end
if skillmodify.scope == 4 || skillmodify.scope == 6
for i in $game_party.actors
if i.exist?
dilute_ratio += 1
end
end
end
end
end
if dilute_ratio == 0 || dilute_ratio == nil
dilute_ratio = 1
end
set_target_battlers(skillmodify.scope)
for target in @target_battlers
target.skill_effect(@active_battler, @skill, dilute_ratio)
end
end
end