MP Absorb Attack for Weapon Type

Hi there everyone.

I was trying to make certain types of weapon able to absorb/gain MP everytime their physical attack successfully hit the target, pretty much in the same fashion of Dragon Quest XI, where mage weapons can absorb MP in the same way.
I was wondering if you got any idea or suggestion to help me.

Thank you very much!
quickest, cheapest fix:
don't assign a default attack, instead assign a specific no-mp-stealing attack for warriors, and another mp-stealing attack for wizards.
add that one attack to the sword, and add a common event after-attack to that attack.
handle all your math through that common event.
Alternatively this script
Code:
#Set Guard/Attack Skills v1.3
#----------#
#Features: Let's you set different attack/guard actions for individual actors
#
#Usage:    Placed in note tags of actors, weapons, armors, classes:
#             <Attack_Id skill_id> - changes default attack
#             <Guard_Id skill_id>  - changes default guard
#
#          Weapons/Armors overrides Classes overides Actors.
#         
#
#----------#
#-- Script by: V.M of D.T
#
#- Questions or comments can be:
#    posted on the thread for the script
#    given by email: [email hidden]
#    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
#
#--- Free to use in any project, commercial or non-commercial, with credit given
# - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)

#Sets Attack/Guard commands to name of skill
SGAS_COMMAND_TO_SKILL_NAME = true

class Game_Actor
  def guard_skill_id
    @equips.each do |item|
      next unless item.object
      return $1.to_i if item.object.note.upcase =~ /<GUARD_ID (\d+)>/
    end
    return $1.to_i if self.class.note.upcase =~ /<GUARD_ID (\d+)>/
    actor.note.upcase =~ /<GUARD_ID (\d+)>/ ? $1.to_i : 2
  end
  def attack_skill_id
    @equips.each do |item|
      next unless item.object
      return $1.to_i if item.object.note.upcase =~ /<ATTACK_ID (\d+)>/
    end
    return $1.to_i if self.class.note.upcase =~ /<ATTACK_ID (\d+)>/
    actor.note.upcase =~ /<ATTACK_ID (\d+)>/ ? $1.to_i : 1
  end
end

class Window_ActorCommand
  def add_attack_command
    text = $data_skills[@actor.attack_skill_id].name if SGAS_COMMAND_TO_SKILL_NAME
    add_command(text ? text : Vocab::attack, :attack, @actor.attack_usable?)
  end
  def add_guard_command
    text = $data_skills[@actor.guard_skill_id].name if SGAS_COMMAND_TO_SKILL_NAME
    add_command(text ? text : Vocab::guard, :guard, @actor.guard_usable?)
  end
end

