I'm creating an "Astral Burst" skill that deals magic damage to all enemies (magic hit type, so it can miss) and restores MP to the user based on the number of enemies it deals damage to (so disregard if 0 damage), 5% Max MP per enemy. However, I can't for the life of me get it to work this way. It seems siimple, but I'm struggling with it. I am using all or Yanfly's plug-ins. Please help.
Recover MP based on enemies hit
RPG Maker MV SupportIt would be helpful if you showed what you'd tried.
You should be able to do this with a Yanfly Skill Core notetag:
You should be able to do this with a Yanfly Skill Core notetag:
Code:
<Pre-Damage Eval>
user.gainMp(Math.ceil(user.mmp*.05));
</Pre-Damage Eval>
That should be doable with damage formula coding alone, although some plugins may help.
simply add a command to give the user MP into the damage formula, and it will be executed on every enemy hit.
In fact that is one case where the usually unwanted "on every hit" is being useful, as long as the actor using this is not set to autobattle this would be a perfect case for that.
EDIT: ninja'd
simply add a command to give the user MP into the damage formula, and it will be executed on every enemy hit.
In fact that is one case where the usually unwanted "on every hit" is being useful, as long as the actor using this is not set to autobattle this would be a perfect case for that.
EDIT: ninja'd
I was trying, on the Post-damage Eval, to loop through the target troop and check if the damage dealt was more than zero, and for each member of the troop, restore MP.
<Post-damage Eval> for(var i=0; i<target; i++){ If(target.result().isHit() & value>0){ User.gainMp(Math.ceil($gameActors.actor(1).mmp*0.05); } } </Post-damage Eval>
I couldn't get it on the Damage Formula, I tried
a.mat*0.7+a.gainMp(Math.ceil($gameActors.actor(1).mmp*0.05)) and
a.mat*0.7;a.gainMp(Math.ceil($gameActors.actor(1).mmp*0.05)), but then it will neither deal damage nor restore MP for every enemy, only once.
And then me, the dumbest man alive, remembered it was easily doable with the "effects" area on the skill. LOL.
Though it doesn't give me the popup numbers with my custom HUD, that's a bummer, but the restoration works as intended. So thank you guys.
if you tried to loop, that is the problem.
You don't have to check any enemy for damage in a loop, because that is what the damage formula is for.
in short the code would be something like this:
d=damage formula; if d>0 a.mp+=10;d
Calculate the damage and temporarily store it in a newly defined variable d
check if d does damage, if yes restore mp
do d damage to target
few things going forward.
additionally, those tags already run for each target within the scope. A loop within them for the purpose of iterating over every target in the other troop and doing something in each iteration is going to end up making your effect happen *many* more times than intended.
use a.opponentsUnit().aliveMembers() if you want to something to loop over the enemy troop. i is an integer and target within those tags is a battler. youd never start the loop since you cant actually compare the two.
also, you typed in "User" instead of "user". regardless of how you were doing it, it wouldnt have run
the pre and post damage eval tags dont run if the skill misses, so theres no need to check the results to see if it hit.
additionally, those tags already run for each target within the scope. A loop within them for the purpose of iterating over every target in the other troop and doing something in each iteration is going to end up making your effect happen *many* more times than intended.
use a.opponentsUnit().aliveMembers() if you want to something to loop over the enemy troop. i is an integer and target within those tags is a battler. youd never start the loop since you cant actually compare the two.
also, you typed in "User" instead of "user". regardless of how you were doing it, it wouldnt have run
if you reversed the second one there, it would have done what you wanted actually(ignoring the having to do damage bit). code before the semicolon in the damage formula box runs, but only what comes after the last set of them ends up being the damage formula. Although, if an enemy were to have that skill, or you use autobattle on any actor that has that skill, the mp recovery would happen every time that battler would consider using any skill
Original thread: https://forums.rpgmakerweb.com/threads/recover-mp-based-on-enemies-hit.163035/