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!
State Which Prevents MP Loss?
● ARCHIVED · READ-ONLY
-
-
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%.
-
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. -
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?
-
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> -
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 -
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. -
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.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.
-
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. -
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. -
@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.