MP to HP and vice versa

Started by MarkHest, November 03, 2013, 06:18:23 pm

Previous topic - Next topic

MarkHest

Is there a way to make a spell convert a specified amount of HP to MP and MP to HP?
The spell should not be able to kill the user. So if you have 600HP and the spell converts 1000HP to MP it will stay at 1 HP and convert 599 HP instead. Same with MP but that can go down to 0.
   

WhiteRose

You might be able to do this with some of the HP damaging skills and SP adding skills in Tons of Addons, but it will probably require a bit of planning and possibly some tiny tweaking of the script. It should be doable, though. :)

MarkHest

I don't know how to edit scripts thought  :uhm:
   

G_G

November 03, 2013, 10:28:05 pm #3 Last Edit: November 03, 2013, 10:32:19 pm by gameus
1) Do you want me to make it so the skills only work if they have the necessary HP/MP?
2) Would you like me to implement percentages? For example: Convert 50% of your HP to MP and vica versa.
3) Would it be easier to make dummy elements such as "HP to MP" and "MP to HP" and then mark the skills accordingly? Or would you rather have an array of skills to configure in the script itself?

MarkHest

1: The skills should always work, however the caster can't kill itself by converting too much HP to MP. The caster also cannot convert more HP/MP than what they have.
2: That would be nice!
3: No idea what this means.
   

G_G

1) Okie dokes
2) Dokie okes
3)
You have two options: Script configuration or Element configuration

Script Configuration:
In the script, you'll define which skills are HP to MP / MP to HP. So you'll have two things to setup in the script.

Or...

Element Configuration:
You can create two new elements in your System Tab, name them "HP to MP" and "MP to HP", then all you have to do is mark the skills you want with those elements, that way the script knows which skills are supposed to convert HP/MP.

MarkHest

I want to define the ability ID's in the scrits. That works best for me :)
   

G_G

Sounds good, I'll have it done by the end of the day.

Also, the script should theoretically work if you want to use the skill on other targets. e.g. Use the skill on a team member, it'll suck your MP but it'll give an ally HP

MarkHest

The skill is intended to work for a targeted ally and if it is casted on another party member the MP/HP is ONLY converted for the targeted ally. The caster isn't affected as long as she doesn't cast it on herself. Unless I put a MP cost, which I won't :D
   

G_G

Oh okay. Well I should probably fix that then. It was setup so it would take from the caster since that seemed a bit more logical to begin with.

G_G

Okay, hopefully this works out.

Script: ShowHide
#===============================================================================
# HP/SP Reversal
# Author gameus
# Version 1.0
#-------------------------------------------------------------------------------
# Intro:
# Uses skills to take SP and convert it to HP or vica versa. The way it's setup
# is if the target is hit with one of these skills, it takes their HP/SP and
# turns it into the other stat. The skill itself doesn't affect the caster
# itself other than taking SP from the skill cost.
#
# Features:
# Use a fixed rate or a percentage
# Skills can work on enemies or allies
# Easy Setup
#
# Setting Up:
# To define a skill as HP to SP, add the id to the HP2SP array.
# Do the same for SP to HP skills, except add it to SP2HP array.
# To define the skills rate as "fixed" or "percentage", just set the skill
# to the desired rate in the config below. (Examples are provided)
#
# To define the amount of HP or SP to convert, all you do is go into the
# database and set the skill's "Power" attribute. e.g.
# If you have a skill that converts 100 HP to SP, make sure it's setup in the
# config:
#  HP2SP = {
#     skill_id => :fixed,
# }
# Then you go to the database and set teh power to 100. If it's a percentage,
# You just set the power to the percentage you want. e.g. 25% is 25 power.
#
# It is not possible to kill the target by converting HP to SP, but you can
# deplete all of the SP converting it to HP
#
# Compatibility:
# Not tested with SDK
# Not tested with any other skill add-ons but it should work
#
# Credits:
# gameus ~ creating it
# Mark Hest ~ Requesting it
#===============================================================================
module HPSP
  # These are skills that convert HP to SP
  HP2SP = {
    59 => :fixed,
    60 => :percent,
  }
  # These are skills that convert SP to HP
  SP2HP = {
    57 => :fixed,
    58 => :percent,
  }
  # Ignore everything below.
  def self.has?(skill_id)
    return (HP2SP.include?(skill_id) || SP2HP.include?(skill_id))
  end
  def self.type(skill_id)
    return nil if !self.has?(skill_id)
    return :hp if HP2SP.include?(skill_id)
    return :sp if SP2HP.include?(skill_id)
  end
end


class Game_Actor < Game_Battler
  alias gg_convert_hpmp_skill_effect_lat skill_effect
  def skill_effect(user, skill)
    if HPSP.has?(skill.id)
      type = HPSP.type(skill.id)
      rate = type == :hp ? HPSP::HP2SP[skill.id] : HPSP::SP2HP[skill.id]
      amount = rate == :fixed ? skill.power : (skill.power * 0.01)
      if type == :hp && self.hp > 1
        amount = (rate == :fixed ? [self.hp - 1, amount].min : self.hp * amount).ceil
        self.hp -= amount.to_i
        self.sp += amount.to_i
        self.damage = "-#{amount} +#{amount}"
      elsif type == :sp && self.sp > 0
        amount = (rate == :fixed ? [self.sp, amount].min : self.sp * amount).ceil
        self.hp += amount.to_i
        self.sp -= amount.to_i
        self.damage = "+#{amount} -#{amount}"
      else
        return false
      end
      return true
    end
    return gg_convert_hpmp_skill_effect_lat(user, skill)
  end
