Status
Not open for further replies.

Sirius270

Veteran
Veteran
Joined
May 2, 2020
Messages
113
Reaction score
44
First Language
English
Primarily Uses
RMMV
Hello, fellow game makers! I hope that you all had/are having a restful weekend.
I'm trying to make a set of active spells/skills that heal when used on an ally (state 30), but do damage to any enemies which are undead (state 301). The method I'm using works, but it displays a 0 value for the healing, even when it heals. How do I get around this?
Script in battle formula:
if(b.isStateAffected(301)){20+a.mat*5-b.mdf;} else{b.gainHp((b.mhp)/2); 0}
Script in Note area:
<Max Mastery Level: 20>
<Target: Everybody>
<Custom Select Condition>
if (target.isStateAffected(301) || target.isStateAffected(30))
{condition = true;}
else {condition = false;}
</Custom Select Condition>
1638162171816.png
 

kirbwarrior

Veteran
Veteran
Joined
Nov 13, 2014
Messages
1,056
Reaction score
902
First Language
English
Primarily Uses
N/A
You can have 300+ states? Wow. I guess that makes sense, still, you learn something every day.

Just at a glance, I'm confused as to the 0 there at the end of the script, it looks like it'll just be 0 always. And the semicolons seems oddly placed with the brackets;

if (b.isStateAffected(301)) 20+a.mat*5-b.mdf; else b.gainHp(b.mhp/2);

is what I would use, but I'm also not sure that the damage formula can heal when it's set to damage. Based on the commands used in notes, I'm assuming you're using Yanfly stuff and that will let you put healing into the notes instead of the damage formula if the above changes don't work.

If you want to make absolute certain the damage formula can heal, replace the half max HP with a flat number just for testing's sake.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,169
Reaction score
2,546
First Language
English
Primarily Uses
RMMV
You're seeing a 0 because the last number you have is 0.
If you want to try to do it this way, instead of using a gainHp call, just return a negative damage amount.

However, with a few plugins you have access to a much more elegant solution:

Just a few tips for the rest of your code, as you progress in writing things:
- if, else and loops automatically apply to the next single code statement. So it doesn't hurt anything, but you don't need to make a code block with braces, you can just do:
Code:
if (target.isStateAffected(301) || target.isStateAffected(30))
    condition=true;

- Any time you find yourself using a conditional only to set the value of a boolean, you can always skip that since the conditional evaluates to a boolean value itself. Thus, your entire notetag could read:
Code:
<Custom Select Condition>
condition=target.isStateAffected(301) || target.isStateAffected(30);
</Custom Select Condition>

if (b.isStateAffected(301)) 20+a.mat*5-b.mdf; else b.gainHp(b.mhp/2);
that will, I'm pretty sure, also display a 0, as the damage formula always uses the value of the most recent code statement (which would be the gainHp method, which returns no value).
 

kirbwarrior

Veteran
Veteran
Joined
Nov 13, 2014
Messages
1,056
Reaction score
902
First Language
English
Primarily Uses
N/A
that will, I'm pretty sure, also display a 0, as the damage formula always uses the value of the most recent code statement (which would be the gainHp method, which returns no value).

I refer to this site whenever I need a refresher, but I'm pretty sure that's also how I've used If/then statements in damage formulae and it worked fine.

However, with a few plugins you have access to a much more elegant solution:
Wow, that's really elegant.

Another option is to have "healing" spells do actual damage, then use passive states to make it so nonundead absorb the healing. I've done that before, especially because I wanted undead to only take damage from "holy" healing but still be healed by any other element. Mind, that requires more plugins and is more complicated, so if you want something simple, the above does that.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,169
Reaction score
2,546
First Language
English
Primarily Uses
RMMV

I refer to this site whenever I need a refresher, but I'm pretty sure that's also how I've used If/then statements in damage formulae and it worked fine.
That site is saying the same thing I said?
But only last number in the formula deals damage.

Using if/else or ternary statements will work fine, but it will always pass the evaluation of the last code statement to the damage formula. There's no way, just within the damage formula, to make it not do anything. Thus, if the last thing you do is a function call that doesn't return a value, it will still display a 0.
 

Sirius270

