RMMV State that heals upon recieving damage

Elhijei

Villager
Member
Joined
Jul 17, 2020
Messages
15
Reaction score
25
First Language
French
Primarily Uses
RMMV
Heyo! :) I'm facing a little issue which I feel should be simple, but has had me stuck for the past few hours...

Using Yanfly's Buffs & States Core and their Thornmail trick I thought about making a Guard command that heals x% the user's HP when getting hit. Everything works until the healing part occurs. Here's what's written in my State note:

<Custom React Effect>
if (value > 0) {
var heal = target.mhp * 0.1;
var heal = Math.ceil(heal);
target.gainHp(heal);
}
</Custom React Effect>

If I write user.gainHp(heal), the ennemy is indeed healed 10% of the character's hp, so the problem doesn't seem to come from above. But for some reason when I put target (or defender, or actor, or even $gameActors.actor(2) ) it doesn't work. I tried using <Custom Respond Effect> but to no avail.

As someone who doesn't know javascript, I was quite proud of "successfully" tweaking the Thornmail code from guessing what each line does, but now I'm stuck and I don't even understand why... :kaocry:
 

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,493
Reaction score
1,082
First Language
English
Primarily Uses
RMMV
Try this:
JavaScript:
<Custom React Effect>
if (value > 0) {
var heal = Math.ceil(target.mhp * 0.1);
target.gainHp(heal);
}
</Custom React Effect>
I think the issue was that you had "var heal" twice so the 1st instance got ignored, or rather replaced by the subsequent "var heal".
 

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
836
Reaction score
464
First Language
Poland
Primarily Uses
RMMV
I took liberty and I made some additional fixes to your code @Frostorm :) Of course, it will work, but I'm bad at explaining things, so I belive you understand my fix :)

Code:
<Custom React Effect>
if (this.isHpEffect()){
if (value > 0) {
var heal = Math.ceil(target.mhp * 0.1);
target.gainHp(heal);
}
}
</Custom React Effect>
All I can say, without that condition isHpEffect() if the spell would damage MP instead of HP, target still would recieve some healing values.
 

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,493
Reaction score
1,082
First Language
English
Primarily Uses
RMMV
All I can say, without that condition isHpEffect() if the spell would damage MP instead of HP, target still would recieve some healing values.
Yes, I personally always include "isHpEffect" as well, but I didn't in this case since OP didn't. Here's a more streamlined version:
JavaScript:
<Custom React Effect>
if (value > 0 && this.isHpEffect()) {
var heal = Math.ceil(target.mhp * 0.1);
target.gainHp(heal);
}
</Custom React Effect>
 

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
836
Reaction score
464
First Language
Poland
Primarily Uses
RMMV
Also also, this still isn't perfect though. When state is in effect and you use for example healing item - now I'm not 100% sure, because I don't have single state that uses <custom react effect> - but someone (enemy or caster) will recieve additional healing value upon using healing potion (item) :)
 

Frostorm

[]D[][]V[][]D aka "Staf00"
Veteran
Joined
Feb 22, 2016
Messages
1,493
Reaction score
1,082
First Language
English
Primarily Uses
RMMV
Also also, this still isn't perfect though. When state is in effect and you use for example healing item - now I'm not 100% sure, because I don't have single state that uses <custom react effect> - but someone (enemy or caster) will recieve additional healing value upon using healing potion (item) :)
Hmm, isn't that why we included "value > 0"? So that only stuff that decreases HP would trigger the effect. A healing pot would have a value < 0 (i.e. a negative value). So it should be fine, however, if an item did have a negative value (drinking a poison potion maybe? lol) then that would probably trigger the effect. Maybe this might work though:
JavaScript:
<Custom React Effect>
if (value > 0 && this.isHpEffect() && (this.isPhysical() || this.isMagical())) {
var heal = Math.ceil(target.mhp * 0.1);
target.gainHp(heal);
}
</Custom React Effect>
 

Elhijei

Villager
Member
Joined
Jul 17, 2020
Messages
15
Reaction score
25
First Language
French
Primarily Uses
RMMV
Wow thank you two for the quick replies!

I didn't think healing would be issue but just in case I'll leave it there ! I didn't even think about MP damage, something I would have realised much much later, if at all haha

I tried the last code but it still won't target my character somehow. Though everything before seems to work since I also tried with "user" and it did heal the mob... I guess shortening the var heal doesn't hurt anyway :D
 

Soulrender

Jack Of All Trades
Veteran
Joined
Jan 12, 2019
Messages
836
Reaction score
464
First Language
Poland
Primarily Uses
RMMV
@Frostorm Variable "value" stores actual damage dealed to battler and isHpEffect() checks if hp was damaged/healed because game engine treats at the same category (level) healing/damaging items and the skills. For example, this is my state, wich gives an actor exp from half the damage he deals to enemy:
Code:
<Custom Establish Effect>

if (this.isHpEffect() && value > 0){

user.gainExp(Math.floor(value * 0.5));

$Soulrender.sayPop("\\i[159] Andvari's ring gave to " + user.name() + "  " + Math.floor(value * 0.5) + "XP");

}

</Custom Establish Effect>
when i used healing potion my actor lost 100XP (potion heals 200HP), so that's why is so important to check some certain factors before applying effect.
 

Elhijei

Villager
Member
Joined
Jul 17, 2020
Messages
15
Reaction score
25
First Language
French
Primarily Uses
RMMV
So I used a different method, it works! But it's the clunkiest thing I've ever seen. From a player point of view it's actually quite good, but god the system is terrible :LZSlol:

JavaScript:
<Custom React Effect>
if (value > 0 && this.isHpEffect() && (this.isPhysical() || this.isMagical())) {
$gameTemp.reserveCommonEvent(27);
}
</Custom React Effect>
This Common Event forces an action. I use that bodgy method quite a lot so I have a dedicated invisble character (turns out the action works even if the actor isn't in the party).
So they use an action, in the note tag of which there is this bit (from Yanfly's Action Sequence):

<target action>
animation 201: character 2
HP +10%: character 2, show
</target action>

Now if it were just me I'd call it a day :LZSangel: It works, there's no delay and I could even add a little animation, but I understand it's quite the mess. Being able to force the action immediatly from the Custom Reaction would a be a plus (but I don't understand the force action script call).

Luckily in my case, there's only one character able to do this, but if someone were to try something similar in a job based game, that wouldn't work, unless they make a different state for each character... Quite tedious. And it wouldn't even work for mobs.

I'm still annoyed the target.gainHp(heal) didn't work. If "target" was propely selected when defining the varariable mhp * 0.1, why didn't it work when actually healing? Javascript will forever remain a mystery to me :LZSoops:
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Oh no. That moment when you try to fix something you modified in your game, like, a year ago but didn't want to fix then, and you now have no idea what you even did. Me right now, trying to figure out why my gold window is over stretched?
LittlePIGGY wrote on atreyoray's profile.
Where are you TT^TT
We need ARP_InGameManual for MZ
Oh my gosh. Thank you, Macy's! Thank you so much! You have made me very happy!
Happy Thanksgiving everyone! What are you thankful for? I'm thankful that I no longer have PTSD, and that I get to enjoy a good meal with my mom and stepdad! It might not be the same as before COVID, but at least I still get to enjoy the holiday!

Forum statistics

Threads
105,549
Messages
1,014,556
Members
137,225
Latest member
Eryndor
Top