Skills that cost HP
Version: 1.2
Author: modern algebra
Date: February 27, 2008
Description
This script allows you to assign hp cost to skills. This means that you can make it so that a skill can hurt (or heal) the user when he casts it.
Features
- Allows skills to have an HP basic cost, as well as a percentage cost
- Very intuitive configuration; it is easy to set up
Instructions
See inside the header for instructions
Script
#======================================================================
# Skills with HP Cost
# Author: modern algebra (rmrk.net)
# Version: 1.2
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Instructions:
# Set up the database below according to instructions
#======================================================================
# ** RPG::Skill
#======================================================================
class RPG::Skill
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * HP Cost
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
def hp_cost
# Default value for skills with undefined HP cost
cost, percent = 0, 0
case @id
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Editable Region
#-----------------------------------------------------------------------------------------------------------------------
# For each skill to which you want to assign an hp_cost, set it up like so:
# when skill ID
# cost = <the amount of HP that you want to subtract from the user. If the number is
# negative, then the user of the skill will be healed by that amount>
# percent = <the percentage of max HP you wish to subtract from the user. If negative,
# then the user of the skill will be healed by that percentage>
#
# There are a couple of examples below. Feel free to delete them once you understand
# what is required of you
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
when 1 # Skill #1 in database
cost = 10 # The amount of HP to subtract from user
percent = 20 # The % of maxhp to subtract from user
when 5
cost = 100
when 33
percent = 10
end
percent = percent.to_f / 100
return cost, percent
end
end
#=====================================================================
# ** Game_Battler
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Summary of Changes:
# aliased methods - skill_can_use?, skill_effect
#=====================================================================
class Game_Battler
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Skill Can Use?
#-----------------------------------------------------------------------------------------------------------------------
# Added a requirement that a skill cannot be used if the user's HP is less than the HP Cost
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias modalg_hp_cost_skills_can_use? skill_can_use?
def skill_can_use? (skill)
if !skill.nil?
basic, percent = skill.hp_cost
return false if (basic + (percent*maxhp).to_i) > hp
end
return modalg_hp_cost_skills_can_use? (skill)
end
end
class Scene_Skill
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# * Skill Effect
#-----------------------------------------------------------------------------------------------------------------------
# Subtract the HP Cost from the user
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
alias modalg_hp_cost_useskill_7uj3 use_skill_nontarget
def use_skill_nontarget (*args)
if !@skill.nil?
basic, percent = @skill.hp_cost
@actor.hp -= ((percent*@actor.maxhp).to_i + basic)
end
modalg_hp_cost_useskill_7uj3 (*args)
end
end
class Scene_Battle
#--------------------------------------------------------------------------
# * Execute Battle Action: Skill
#--------------------------------------------------------------------------
alias mala_hpcost_excut_skill_6yh1 execute_action_skill
def execute_action_skill (*args)
mala_hpcost_excut_skill_6yh1 (*args)
if @active_battler && @active_battler.action && @active_battler.action.skill
basic, percent = @active_battler.action.skill.hp_cost
@active_battler.hp -= ((percent*@active_battler.maxhp).to_i + basic)
end
end
end
Credit
Thanks
- Johnny Intergalactic Man, for requesting the script
Support
Just post in this topic at rmrk for quick support. I wrote this script very quickly and have not done any extensive testing, so please inform me if any issues arise.
Known Compatibility Issues
It should be compatible with any script that does not perform the same function as this one. If any issues arise, I will be happy to fix them for you.
This script by
modern algebra is licensed under a
Creative Commons Attribution-Non-Commercial-Share Alike 2.5 Canada License.