Negative MP plugin?

I'm trying to make it possible for actors to have negative MP.
For example: A skill costs 8 mp but the actor has 4 mp. The actor can use the skill but it puts the MP at -4.
I want it to be impossible for the actor to cast any more magic skills until the MP number is positive.

I did see one plugin that achieved this. However the plugin made it so the actor cannot cast magic, attack and guard.
However the plugin made it so the actor cannot cast magic, attack and guard.
that sounds as if you simply configured the plugin in the wrong way, so it might be better to give a link to the plugin and work on bughunting its configuration.
Copy and paste this into a text editor, save it as a *.js file, install it as a plugin:
Code:
Game_BattlerBase.prototype.canPaySkillCost = function(skill) {
    return this._tp >= this.skillTpCost(skill) && this._mp > 0;
};
Copy and paste this into a text editor, save it as a *.js file, install it as a plugin:
Code:
Game_BattlerBase.prototype.canPaySkillCost = function(skill) {
    return this._tp >= this.skillTpCost(skill) && this._mp > 0;
};
Sorry, but It doesn't seem to work for me.
I still can't cast a skill that has a higher mp cost than my mp.
that sounds as if you simply configured the plugin in the wrong way, so it might be better to give a link to the plugin and work on bughunting its configuration.
https://github.com/InBlast/Plugins/blob/master/IB_NegativeMana.js
This is the plugin I was talking about.
The plugin only has configuration for the UI and what state to apply when the MP is negative.
Even when I don't enter any state it still blocks all of the battle options.
I dunno what to say, it works perfectly for me.
Screenshot 2023-02-24 133750.jpg

Although it does reset MP back to 0 a moment later, so you also need to add this:
Code:
Game_BattlerBase.prototype.refresh = function() {
    this.stateResistSet().forEach(function(stateId) {
        this.eraseState(stateId);
    }, this);
    this._hp = this._hp.clamp(0, this.mhp);
    this._mp = Math.min(this._mp, this.mmp);
    this._tp = this._tp.clamp(0, this.maxTp());
};

Did you save your project and start a new game after installing the plugin? Try turning off all other plugins, or moving this to the bottom.
Even when I don't enter any state it still blocks all of the battle options.
perhaps it is neither that plugin nor one other, but a misconfiguration on your skills?
can you give screenshots of your skills #1 and #2? Full database screenshots please, nothing cut away.
It's still doesn't work. I even created a new project. Maybe I pasted it wrong or something?
Here's a screenshot of the file opened in a notepad.
1677264918092.png
perhaps it is neither that plugin nor one other, but a misconfiguration on your skills?
can you give screenshots of your skills #1 and #2? Full database screenshots please, nothing cut away.
This the attack skill.
1677265111301.png

And this is the guard skill.
1677265139617.png
I dunno what to say, it works perfectly for me.
Okay, I got it working.
But... It looks like you were right with this.
perhaps it is neither that plugin nor one other, but a misconfiguration on your skills?
With this plugin the attack and guard don't work either.
However I can't seem to find what's wrong with the skill.
When I disable all the plugins nothing changes.
With this plugin the attack and guard don't work either.
What is "this" plugin? The code I posted for you or the full plugin you linked to above?

However I can't seem to find what's wrong with the skill.
When I disable all the plugins nothing changes.
That means there's absolutely something borked in your project's database. As a general rule, you should avoid editing the defaults (Attack and Guard skills, Knockout state) unless you're confident about what you're doing.

Try making a new project and copying Attack and Guard over from it, make sure your game functions without any plugins running.
What is "this" plugin? The code I posted for you or the full plugin you linked to above?
Sorry for being so unprecise about what I meant. I meant your code.
Try making a new project and copying Attack and Guard over from it, make sure your game functions without any plugins running.
So I made a new project and copied the skills but they still don't work.
And let me make sure we're on the same page here. They only don't work when my MP is 0 or less.
So it's been an issue with the skills all along. I just never got to 0 MP while testing before getting the Negative MP plugins. So sorry for this.

But, I still don't know what's wrong with the skills. Do you have any ideas what could be wrong with it?
How exactly are you testing the skills? Battletest, Playtest with a new game, playtest with an old savefile?
How exactly are you testing the skills? Battletest, Playtest with a new game, playtest with an old savefile?
I am Playtesting with a new game.
But, I still don't know what's wrong with the skills. Do you have any ideas what could be wrong with it?
That's made me think of a potential error in the code I provided, which I'll give a fix for here. But if you're saying this happens when plugins are turned off, no, I don't know what could be wrong.

Possible bug fix:
Code:
Game_BattlerBase.prototype.canPaySkillCost = function(skill) {
    return this._tp >= this.skillTpCost(skill) && (this._mp > this.skillMpCost(skill) || this._mp > 0);
};
Possible bug fix:
Code:
Game_BattlerBase.prototype.canPaySkillCost = function(skill) {
return this._tp >= this.skillTpCost(skill) && (this._mp > this.skillMpCost(skill) || this._mp > 0);
};
So I just paste this on the bottom of the script right?

I don't know what could be wrong.
OKAY, this is weird. So I just found out. That I wasn't turing off the NegativeMP plugin when testing with 0 mp the attack and guard skill. And, when the plugin is off... the skills work.
I'm seriously lost right now. So in the end it's actually the plugin??
But what could be causing this?
One more thing, it's not just the attack and guard skill. It's all of the skills.
I put a skill that doesn't consume any mp and it doesn't work either.
It's still doesn't work. I even created a new project. Maybe I pasted it wrong or something?
Here's a screenshot of the file opened in a notepad.
View attachment 254189
You're missing a closing bracket on line 3 (this: }). In general, every { should always be closed with a }. It's likely that this causes an error and results in some of the weird behaviour you've been getting.
You're missing a closing bracket on line 3 (this: }). In general, every { should always be closed with a }. It's likely that this causes an error and results in some of the weird behaviour you've been getting.
Oh, that was a while ago. The file looks like this right now. But thanks anyway.
1677273882816.png
Oh, that was a while ago. The file looks like this right now. But thanks anyway.
View attachment 254203
So did Turan's fix work? Just replace your current canPaySkillCost with the new one.
That's made me think of a potential error in the code I provided, which I'll give a fix for here. But if you're saying this happens when plugins are turned off, no, I don't know what could be wrong.

Possible bug fix:
Code:
Game_BattlerBase.prototype.canPaySkillCost = function(skill) {
    return this._tp >= this.skillTpCost(skill) && (this._mp > this.skillMpCost(skill) || this._mp > 0);
};

That still wouldn't allow you to cast a 0 mp skill at 0 mp though; you'd need to change that > to a >=. So, possible bug fix for the bug fix:

JavaScript:
Game_BattlerBase.prototype.canPaySkillCost = function(skill) {
    return this._tp >= this.skillTpCost(skill) && (this._mp >= this.skillMpCost(skill) || this._mp > 0);
};
Okay. So now, the attack, guard and other skills work on 0 MP. But they don't still don't work on negative numbers. Just to be clear. I don't have any other plugins enabled, it's on a new project and it's through a playtest on a new game.
The solution for 0 MP to work seemed to be this.
That still wouldn't allow you to cast a 0 mp skill at 0 mp though; you'd need to change that > to a >=. So, possible bug fix for the bug fix:

JavaScript:
Game_BattlerBase.prototype.canPaySkillCost = function(skill) {
return this._tp >= this.skillTpCost(skill) && (this._mp >= this.skillMpCost(skill) || this._mp > 0);
};

Original thread: https://forums.rpgmakerweb.com/threads/negative-mp-plugin.155267/