Random (and unwanted) MP gain while in auto-battle

Hello, I just noticed that my actors were being granted large amounts of MP while set to Auto-Battle. I don't use any script that affects auto-battle or even battle.

After testing a bit more, it looks like it is related to the a.mp+=n (where n is the amount of MP) in the damage formula that I use to gain MP on some skills. Still, it works fine when not using auto-battle.

Do you have an idea where this MP gain comes from, and how to prevent it?

Thanks
Please confirm: Do you mean the real MP or have you renamed/confused this with TP?

There the only way for MP to be gained would be if there is a MP-Regeneration buff or an script error, but TP is automatically gained by receiving damage, and skills also have a TP-Gain-Value, so this could easily happen due to a wrong value in one of the skills if it's TP that is increased.

Also, please provide a number - we don't know what "large amounts of MP" are for your game - there are games where the actors never have more than 40 MP, and other games where the actors start with 100 and have skill costs that can be several hundred for later skills. With a number as an example we can better tell where that can come from, because some sources are more likely for higher or for lower totals.

And please test this with a temporary actor that has no skills - if such an actor doesn't increase in autobattle, it's often a case of wrong values in skills - if it happens to them as well it's either a problem with the attack skill or in the scripts/engines.

EDIT:

You hadn't added the "after testing" info yet when I wrote the above.

If you placed such a line in some damage formulas, then that is most likely the cause - please post screenshots of those skills, test if that happens when the actor's don't have those skills and check that you didn't accidentally copy that command into a skill not intended for it's use.

Most probably the autobattle focuses on using one of the skills with that option and uses that more often than any intelligent player would use it...
By large amounts I mean 15 to 90 MP, when my characters have 100 max MP. I am not confusing it with TP; I didn't rename either.

I'll explain in details what happens, turn by turn.

Character uses Attack (ID#1 skill, default, no MP gain there, only TP) until another skill becomes available.

Character uses a skill that has a damage formula looking like " a.mp+=5;damageFormula " so this character gains 5 MP with the skill after it hits, rather than giving MP to the target.

Then no matter what the character does, Attack (no MP gain intended) or special skill (with 5MP gain after the attack hits), its MP are increased (+15MP) before the skill hits.

And again, except the amount of unwanted MP seems to double each time. On some occasions, this unwanted gain doesn't happen.

So it is obviously when a "a.mp+=n" skill is used that the problem occures, but I still don't know why.
So when you take out that "a.mp += 5" it doesn't happen anymore?
Auto battle does a 'test-run' evaluation through the skill list to determine which one to use. This test run evaluates the formulas, and since simply evaluating the formula will add MP to the subject in this case, you are getting the extra MP. Other testing is first done to determine if the action is valid before it is tested, which also explains why you are sometimes getting less or none. Each potential target is tested, so the formula may be run several times in one test.


You should be able to get around this by cloning the action subject for the test runs (in Game_Action#evaluate_item_with_target, try changing subject to subject.clone).
Mithran's explanation makes sense. I knew the auto-battle evaluates the skills, but I didn't know it would actually have an effect on the game.

Testing on a clone instance works, so problem solved, thanks!
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.

Original thread: https://forums.rpgmakerweb.com/threads/random-and-unwanted-mp-gain-while-in-auto-battle.18034/