Define your altered attack skill, then use <Attack_Id x> (where x is your skill's ID) in the respective weapon's notebox. You can also put that into the class/actors instead so it applies for that class/actor always.
quickest, cheapest fix:
don't assign a default attack, instead assign a specific no-mp-stealing attack for warriors, and another mp-stealing attack for wizards.
add that one attack to the sword, and add a common event after-attack to that attack.
handle all your math through that common event.

Not a bad idea indeed,even though I would have to play up a bit with the database.
What kind of formula would you suggest for gaining/stealing 10% MP of the damage dealt?
Alternatively this script
Code:
#Set Guard/Attack Skills v1.3
#----------#
#Features: Let's you set different attack/guard actions for individual actors
#
#Usage:    Placed in note tags of actors, weapons, armors, classes:
#             <Attack_Id skill_id> - changes default attack
#             <Guard_Id skill_id>  - changes default guard
#
#          Weapons/Armors overrides Classes overides Actors.
#        
#
#----------#
#-- Script by: V.M of D.T
#
#- Questions or comments can be:
#    posted on the thread for the script
#    given by email: [email hidden]
#    provided on facebook: http://www.facebook.com/DaimoniousTailsGames
#
#--- Free to use in any project, commercial or non-commercial, with credit given
# - - Though a donation's always a nice way to say thank you~ (I also accept actual thank you's)

#Sets Attack/Guard commands to name of skill
SGAS_COMMAND_TO_SKILL_NAME = true

class Game_Actor
  def guard_skill_id
    @equips.each do |item|
      next unless item.object
      return $1.to_i if item.object.note.upcase =~ /<GUARD_ID (\d+)>/
    end
    return $1.to_i if self.class.note.upcase =~ /<GUARD_ID (\d+)>/
    actor.note.upcase =~ /<GUARD_ID (\d+)>/ ? $1.to_i : 2
  end
  def attack_skill_id
    @equips.each do |item|
      next unless item.object
      return $1.to_i if item.object.note.upcase =~ /<ATTACK_ID (\d+)>/
    end
    return $1.to_i if self.class.note.upcase =~ /<ATTACK_ID (\d+)>/
    actor.note.upcase =~ /<ATTACK_ID (\d+)>/ ? $1.to_i : 1
  end
end

class Window_ActorCommand
  def add_attack_command
    text = $data_skills[@actor.attack_skill_id].name if SGAS_COMMAND_TO_SKILL_NAME
    add_command(text ? text : Vocab::attack, :attack, @actor.attack_usable?)
  end
  def add_guard_command
    text = $data_skills[@actor.guard_skill_id].name if SGAS_COMMAND_TO_SKILL_NAME
    add_command(text ? text : Vocab::guard, :guard, @actor.guard_usable?)
  end
end

Define your altered attack skill, then use <Attack_Id x> (where x is your skill's ID) in the respective weapon's notebox. You can also put that into the class/actors instead so it applies for that class/actor always.


That seems quite promising, thanks for the heads up!
Are you using the script yourself? And if yes, any problems so far?
I use that script a lot, and have found it very straightforward.
Having assigned the relevant skill to the actor, you would then achieve what you want through the damage formula. There is a question, however. Do you want this attack to only drain MP or do you want it to drain MP and do HP damage?
I use that script a lot, and have found it very straightforward.
Having assigned the relevant skill to the actor, you would then achieve what you want through the damage formula. There is a question, however. Do you want this attack to only drain MP or do you want it to drain MP and do HP damage?

Hey there, thank you very much for confirming the script reliability.
I would like it do HP damage and Drain 10% of the damage dealt if that's possible.
Having the MP drain = a percentage of the damage dealt is a bit more tricky. That is because your formula must end with the damage. Therefore you have to apply the MP parts before the actual damage, so you have to juggle the damage part very exactly, you couldn't just a a.attack * 4 - b.def *2 type of formula. I don't know that that can be done in a way that allows the skill to function accurately across a range of enemies with varying DEF stats and an actor whose ATK will change over time and/or with gear.

Okay, here is the basic logic for a drain MP and damage HP skill.

Set damage type to HP damage

a.mp+=b.mp/5; b.mp-=b.mp/5; damage formula here

The first expression gives the actor a percentage of the enemy's MP. The second reduces the enemy's MP by that amount. The third part is where you specify the calculation of the damage.

I do know of a way of dealing MP damage and draining a percentage of that, but not for when it's HP damage.
Having the MP drain = a percentage of the damage dealt is a bit more tricky. That is because your formula must end with the damage. Therefore you have to apply the MP parts before the actual damage, so you have to juggle the damage part very exactly, you couldn't just a a.attack * 4 - b.def *2 type of formula. I don't know that that can be done in a way that allows the skill to function accurately across a range of enemies with varying DEF stats and an actor whose ATK will change over time and/or with gear.

Okay, here is the basic logic for a drain MP and damage HP skill.

Set damage type to HP damage

a.mp+=b.mp/5; b.mp-=b.mp/5; damage formula here

The first expression gives the actor a percentage of the enemy's MP. The second reduces the enemy's MP by that amount. The third part is where you specify the calculation of the damage.

I do know of a way of dealing MP damage and draining a percentage of that, but not for when it's HP damage.

I definitely understand that it's quite complicated as a percentage of the damage dealt is way too variable instead of something specific, but I guess there are more ways to get to the same end...

So as you suggested if a certain percentage of damage dealt is too tricky may I use a try and use a set fraction instead like 1/10 of enemy MP (that should be similar to the formula you suggested)?
Or even a certain amount of MP per attack, let's say 10 MP drain/gain each time they successufully attack?

PS: Your explanation is fantastic and very detailed, thank you very much for your time.
If you want to deal a specific amount of MP instead of a percentage, then the formula would be (using 10MP as an example)
a.mp+=10; b.mp-=10; damage formula here

Of course, you could do a bit of a combination on this. You could have the actor gaining a specific amount while the enemy loses a percentage (or the other way round), so then it would look like this
a.mp+=10; b.mp-=b.mp/5; damage formula here

Ah, just had a thought.
The percentage formula I've given is for 20% of actual MP. If you want it to be a percentage of maximum MP, then it would be b.mmp
You should be able to do something like this in the damage formula:
Ruby:
dam = a.atk * 4 - b.def * 2; a.mp+=(dam*0.1).to_i; b.mp-=(dam*0.1).to_i; dam

Change a.atk * 4 - b.def * 2 to whatever your formula should be. This way you're setting the amount at the start, using it for the MP drain and then using it for the damage at the end. (dam*0.1).to_i gets 10% of the damage formula amount. Just bear in mind that it won't take into account any skill variance amount.
That seems quite promising, thanks for the heads up!
Are you using the script yourself? And if yes, any problems so far?

Yes, we use this script quite a bit and it never had issues.
If you want to deal a specific amount of MP instead of a percentage, then the formula would be (using 10MP as an example)
a.mp+=10; b.mp-=10; damage formula here

Of course, you could do a bit of a combination on this. You could have the actor gaining a specific amount while the enemy loses a percentage (or the other way round), so then it would look like this
a.mp+=10; b.mp-=b.mp/5; damage formula here

Ah, just had a thought.
The percentage formula I've given is for 20% of actual MP. If you want it to be a percentage of maximum MP, then it would be b.mmp

I will try both Formulas and test the script later and hopefully everything will go well.
Thank you very much for your suggestions and help though, you've been really helpful!

You should be able to do something like this in the damage formula:
Ruby:
dam = a.atk * 4 - b.def * 2; a.mp+=(dam*0.1).to_i; b.mp-=(dam*0.1).to_i; dam

Change a.atk * 4 - b.def * 2 to whatever your formula should be. This way you're setting the amount at the start, using it for the MP drain and then using it for the damage at the end. (dam*0.1).to_i gets 10% of the damage formula amount. Just bear in mind that it won't take into account any skill variance amount.

That looks like an interesting formula indeed, I never faced a formula with "dam" parameter.
I will definitely give it in try later, finger-crossed it'll do the magic!
Thank you very much for your help!
You're basically creating a local variable called dam and using that to store the damage formula; you can call it whatever you want, e.g. x, as long as it isn't already an existing method (e.g. things like def, atk, if). It needs to be short for sake of the damage formula. But this might be more information than you care about, haha.

Original thread: https://forums.rpgmakerweb.com/threads/mp-absorb-attack-for-weapon-type.123358/