end


Example of it working in battle (also works in the menu).

Spoiler: ShowHide


Configuration. It's all explained in the script but here's a bit of help.
Spoiler: ShowHide




WhiteRose

Quote from: gameus on November 04, 2013, 10:20:29 pm
Okay, hopefully this works out.

Script: ShowHide
#===============================================================================
# HP/SP Reversal
# Author gameus
# Version 1.0
#-------------------------------------------------------------------------------
# Intro:
# Uses skills to take SP and convert it to HP or vica versa. The way it's setup
# is if the target is hit with one of these skills, it takes their HP/SP and
# turns it into the other stat. The skill itself doesn't affect the caster
# itself other than taking SP from the skill cost.
#
# Features:
# Use a fixed rate or a percentage
# Skills can work on enemies or allies
# Easy Setup
#
# Setting Up:
# To define a skill as HP to SP, add the id to the HP2SP array.
# Do the same for SP to HP skills, except add it to SP2HP array.
# To define the skills rate as "fixed" or "percentage", just set the skill
# to the desired rate in the config below. (Examples are provided)
#
# To define the amount of HP or SP to convert, all you do is go into the
# database and set the skill's "Power" attribute. e.g.
# If you have a skill that converts 100 HP to SP, make sure it's setup in the
# config:
#  HP2SP = {
#     skill_id => :fixed,
# }
# Then you go to the database and set teh power to 100. If it's a percentage,
# You just set the power to the percentage you want. e.g. 25% is 25 power.
#
# It is not possible to kill the target by converting HP to SP, but you can
# deplete all of the SP converting it to HP
#
# Compatibility:
# Not tested with SDK
# Not tested with any other skill add-ons but it should work
#
# Credits:
# gameus ~ creating it
# Mark Hest ~ Requesting it
#===============================================================================
module HPSP
  # These are skills that convert HP to SP
  HP2SP = {
    59 => :fixed,
    60 => :percent,
  }
  # These are skills that convert SP to HP
  SP2HP = {
    57 => :fixed,
    58 => :percent,
  }
  # Ignore everything below.
  def self.has?(skill_id)
    return (HP2SP.include?(skill_id) || SP2HP.include?(skill_id))
  end
  def self.type(skill_id)
    return nil if !self.has?(skill_id)
    return :hp if HP2SP.include?(skill_id)
    return :sp if SP2HP.include?(skill_id)
  end
end


class Game_Actor < Game_Battler
  alias gg_convert_hpmp_skill_effect_lat skill_effect
  def skill_effect(user, skill)
    if HPSP.has?(skill.id)
      type = HPSP.type(skill.id)
      rate = type == :hp ? HPSP::HP2SP[skill.id] : HPSP::SP2HP[skill.id]
      amount = rate == :fixed ? skill.power : (skill.power * 0.01)
      if type == :hp && self.hp > 1
        amount = (rate == :fixed ? [self.hp - 1, amount].min : self.hp * amount).ceil
        self.hp -= amount.to_i
        self.sp += amount.to_i
        self.damage = "-#{amount} +#{amount}"
      elsif type == :sp && self.sp > 0
        amount = (rate == :fixed ? [self.sp, amount].min : self.sp * amount).ceil
        self.hp += amount.to_i
        self.sp -= amount.to_i
        self.damage = "+#{amount} -#{amount}"
      else
        return false
      end
      return true
    end
    return gg_convert_hpmp_skill_effect_lat(user, skill)
  end
end


Example of it working in battle (also works in the menu).

Spoiler: ShowHide


Configuration. It's all explained in the script but here's a bit of help.
Spoiler: ShowHide






You whipped that up in one day? You're awesome, G_G. :)

KK20

Just curious, why use symbols when you can use strings?

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

G_G

Iunno. Not really much of a difference, especially if it's just used for configuration options. And plus I don't have to make the string into all lowercases before comparing since "Fixed" doesn't equal "fixed".

MarkHest

Finaly got some sleep and I'm not a wandering potatoe anymore. Thank you so much for the script GG! :haha:
I'll be sure to report any bugs if I find any in the script. Thank you again :)
   

MarkHest

Found a bug. It is incompatible with another script I am using: Full Reflection System by Blizzard

When I use my ability I get the error:


QuoteScript 'Full Refection System' line 160: ArgumentError occurred.

wrong number of arguments(3 for 2)



The line in the full reflection script says:

target.skill_effect(battler, skill, true)
   

Blizzard

Put my script below this one. Or vice versa.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

MarkHest

   

KK20

Remove 'Game_Actor < ' in G_G's script.

Other Projects
RPG Maker XP Ace  Upgrade RMXP to RMVXA performance!
XPA Tilemap  Tilemap rewrite with many features, including custom resolution!

Nintendo Switch Friend Code: 8310-1917-5318
Discord: KK20 Tyler#8901

Join the CP Discord Server!

MarkHest