08-10-2009, 01:00 PM
(This post was last modified: 05-14-2017, 06:00 AM by DerVVulfman.)
"Drain" skills or weapons for DBS
by Jimmie
August 10, 2009
This has probably been done a hundred times...
Introduction
A skill which leeches HP from an enemy. A sword which hurts both the target and the wielder. Etc.
In short, this script:
by Jimmie
August 10, 2009
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.
No support is given. If you are the owner of the thread, please contact administration.
This has probably been done a hundred times...
Introduction
A skill which leeches HP from an enemy. A sword which hurts both the target and the wielder. Etc.
In short, this script:
- Makes certain skills and weapons heal/hurt the user in proportion to the damage dealt (or healed) by use of said skill or weapon
- Shows an animation on the user which plays after the target animation but before healing/dealing damage to the user
- Allows multiple drain effects with varying efficiency and animations
- Allows you to choose how it deals with using a draining skill with a draining weapon.
- This script was designed for the default battle system. It may or may not work with other battle systems.
Installation
Copy/paste the script below into a new slot above main.
Code:#==============================================================================
# ** Draining skills and weapons
# Vesion 1.0 by Jimmie 10 of August 2009
#------------------------------------------------------------------------------
# Allows skills and weapons to make the user gain (or lose) life depending on
# the damage dealt to targets.
#==============================================================================
# Which elements indicate a draining skill/weapon?
# Syntax: Element_ID => [percent of damage drained, animation ID] (remember commas!)
# Negative percentages will make the user pay HP when using the skill.
# Put 0 for no animation
DRAIN_ELEMENTS = {
17 => [100, 100],
18 => [50, 2],
19 => [25, 3],
20 => [-10, 4]
}
# When using a skill...
# 0: Weapon drainage doesn't count
# 1: Weapon drainage counts as normal
# 2: Uses weapon drainage * skill ATK-F / 100
WEAPON_DRAIN_WHEN_USING_SKILL = 2
# When using a skill...
# 0: Skill drainage as in database
# 1: Skill drainage * skill INT-F
SKILL_DRAIN = 0
# Skill animation will always take priority
# End of configuration
class Scene_Battle
def make_skill_action_result
# Get skill
@skill = $data_skills[@active_battler.current_action.skill_id]
# If not a forcing action
unless @active_battler.current_action.forcing
# If unable to use due to SP running out
unless @active_battler.skill_can_use?(@skill.id)
# Clear battler being forced into action
$game_temp.forcing_battler = nil
# Shift to step 1
@phase4_step = 1
return
end
end
# Use up SP
@active_battler.sp -= @skill.sp_cost
# Refresh status window
@status_window.refresh
# Show skill name on help window
@help_window.set_text(@skill.name, 1)
# Set animation ID
@animation1_id = @skill.animation1_id
@animation2_id = @skill.animation2_id
# Set command event ID
@common_event_id = @skill.common_event_id
# Set target battlers
set_target_battlers(@skill.scope)
# Apply skill effect
# Keep track of total damage dealt
total_damage = 0
for target in @target_battlers
target.skill_effect(@active_battler, @skill)
total_damage += target.damage if target.damage.is_a?(Numeric)
end
# Checks whether the used skill is a draining skill,
# and if so apply the effects
drain = DRAIN_ELEMENTS[DRAIN_ELEMENTS.keys.find {|element, value| @skill.element_set.include?(element)}]
if SKILL_DRAIN == 1
drain[0] *= @skill.int_f / 100
end
# Checks whether the equipped weapon is a draining weapon
if WEAPON_DRAIN_WHEN_USING_SKILL != 0
weapon_drain = DRAIN_ELEMENTS[DRAIN_ELEMENTS.keys.find {|element, value| @active_battler.element_set.include?(element)}]
if weapon_drain != nil
weapon_drain = weapon_drain[0]
if WEAPON_DRAIN_WHEN_USING_SKILL == 2
weapon_drain *= @skill.atk_f / 100
end
drain[0] += weapon_drain
end
end
if drain != nil
# Performs the effects of the drain on the user
@active_battler.hp += total_damage * drain[0] / 100
@active_battler.damage = - total_damage * drain[0] / 100
@draining_battler = @active_battler
@drain_animation = drain[1]
else
@draining_battler = nil
@drain_animation = nil
end
end
def make_basic_action_result
# If attack
if @active_battler.current_action.basic == 0
# Set anaimation ID
@animation1_id = @active_battler.animation1_id
@animation2_id = @active_battler.animation2_id
# If action battler is enemy
if @active_battler.is_a?(Game_Enemy)
if @active_battler.restriction == 3
target = $game_troop.random_target_enemy
elsif @active_battler.restriction == 2
target = $game_party.random_target_actor
else
index = @active_battler.current_action.target_index
target = $game_party.smooth_target_actor(index)
end
end
# If action battler is actor
if @active_battler.is_a?(Game_Actor)
if @active_battler.restriction == 3
target = $game_party.random_target_actor
elsif @active_battler.restriction == 2
target = $game_troop.random_target_enemy
else
index = @active_battler.current_action.target_index
target = $game_troop.smooth_target_enemy(index)
end
end
# Set array of targeted battlers
@target_battlers = [target]
# Apply normal attack results
# Keep track of damage
total_damage = 0
for target in @target_battlers
target.attack_effect(@active_battler)
total_damage += target.damage if target.damage.is_a?(Numeric)
end
# Checks whether the used weapon has drain properties
# and if so apply the effects
drain = DRAIN_ELEMENTS[DRAIN_ELEMENTS.keys.find {|element, value| @active_battler.element_set.include?(element)}]
if drain != nil
# Performs the effects of the drain on the user
@active_battler.hp += total_damage * drain[0] / 100
@active_battler.damage = - total_damage * drain[0] / 100
@draining_battler = @active_battler
@drain_animation = drain[1]
else
@draining_battler = nil
@drain_animation = nil
end
return
end
# If guard
if @active_battler.current_action.basic == 1
# Display "Guard" in help window
@help_window.set_text($data_system.words.guard, 1)
return
end
# If escape
if @active_battler.is_a?(Game_Enemy) and
@active_battler.current_action.basic == 2
# Display "Escape" in help window
@help_window.set_text("Escape", 1)
# Escape
@active_battler.escape
return
end
# If doing nothing
if @active_battler.current_action.basic == 3
# Clear battler being forced into action
$game_temp.forcing_battler = nil
# Shift to step 1
@phase4_step = 1
return
end
end
def update_phase4_step5
# Hide help window
@help_window.visible = false
# Refresh status window
@status_window.refresh
# Display damage
for target in @target_battlers
if target.damage != nil
target.damage_pop = true
end
end
# Did someone use a drain skill?
if @draining_battler != nil
# Show the drained HP
if @drain_animation != 0
@draining_battler.animation_id = @drain_animation
length = $data_animations[@drain_animation].frame_max * Graphics.frame_rate / 20
while length > 0
length -= 1
#p @draining_battler
@spriteset.update
Graphics.update
end
end
@draining_battler.damage_pop = true
end
# Shift to step 6
@phase4_step = 6
end
end
As the script indicates, the values at the top of the script determine which elements indicate a draining skill or weapon, and how much these skills/weapons will heal the user as well as what animation is used. Set these up to your liking. It's recommended that the remaining options are left as they are, but feel free to play around, that's what they're there for.
Have fun!
//Jimmie
- This script was designed for the default battle system. It may or may not work with other battle systems.