03-03-2008, 05:55 AM
Randomly Targetted Skills
by RPG Advocate
saved from Phylomortis.Com
by RPG Advocate
saved from Phylomortis.Com
Introduction
This script allows you to designate skills to have additional target types as follows:
Scope 8: Random number of allies
Scope 9: Random number of enemies
Scope 10: Random number of allies (HP 0)
Scope 11: One random ally
Scope 12: One random enemy
Since these new target types can't be set in the editor, you will need to use scripts to change the scope of the appropriate skill to the desired value. A simple script call of: $data_skills[1].scope = 8 would set the 1st skill (Heal) to affect a random number of allies[i].
The formula is simple: $data_skills[[i]skill ID].scope = scope
Demo
>Click<
Script
Randomly Targetted Skills
Code:
# Randomly Targetted Skills
# by RPG Advocate
# As this adds additional scopes to the system that are out of the range of
# the RMXP Editor, you will have to add them through scripts or script calls.
#
# The command call is simple: $data_skills[n].scope = s
#
# Where n is the index number of your skill (in the database), and s is the
# number of the targetting scope being applied (see below):
#
# Scope 8: Random number of allies
# Scope 9: Random number of enemies
# Scope 10: Random number of allies (HP 0)
# Scope 11: One random ally
# Scope 12: One random enemy
#==============================================================================
# ** Game_Party
#------------------------------------------------------------------------------
# This class handles the party. It includes information on amount of gold
# and items. Refer to "$game_party" for the instance of this class.
#==============================================================================
class Game_Party
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
def multi_random_target_actor(hp0 = false)
max_targets = 0
num_targets = 0
selected_targets = []
if hp0
for actor in $game_party.actors
if actor.hp == 0
max_targets += 1
end
end
else
for actor in $game_party.actors
if actor.hp > 0
max_targets += 1
end
end
end
if max_targets == 0
return nil
end
targz = rand(max_targets) + 1
max_targets = targz
while num_targets < max_targets
t = $game_party.actors[rand($game_party.actors.size)]
if selected_targets.include?(t)
next
end
if hp0
if t.hp == 0
selected_targets.push(t)
num_targets += 1
end
else
if t.hp > 0
selected_targets.push(t)
num_targets += 1
end
end
end
return selected_targets
end
end
#==============================================================================
# ** Game_Troop
#------------------------------------------------------------------------------
# This class deals with troops. Refer to "$game_troop" for the instance of
# this class.
#==============================================================================
class Game_Troop
#--------------------------------------------------------------------------
# * Object Initialization
#--------------------------------------------------------------------------
def multi_random_target_enemy(hp0 = false)
max_targets = 0
num_targets = 0
selected_targets = []
if hp0
for monster in $game_troop.enemies
if monster.hp == 0
max_targets += 1
end
end
else
for monster in $game_troop.enemies
if monster.hp > 0
max_targets += 1
end
end
end
if max_targets == 0
return nil
end
targz = rand(max_targets) + 1
max_targets = targz
while num_targets < max_targets
t = $game_troop.enemies[rand($game_troop.enemies.size)]
if selected_targets.include?(t)
next
end
if hp0
if t.hp == 0
selected_targets.push(t)
num_targets += 1
end
else
if t.hp > 0
selected_targets.push(t)
num_targets += 1
end
end
end
return selected_targets
end
end
#==============================================================================
# ** Scene_Battle
#------------------------------------------------------------------------------
# This class performs battle screen processing.
#==============================================================================
class Scene_Battle
#--------------------------------------------------------------------------
# * Set Targeted Battler for Skill or Item
# scope : effect scope for skill or item
#--------------------------------------------------------------------------
def set_target_battlers(scope)
# If battler performing action is enemy
if @active_battler.is_a?(Game_Enemy)
# Branch by effect scope
case scope
when 1 # single enemy
index = @active_battler.current_action.target_index
@target_battlers.push($game_party.smooth_target_actor(index))
when 2 # all enemies
for actor in $game_party.actors
if actor.exist?
@target_battlers.push(actor)
end
end
when 3 # single ally
index = @active_battler.current_action.target_index
@target_battlers.push($game_troop.smooth_target_enemy(index))
when 4 # all allies
for enemy in $game_troop.enemies
if enemy.exist?
@target_battlers.push(enemy)
end
end
when 5 # single ally (HP 0)
index = @active_battler.current_action.target_index
enemy = $game_troop.enemies[index]
if enemy != nil and enemy.hp0?
@target_battlers.push(enemy)
end
when 6 # all allies (HP 0)
for enemy in $game_troop.enemies
if enemy != nil and enemy.hp0?
@target_battlers.push(enemy)
end
end
when 7 # user
@target_battlers.push(@active_battler)
when 8 # Random number of allies
@target_battlers = $game_troop.multi_random_target_enemy
when 9 # Random number of enemies
@target_battlers = $game_party.multi_random_target_actor
when 10 # Random number of allies (HP 0)
@target_battlers = $game_party.multi_random_target_actor(true)
when 11 # One random ally
@target_battlers = [$game_troop.random_target_enemy]
when 12 # One random enemy
@target_battlers = [$game_party.random_target_actor]
end
end
# If battler performing action is actor
if @active_battler.is_a?(Game_Actor)
# Branch by effect scope
case scope
when 1 # single enemy
index = @active_battler.current_action.target_index
@target_battlers.push($game_troop.smooth_target_enemy(index))
when 2 # all enemies
for enemy in $game_troop.enemies
if enemy.exist?
@target_battlers.push(enemy)
end
end
when 3 # single ally
index = @active_battler.current_action.target_index
@target_battlers.push($game_party.smooth_target_actor(index))
when 4 # all allies
for actor in $game_party.actors
if actor.exist?
@target_battlers.push(actor)
end
end
when 5 # single ally (HP 0)
index = @active_battler.current_action.target_index
actor = $game_party.actors[index]
if actor != nil and actor.hp0?
@target_battlers.push(actor)
end
when 6 # all allies (HP 0)
for actor in $game_party.actors
if actor != nil and actor.hp0?
@target_battlers.push(actor)
end
end
when 7 # user
@target_battlers.push(@active_battler)
when 8 # Random number of allies
@target_battlers = $game_party.multi_random_target_actor
when 9 # Random number of enemies
@target_battlers = $game_troop.multi_random_target_enemy
when 10 # Random number of allies (HP 0)
@target_battlers = $game_troop.multi_random_target_enemy(true)
when 11 # One random ally
@target_battlers = [$game_party.random_target_actor]
when 12 # One random enemy
@target_battlers = [$game_troop.random_target_enemy]
end
end
end
end