Skill that targets dead enemy, restores user HP, then "erases" dead enemy?

Trying to achieve something like the persistent corpses in "Darkest Dungeon" (https://darkestdungeon.gamepedia.com/Corpse) where enemies leave a corpse on the battlefield that preserves the original rows/formations until it is destroyed by the player or disappears over time.

I also want a PC skill, "Scavenge", that ONLY targets dead enemies, consuming the dead enemy for half of its max HP and then destroying the corpse/removing the enemy from the battlefield.

I've got the dead enemies remaining on the battlefield rather than disappearing using YEP_X_Animated Sideview Enemies and custom "dead" animations in the spritesheet.

Today I tried making a custom "Corpse" state that basically mimics the "Knockout"/dead state, and a "Scavenge" skill that can only target the "Corpse" state using Target Core and Selection Control commands. Using Troop controls I have it set so if an enemy reaches 0 HP the "Knockout" state is removed, a tiny amount of HP is restored, and the "Corpse" state is applied. I set "collapse" back to true for the "Knockout" state so when enemies are hit in the "Corpse" state they automatically go to the "Knockout" state and disappear.

This seems to kinda sorta work, up until the point I actually use Scavenge on an enemy; it displays the animation and plays the sound, then the game crashes with an error message.

How would you go about achieving this gameplay? What am I doing wrong with my approach? Is there a simpler approach? Thanks!
well I see that your damage formula is wrong/mistyped

part of it says b.mph

should be b.mhp

did you fix that part yet?
I will follow this thread as I want to create some necromocian skill with the possibilities to ressurect an enemie and apply a "controle" state 🙂
well I see that your damage formula is wrong/mistyped

part of it says b.mph

should be b.mhp

did you fix that part yet?


Thanks lol, that instantly solved the crash. I'm glad it was something simple. The formula was still wrong though since it sets the user's HP to exactly half the enemy's total HP, what I actually wanted was to add half the enemy's total HP to the user's current HP, and in only whole numbers/integers:

a.setHp(a.hp + Math.round(b.mhp / 2))

Everything seems to be working as I'd expect it at this point. Thanks again!

Original thread: https://forums.rpgmakerweb.com/threads/skill-that-targets-dead-enemy-restores-user-hp-then-erases-dead-enemy.120911/