Veteran
Veteran
Joined
May 2, 2020
Messages
113
Reaction score
44
First Language
English
Primarily Uses
RMMV
@ATT_Turan
You're always saving me! Thank you! If I don't put that 0 in there, then the game crashes and says that there's a non-finite value, so that's why I had it there. The damage part was/is working perfectly, even displaying the value. For whatever reason, when I set the damage to negative (to heal), it comes out as 0 - not healing anything for my allies, but still doing damage to my enemies with the Undead state. Therefore, I will move on to using the Undead Plug-In. I'm already using all the prerequisites and should have purchased it already, so that should be easy enough. Thank you!
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,169
Reaction score
2,546
First Language
English
Primarily Uses
RMMV
For whatever reason, when I set the damage to negative (to heal), it comes out as 0
The reason is probably basic error-checking in the engine. After all, if you had a really basic damage calculation like a.atk-b.def and you hit an enemy with a greater defense than your attack, you wouldn't want it to heal them, right?
Therefore, I will move on to using the Undead Plug-In.
Yeah, that should handle it neatly and you won't need any shenanigans in your formula.
 

kirbwarrior

Veteran
Veteran
Joined
Nov 13, 2014
Messages
1,056
Reaction score
902
First Language
English
Primarily Uses
N/A
Using if/else or ternary statements will work fine, but it will always pass the evaluation of the last code statement to the damage formula. There's no way, just within the damage formula, to make it not do anything. Thus, if the last thing you do is a function call that doesn't return a value, it will still display a 0.
I probably misinterpreted your first statement then. The skill, as is, can only target either a battler with the "undead" state or the "ally" state, then the damage formula checks if they have the "undead" state. I'm not sure how it would show a 0 because of if/then. I did assume it would show a 0 for;

For whatever reason, when I set the damage to negative (to heal), it comes out as 0 - not healing anything for my allies, but still doing damage to my enemies with the Undead state.
HP damage has a minimum of 0. This is to prevent cases such as "a.atk - b.def" healing the target when defense is higher than attack. To fix that, I think you'd want something like the Damage Core by Yanfly.

I'm already using all the prerequisites and should have purchased it already, so that should be easy enough.
For others reading this thread, both plugins required for Undead are part of the free bundle.
 

ATT_Turan

Forewarner of the Black Wind
Veteran
Joined
Jul 2, 2014
Messages
4,169
Reaction score
2,546
First Language
English
Primarily Uses
RMMV
I probably misinterpreted your first statement then.
No problem. I was referring to your suggestion of:
if (b.isStateAffected(301)) 20+a.mat*5-b.mdf; else b.gainHp(b.mhp/2);
That "else" condition would still make a 0 appear as a damage popup because the last code statement (b.gainHp) has no value.

You can test this really easily, go to your attack skill and change the damage formula to a.gainHp(100)
When you hit an enemy, you'll see a healing popup for 100 over your character, and a damage popup of 0 over the enemy.
 

Sirius270

Veteran
Veteran
Joined
May 2, 2020
Messages
113
Reaction score
44
First Language
English
Primarily Uses
RMMV
@ATT_Turan; Worked like a charm! Thank you!
Yes... the Undead piece by Yanfly is free, and is not a plug-in, but just something you put in the Notes section of the state in your game. I also was able to customize the damage to fit my previous model. Thank you, again!
 

kirbwarrior

Veteran
Veteran
Joined
Nov 13, 2014
Messages
1,056
Reaction score
902
First Language
English
Primarily Uses
N/A
That "else" condition would still make a 0 appear as a damage popup because the last code statement (b.gainHp) has no value.
Gotcha, yes, I forgot to say something about that. That would be a side effect of doing it that way. Now things make sense.
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
3,552
Reaction score
2,668
First Language
EN
Primarily Uses
RMMZ
If I don't put that 0 in there, then the game crashes and says that there's a non-finite value, so that's why I had it there.
I think it's YEP Damage Core that does this: last time I checked, its default parameter setup removes the "replace not-a-number with 0" safety check from the core scripts. Can help to catch errors, but is otherwise a bit of a nuisance. :kaoslp:

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Happy RPG Making! :kaohi:
 
Status
Not open for further replies.

Latest Threads

Latest Posts

Latest Profile Posts

ngl i feel like im morbin out
I've made a lot of small changes and fixes over the past couple weeks without actually making any progress on my game...now I'm running out of things I want to change, and I'm terrified that I might have to start being productive again...the horror! D:
I made a mini devlog about the sprite animations I've been working on! You can read it by clicking here


applebuds-dreamtrotter.gif
What happens with this list, is it currently possible to buy any of these RPGMAKER at least those that are for PC?

Combat skill combination demostration

Forum statistics

Threads
122,203
Messages
1,147,231
Members
160,471
Latest member
sanguine1038
Top