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.
Skills that cost HP

0 Members and 1 Guest are viewing this topic.

*
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
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


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


  • modern algebra

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.


Creative Commons License
This script by modern algebra is licensed under a Creative Commons Attribution-Non-Commercial-Share Alike 2.5 Canada License.
« Last Edit: March 22, 2011, 12:25:54 PM by modern algebra »

**
Rep: +0/-0Level 86
What's with these people?!?
This could come in handy for healing spells. Though it would be better if you could set a percentage value or a random value between numbers... But so far this sounds good. I'm definitely using this!

EDIT: I guess not! XD It only works for the user. Oh well. Could come to use sometime.
« Last Edit: February 26, 2008, 12:14:09 AM by GasparXR »

*
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
You can set healing spells in the database normally. Just set the damage effect to a negative value.

**
Rep: +0/-0Level 86
What's with these people?!?
I know that, but it's a random value. I guess that's okay though, that's why there's such a thing as updating =P I remember in 2000 that you could set a spell to heal... I'll have to check it again.

*
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
random? set variance, pdef_f, and mdef_f to 0 and it will do the exact amount you set in basic effect

**
Rep:
Level 86
CHAINSAW!!
hate to rain on ur parade but.... this could be done with common events =P
I have:
GM7
RPGXP
RPGVX
FPS Creator
Cube 2
3D Gamemaker (SHITBOX!)

WIP stats:
RPGVX:
none, just experimenting with random events...

*
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
Yeah, I know that, but it's easier through a script like this.

And also, you aren't able to disable the skill easily if the hero doesn't have enough HP to cast it through events. It's a huge pain. With scripts, it simply doesn't allow you to use the skill if you don't have enough HP to do so.

**
Rep: +0/-0Level 86
This script also works with MP.  You just have to change few things that have hp in the script. 

*
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
You can set the skill to decrease the user's MP through the database :P

**
Rep: +0/-0Level 86

Yea. but I wonder we can modify the script to do percent instead.

**
Rep:
Level 84
Yes...Very good script..

I might use this script..
If I found bug or other error I will post in this thread...

Thank you~^^

**
Rep: +0/-0Level 83
This is awesome! Thanks a lot.

**
Rep: +0/-0Level 82
A win = a fail at failing... So a Win = a Fail.
Does this work with GubiD's Tactical Battle System VX?
I couldnt get it working on there for some reason. If there is a patch to make it work, or if you know it doesn't work, please get back to me on this one.

Thanks a lot.           Jesse

Ps. You have made all of my favourite work. (Not a big Yanfly fan, not saying Yanfly is bad, just an opinion)

*
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
I don't know if it works with GubiD or not, but I would think it strange not to. Have you tried putting this script below Gubid's TBS in the Script Editor. It should still be above Main.

And thanks for the compliment.

**
Rep: +0/-0Level 82
A win = a fail at failing... So a Win = a Fail.
Yeah, I've tried that. I'm not too skilled at scripting in general, but if I have a problem I can usually find a solution... But this eludes me at every turn... Theres no errors. No leads... Just... Nothing.

*
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
So there aren't any errors or anything - it just isn't being applied?


EDIT::

I just downloaded and tested - it worked for me - the HP was reduced, though there was no damage popup.
« Last Edit: October 14, 2009, 08:21:00 PM by Owyn »

**
Rep: +0/-0Level 82
A win = a fail at failing... So a Win = a Fail.
Hmm, I didnt even get that much out of it... What exactly did you do then? I may have written it wrong, or in the wrong place. Hence the fact that Im only human.  xD Lol. And thanks for your help.

*
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
All I did was put it directly above Main and below all parts of Gubid's script

****
kikiki
Rep:
Level 84
Hi
This looks nice...


but I want one for RMXP ;_;
Hi

**
Rep: +0/-0Level 79
RMRK Junior
Hello,
I got an error when using this script.  The error comes when I attempt to use the skill of a hero who does not have any skills yet.

line 61: NoMethodError occurred.
undefined method 'hp_cost' for nil:NilClass

Thanks a bunch!

*
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
I updated the script in the main post. Replace your version with that and see if it works.

**
Rep: +0/-0Level 79
RMRK Junior
It works perfectly now! Thanks for your quick responses.  I'm using a lot of your scripts because they are just too useful to pass up.  ;D

**
Rep: +0/-0Level 74
RMRK Junior
Would it be possible to make something with a state like if inflicted with a state all skills that require MP will use up HP instead?

****
Rep:
Level 76
Praise the Sun (Arcana)
GIAW 14: 1st Place (Hard Mode)
I smell my 13th class - heh heh heh :zwink:, the Bloodmage. Great job yet again.

**
Rep: +0/-0Level 81
RMRK Junior
hi would it be at all possible to have it so it shows the hp cost with the skill like it dse for mp

**
Rep: +0/-0Level 83
Hey Modern Algebra, just wanted to say that I can't seem to get this script functioning with Tankentai. I've tried placing this script into a fresh download of the SBS, changed the script to have a skill take 40% of my maximum HP, and when I use the skill, it kills the user.

I was attempting to make an attack that Drained his health and healed all the allies.

I made another attack that damaged all enemies and drained 10% of his Maximum HP, and it took way more than 10%. I've tried placing the script, above, below, all around and upside down in my list of scripts, and still doesn't seem to work. Any idea? I love this script and have a character in my RPG completely based around his skills functioning like this. I'm also not a complete newbie when it comes to editting scripts and customizing them a bit, so I do not think that is the issue. You placed a pretty easy to follow example in the script itself.

*
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
Hmm, it looks like it might not have anything to do with tankentai - just a straight up logic error - totally my fault. I'll fix it.

EDIT::

Alright, I did a quick and messy "fix" and it is now in the first post. It should fix the initial problem, which was that I was subtracting the HP every time the skill hit a target. So 3 targets meant 120% instead of 40%. However, I haven't tested the new fix so I might have screwed up with syntax or any other number of reasons it's dumb not to test things.

Also, now it really might not be compatible with Tankentai, as I directly alias a method in Scene_Battle, which may operate unexpectedly now. So test it out in a new project and see if everything is dandy before putting it in your main project. If I created an incompatibility or created a new error, just let me know and I will address the problem more fully once I have time.
« Last Edit: February 15, 2011, 02:57:10 AM by modern algebra »

**
Rep: +0/-0Level 83
Here is the error that I receive now. The skill fires off, but when it goes to calculate the HP done, this happens. I don't actually see the HP get subtracted.



Uploaded with ImageShack.us

*
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
Sorry, dumb mistake. I have again updated the first post so try it again.

*
Rep: +0/-0Level 71
RMRK Junior
Getting a similar problem to the guy above. The HP is subtracted after the skill is used, but then I get this error and the game crashes.


*
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
Are you using a non-default battle system? Either way, you might be able to fix it by replacing:

Code: [Select]
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)
    basic, percent = @active_battler.action.skill.hp_cost
    @active_battler.hp -= ((percent*@active_battler.maxhp).to_i + basic)
  end
end

with:

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

*
Rep: +0/-0Level 71
RMRK Junior
Ah, that took care of it. Thanks. I was using the Tankentai Side View System, which may have caused the problem. But that code took care of it.

**
Rep: +0/-0Level 64
RMRK Junior
How do I set up the displayed cost for a skill? To have either the text be misleading or have a skill cost both MP and HP is very annoying.