Trying to increase a variable based on a class's mana use

Essentially, I want to increase a variable based on the amount of mana that a specific character uses. So if their mana bar goes down by 10, I want the variable to go up by 10.

I know you can adjust the damage formula in order to do this, but I don't want this to happen every single time a character uses a spell. While I can just make different versions of each spell, some for the class I want this to happen with and some for the others, that seems like a huge pain.

I figure a common event can be written to make this work, with an conditional statement that makes it only apply to the single class, but I cannot seem to figure out how to set it up so that this works right.
It's possible.

Just so that I understand it clearly, you don't want the variable increases for all spells, only certain spells?

Yeah, a common event would work best, and you would just need to add it to the spells you *want* the variable event to trigger.

You could do a math way, like - current from new, etc, or you could add multiple common events to increase the variable to each skill, each being different dependent on the MP cost?
It's possible.

Just so that I understand it clearly, you don't want the variable increases for all spells, only certain spells?

Yeah, a common event would work best, and you would just need to add it to the spells you *want* the variable event to trigger.

You could do a math way, like - current from new, etc, or you could add multiple common events to increase the variable to each skill, each being different dependent on the MP cost?
I'd like it specifically when a certain character casts a spell. So when Max casts fire for 5 mana, I'd like the variable to go up by 5. If someone else does, I don't want the variable to move.

I was hoping there would be a way to write a common event that checked the cost of the spell and then added that number to the variable in question.
The hardest thing I can think about with this as a common event is getting the MP cost after any trait adjustments.

That said, doing this via a plugin would be fairly simple.
(You'd need this to track a specific Actor, not an actor's class, right? There IS a difference.)
I'd like it specifically when a certain character casts a spell. So when Max casts fire for 5 mana, I'd like the variable to go up by 5. If someone else does, I don't want the variable to move.

I was hoping there would be a way to write a common event that checked the cost of the spell and then added that number to the variable in question.

Yeah I would at that point make a separate skill for that class if you want to keep it simple.

But it also depends, can your character change classes at all?
The hardest thing I can think about with this as a common event is getting the MP cost after any trait adjustments.

That said, doing this via a plugin would be fairly simple.
(You'd need this to track a specific Actor, not an actor's class, right? There IS a difference.)

Just the specific actor, yes.

OK, so what would the plugin look like? Define the variable being used, identify the actor in question, track their mana usage, and then plug that into the variable somehow?

Yeah I would at that point make a separate skill for that class if you want to keep it simple.

But it also depends, can your character change classes at all?
No class changes. Honestly, I was hoping to avoid having to double up on skills like that as it would be a pain to keep track of. I imagine it would be easier in the long-term to be able to automate it through a common event or something like that.
In a word: yep

If you know which actor ID and the variable number you want, I could throw a snippet together for ya. It should only take a few minutes.
In a word: yep

If you know which actor ID and the variable number you want, I could throw a snippet together for ya. It should only take a few minutes.
Honestly, I'm still in the phase where I'm figuring out how to do all the stuff I want to do. Can probably just say it's actor 1 and variable 3.
Ok.

So I made a snippet that counts the MP use for ALL actors.
(Separate totals, of course.)

So just drop this into your project:
LINK

The plugin will automatically tally MP use for each actor.

To put the number into a variable, use the script call:

JavaScript:
$gameParty.getActorMPCount(x)

Where X is the actor ID number in the database.
(You'll need to start a new game to make sure this works properly.)

Let me know if you need anything more with this.
(I was thinking you might not want it to work from the menu or for certain skills.
You can let me know if that is the case.)
Ok.

So I made a snippet that counts the MP use for ALL actors.
(Separate totals, of course.)

So just drop this into your project:
LINK

The plugin will automatically tally MP use for each actor.

To put the number into a variable, use the script call:

JavaScript:
$gameParty.getActorMPCount(x)

Where X is the actor ID number in the database.
(You'll need to start a new game to make sure this works properly.)

Let me know if you need anything more with this.
(I was thinking you might not want it to work from the menu or for certain skills.
You can let me know if that is the case.)
Well, the idea is it's supposed to force the player to limit the MC's mana usage so ideally it would also track from the menu.

What I am interested in is figuring out how it works exactly so I can customize it a bit if needed. So if you could explain what each of the four parts do?
Do you intend to use this variable during the battle or afterwards? Because it's not difficult to do this using only events.
It's a snippet, so I can explain it a bit.

JavaScript:
var MalMPCGPInit = Game_Party.prototype.initialize

Game_Party.prototype.initialize = function() {

    this._actorMPCount = [];

    MalMPCGPInit.call(this);

};

This part just creates the data structure for holding the count and is made on starting a new game.

JavaScript:
var MalMPCpaySkillCost = Game_BattlerBase.prototype.paySkillCost;

Game_BattlerBase.prototype.paySkillCost = function(skill) {

    MalMPCpaySkillCost.call(this, skill);

    if (this._actorId) this.countMP(this.skillMpCost(skill))

};

This is an alias of the process that removes MP when it is spent on a skill.
I inject a new function here to collect the spent MP data.
(It checks to see if the skill user is an Actor before moving forward so this does not work with enemies.)

JavaScript:
Game_BattlerBase.prototype.countMP = function(count) {

    var id = this._actorId;

    if (!$gameParty._actorMPCount[id]) $gameParty._actorMPCount[id] = 0;

    $gameParty._actorMPCount[id] += count;

};

This will check to see if the count has been set yet and will first set it to 0.
After that it add the value of the MP spent on the skill.
(Coding-wise, there is a way to preset the array to be 0, but I didn't remember how, so I did it this way.)

JavaScript:
Game_Party.prototype.getActorMPCount = function (id){

        if (!$gameParty._actorMPCount[id]) $gameParty._actorMPCount[id] = 0;

        return $gameParty._actorMPCount[id];

}

This is the function that returns the value stored for the Actor you want.
Again, it creates a 0 if the count was not changed previously to avoid crashes if you were to try to use the value as a number before the number was actually there.

Hope this helps.

Do you intend to use this variable during the battle or afterwards? Because it's not difficult to do this using only events.
I wouldn't mind seeing how you'd handle this. How would you capture the value?
I wouldn't mind seeing how you'd handle this. How would you capture the value?
Comparing the difference and then adding it to the main variable:
RMMZ-MPCheck.png


RMMV and RMMZ only show the variable names in Conditional Branches, so it can be confusing. See here for a clearer explanation:
Spoiler
Code:
◆Control Variables:#0001 MP Current = MP of Reid
◆If:#0002 MP First read is OFF
  ◆Control Variables:#0002 MP Last = MP of Reid
  ◆Control Switches:#0002 MP First read = ON
  ◆
:End
◆If:#0001 MP Current < #0002 MP Last
  ◆Control Variables:#0003 MP Calc Function = #0002 MP Last
  ◆Control Variables:#0003 MP Calc Function -= #0001 MP Current
  ◆Control Variables:#0004 MP (Total spending) += #0003 MP Calc Function
  ◆Comment:######## Turns off the "Conditional branch" ########
  ◆Control Variables:#0002 MP Last = #0001 MP Current
  ◆
:End

The Switch is just to avoid repeating the reading. This takes into account the player's current MP even if it's not at the maximum for the current level.

In my opinion, the OP needs something simple for something in their project, so creating a complex plugin might not be the best solution.
I see. That would work I think. Unless I'm missing something, it looks pretty sound.

There's this monster in my game that does the equivalent of MP poison on my party...

Original thread: https://forums.rpgmakerweb.com/threads/trying-to-increase-a-variable-based-on-a-classs-mana-use.180922/