RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[Script Support - SOLVED] Skills that cost HP

0 Members and 1 Guest are viewing this topic.

***
Rep:
Level 74
I'm baaack!
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)
« Last Edit: April 06, 2011, 09:34:46 PM by RPGMakerVX52 »

*
Rep:
Level 97
2014 Most Unsung Member2014 Best RPG Maker User - Engine2013 Best RPG Maker User (Scripting)2012 Most Mature Member2012 Favorite Staff Member2012 Best RPG Maker User (Scripting)2012 Best MemberSecret Santa 2012 ParticipantProject of the Month winner for July 20092011 Best Use of Avatar and Signature Space2011 Best RPG Maker User (Scripting)2011 Most Mature Member2011 Favourite Staff Member2011 Best Veteran2010 Most Mature Member2010 Favourite Staff Member
Well, you're missing an end right before:

Code: [Select]
    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.

***
Rep:
Level 74
I'm baaack!
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