State Which Prevents MP Loss?

Soryuju

Combat Balance Enthusiast
Veteran
Joined
Apr 19, 2018
Messages
179
Reaction score
213
First Language
English
Primarily Uses
RMMV
I’m interested in making a state which locks the target’s MP to its maximum value for the duration of the state. Is this sort of effect possible to achieve (with or without plugins)?

For context, skills don’t cost MP to use in my project, but certain incoming skills may reduce the target’s MP, amongst other effects. I’m trying to just block all MP reductions on targets with this state.

Thanks!
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
Easiest way to do this is to give all MP reduction attacks their own element (I call mine Mana), then make it that anyone in this state has the element rate Mana * 0%.
 

Soryuju

Combat Balance Enthusiast
Veteran
Joined
Apr 19, 2018
Messages
179
Reaction score
213
First Language
English
Primarily Uses
RMMV
Easiest way to do this is to give all MP reduction attacks their own element (I call mine Mana), then make it that anyone in this state has the element rate Mana * 0%.
Thanks for the answer! Unfortunately, I’m afraid this isn’t working with some of my skills because they deal both HP and MP damage. They use a formula like this:

b.gainMp(-(50 + a.luk)); a.atk * 4 - b.def * 2

So Element Rate 0% reduces the HP damage to 0, but the skill still deals maximum MP damage. If I could reverse it, it would be perfect.

Sorry, I probably should have mentioned that in the original post! I was trying to keep it brief so people wouldn’t have to read an essay about my project.
 

bgillisp

Global Moderators
Global Mod
Joined
Jul 2, 2014
Messages
13,522
Reaction score
14,255
First Language
English
Primarily Uses
RMVXA
You'll have to code in a conditional check then to avoid that. I don't know the code for that but maybe another poster will?
 

Soryuju

Combat Balance Enthusiast
Veteran
Joined
Apr 19, 2018
Messages
179
Reaction score
213
First Language
English
Primarily Uses
RMMV
Update: I think I got it working with Yanfly’s Damage Core! I’ll have to manually put the code into each MP-damaging skill rather than directly into a single state, but otherwise, it’s working the way I’d hoped so far.

The regular damage formula box wasn’t happy about trying to run a conditional branch with the gainMp() command (which could just be user error, honestly), but by using the <damage formula> tags from the Damage Core plugin, I was able to implement the conditional branch successfully. The state itself is just a dummy state with a certain turn duration.

Here’s a simplified version of my code:

<damage formula>
if (target.isStateAffected(44) {
target.gainMp(0);
value = user.atk
}
else {
target.gainMp(-(30 + user.luk));
value = user.atk;
}
</damage formula>
 

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,523
Reaction score
1,415
First Language
English
Primarily Uses
RMMV
You could probably simplify that like so:

<damage formula>
if (!target.isStateAffected(44) target.gainMp(-(30 + user.luk));
value = user.atk;
</damage formula>


Since user.atk is the same regardless of state, there's no need to have it in both conditional branches and unless I'm wrong, there's no reason to call gainMp if there's no MP adjustment being made. For the damage formula line, you could probably even use this:

if (!b.isStateAffected(44)) b.gainMp(-(30 + a.luk)); a.atk
 

Soryuju

Combat Balance Enthusiast
Veteran
Joined
Apr 19, 2018
Messages
179
Reaction score
213
First Language
English
Primarily Uses
RMMV
You could probably simplify that like so:

<damage formula>
if (!target.isStateAffected(44) target.gainMp(-(30 + user.luk));
value = user.atk;
</damage formula>


Since user.atk is the same regardless of state, there's no need to have it in both conditional branches and unless I'm wrong, there's no reason to call gainMp if there's no MP adjustment being made. For the damage formula line, you could probably even use this:

if (!b.isStateAffected(44)) b.gainMp(-(30 + a.luk)); a.atk
Thanks for the suggestions! I’m in the early stages of teaching myself JavaScript, so my attempts at code aren’t the most elegant right now.

The one hiccup is that I do still seem to need something like the conditional branch with value = user.atk; in both sections, or the HP damage is also reduced to 0 when the state is applied. The code you provided works perfectly as is, but some other information I omitted about my specific project was that I’m actually checking multiple versions of the state in the same if statement (&& !target.isStateAffected(45) && !target.isStateAffected(46)). There are probably other ways to fix this as well, but I found that putting the else branch back in with just value = user.atk; does at least get the code working again.
 

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,523
Reaction score
1,415
First Language
English
Primarily Uses
RMMV
The one hiccup is that I do still seem to need something like the conditional branch with value = user.atk; in both sections, or the HP damage is also reduced to 0 when the state is applied. The code you provided works perfectly as is, but some other information I omitted about my specific project was that I’m actually checking multiple versions of the state in the same if statement (&& !target.isStateAffected(45) && !target.isStateAffected(46)). There are probably other ways to fix this as well, but I found that putting the else branch back in with just value = user.atk; does at least get the code working again.
When the damage formula contains an error, rather than throw an exception and halt the game, it just returns 0 and fails silently. In your expression, the && right after the opening parentheses is invalid syntax and will cause an error. Multiple conditions normally doesn't cause any problem in the damage formula. If you post the code you're using, I (or anyone who gets to it before me) can give you some pointers and offer corrections.
 

Soryuju

Combat Balance Enthusiast
Veteran
Joined
Apr 19, 2018
Messages
179
Reaction score
213
First Language
English
Primarily Uses
RMMV
Here’s the code I was trying to use without the else branch:

<damage formula>
if (!target.isStateAffected(44) && !target.isStateAffected(45) && !target.isStateAffected(46)) {
target.gainMp(-(30 + user.luk));
value = user.atk;
}
</damage formula>

The code above runs normally at first, but as soon as the target is affected by states 44, 45, or 46 (all dummy states, just with different durations), it begins to return 0. If I add the else branch with just value = user.atk; then the skill works properly.
 

Aesica

undefined
Veteran
Joined
May 12, 2018
Messages
1,523
Reaction score
1,415
First Language
English
Primarily Uses
RMMV
That's because value = user.atk is in the conditional code block. You'll notice that the version I posted didn't include the curly braces { }. If left out, an if statement will only execute the line directly after it. Here's what I mean:

Code:
if (thing === true)
console.log("Hello");
console.log("World");
If "thing" is true, it will write both Hello and World to the console. If "thing" is false, it will only write World.

Now in contrast:

Code:
if (thing === true)
{
  console.log("Hello");
  console.log("World");
}
If "thing" is true, it will write both Hello and World to the console. if "thing" is false, it will do neither.

If you were to move value = user.atk; above the if statement, or below the closing curly brace, it would work regardless of state.
 

Soryuju

Combat Balance Enthusiast
Veteran
Joined
Apr 19, 2018
Messages
179
Reaction score
213
First Language
English
Primarily Uses
RMMV
@Aesica Ah, I see now. A lot of these programming subtleties are still lost on me, so I appreciate you taking the time to explain! Maybe one of these days I’ll get the hang of it.
 

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

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,083
Members
137,583
Latest member
write2dgray
Top