I want to make a skill that deals damage to an enemy and heals the user by the equivalent amount of health. Any ideas? I'm willing to edit the script but I'm hesitant to since I'm not familiar with the code, though I am familiar with coding in general.
Drain Health From Enemy
RPG Maker XP SupportYou'll want to make the addition in Game_Battler 3. It needs to go (shortly) after the "Subtract Damage from HP" block (specifically, sometime shortly after this line: " effective |= self.hp != last_hp ").
Here's the coding I used for my similar skill:
# Drain Needles Processing if skill.id == 97 user.damage = [(0 - [last_hp, self.damage].min/2),0].min user.hp -= user.damage user.damage_pop = true endChange 97 to whatever the Skill ID is. Note that user.damage is a construct for the skill's user to keep track of how much health they're about to heal - it is self.damage that pulls in the amount of damage you did to your target. For your skill, you can simply set the formula to: user.damage = self.damage because you want to heal an amount equal to damage dealt (my more complicated formula heals half of either the damage dealt or the amount of HP the target had remaining - whichever is smaller). The next line does the actual change to the skill user's HP. The final line allows the player to see how much damage the user healed by giving them their own damage popup.
Here's the coding I used for my similar skill:
# Drain Needles Processing if skill.id == 97 user.damage = [(0 - [last_hp, self.damage].min/2),0].min user.hp -= user.damage user.damage_pop = true endChange 97 to whatever the Skill ID is. Note that user.damage is a construct for the skill's user to keep track of how much health they're about to heal - it is self.damage that pulls in the amount of damage you did to your target. For your skill, you can simply set the formula to: user.damage = self.damage because you want to heal an amount equal to damage dealt (my more complicated formula heals half of either the damage dealt or the amount of HP the target had remaining - whichever is smaller). The next line does the actual change to the skill user's HP. The final line allows the player to see how much damage the user healed by giving them their own damage popup.
Thanks. Slotting that exact piece of code in worked just fine. Coincidentally it was even at the same skill id. I now understand the code a bit better too. One minor issue, design more than anything else, but it heals the user before it deals damage to the target. I'd prefer to heal after dealing the damage so it looks like its draining the energy. I imagine it's just a case of moving the code somewhere else but if its more complicated than that then it's no big deal.
No way! It was skill #97? XD
Yeah, I think it's because I immediately set damage_pop to true here for the user, whereas it's a bit later on in the processing that it's set for the target. There are certainly ways to flag that it should be triggered later, and then trigger it later, but they're more complicated than what I gave you here and it's been a while since I've scripted with XP so it's not really something I can help you with.
Ah cool then. No problem. I can officially declare this issue solved.
Original thread: https://forums.rpgmakerweb.com/threads/drain-health-from-enemy.46024/