RMRK is retiring.
Server is paid up for the rest of 2026, but the forum may go after that. See here for more information. Please archive or save anything you would like to keep before 2027.
Main Menu
  • Welcome to The RPG Maker Resource Kit.

[Script Support - SOLVED] Skills that cost HP

Started by Infinate X, April 05, 2011, 10:45:30 PM

0 Members and 1 Guest are viewing this topic.

Infinate X

I need help with one of modern algebras scripts: Skills that cost HP

#======================================================================
#  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 %  % = Skill ID in database     
#     cost = 10 # The amount of HP to subtract from user is 10.
#  percent = 20 # The % of maxhp to subtract from user is 20%.
    when 1
      cost = 10
   percent = 0
    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


Line 95(The last line) is glitched, and the only part I edited was where modern algebra said people could remove (The set up)

modern algebra

Well, you're missing an end right before:


    percent = percent.to_f / 100
    return cost, percent


When I said you could delete the examples I certainly didn't mean the end, just the when branches.

Infinate X

Oh...I didn't realize I deleted an end... Thanks for your help even though you said you were to busy with exams... I'll just fix that and delete this topic...  :(

Just in case it makes you feel nice I'm accually just going to lock the topic so you can see my reply. :D