How could I set up a skill so that it drains HP?

Basically, I want the skill to drain MP normally, but if the character doesn't have enough MP, to drain HP instead. Is there a way to do this?
Absolutely!
You could do this by having the skill trigger a common event that contains a conditional statement comparing the value you're draining to the current MP of the caster. You'll need to assign/update variables ahead of time, to represent the caster's actor ID and their current MP in the conditional statement.

Plugins such as Yanfly Skill Core, which lets you control a lot of this stuff through note tags in the skills/actor databases, will make this much more efficient.

If you do use Yanfly's skill core plugin, I think I've got a script you can drop in the skill's notebox to set it up without needing any common events... but I don't know where it's at in my notes, and I've been away from RMMV for much too long to write it from memory with any amount of accuracy XD so that'll have to wait
Absolutely!
You could do this by having the skill trigger a common event that contains a conditional statement comparing the value you're draining to the current MP of the caster. You'll need to assign/update variables ahead of time, to represent the caster's actor ID and their current MP in the conditional statement.

Plugins such as Yanfly Skill Core, which lets you control a lot of this stuff through note tags in the skills/actor databases, will make this much more efficient.

If you do use Yanfly's skill core plugin, I think I've got a script you can drop in the skill's notebox to set it up without needing any common events... but I don't know where it's at in my notes, and I've been away from RMMV for much too long to write it from memory with any amount of accuracy XD so that'll have to wait
This is an RPG Maker MZ question, but I am assuming VisuStella has something similar, I just cannot find how to make it work.
I try and make a skill use a common event that then either subtracts HP or MP depending on if the character has enough MP, but the common event doesn't do anything at all. Not sure why.

Either way, thank you, because you mentioning Yanfly Skill Core made me realize I was looking at the wrong plugin altogether (Battle Core) when I should be looking at Skill Core. ^^''

I also noticed I didn't put MZ as my engine since i upgraded last year >.>' I am getting forgetful in my 40s, damn...
This is an RPG Maker MZ question, but I am assuming VisuStella has something similar, I just cannot find how to make it work.
I try and make a skill use a common event that then either subtracts HP or MP depending on if the character has enough MP, but the common event doesn't do anything at all. Not sure why.

Either way, thank you, because you mentioning Yanfly Skill Core made me realize I was looking at the wrong plugin altogether (Battle Core) when I should be looking at Skill Core. ^^''

I also noticed I didn't put MZ as my engine since i upgraded last year >.>' I am getting forgetful in my 40s, damn...
No worries XD
I don't have experience with MZ and may not be very useful troubleshooting it, but if the event itself doesn't seem to be working, perhaps it might help others to see the problem if you shared screenshots of the event you're trying to run, and maybe the skills database (if you have anything in note tags or the skill tries to do anything other than call on a common event)

*Oh, and also include information about any plugins you're currently using. Since you mentioned VisuStella, perhaps there's someone with knowledge about their plugins who can inform you on how to use it for this purpose or why it might not be functioning properly!
This is an RPG Maker MZ question
Just as a note, if MZ is going to be the engine for your main project, change your primary engine to it too. You did correctly put the thread in the MZ section, sometimes people will see the primary engine and go from there. Just refreshed the page. I see you edited it in 🙂

I try and make a skill use a common event that then either subtracts HP or MP depending on if the character has enough MP, but the common event doesn't do anything at all. Not sure why.
You would have to show us your common event for us to know.

I am assuming VisuStella has something similar, I just cannot find how to make it work.
Try this in your skill's notebox. It should just need the battle core
Code:
<JS Pre-Damage>
target._prevMp = target.mp;
</JS Pre-Damage>

<JS Post-Damage>
if (target._prevMp < value){
  target.gainHp(target._prevMp - value);
  user.gainHp(value - target._prevMp);
}
</JS Post-Damage>
Code:
<JS Pre-Damage>
target._prevMp = target.mp;
</JS Pre-Damage>

<JS Post-Damage>
if (target._prevMp < value){
target.gainHp(target._prevMp - value);
user.gainHp(value - target._prevMp);
}
</JS Post-Damage>
This sadly did nothing. I did ofc edit the values etc.
The thing I want to do is that, basically, any skill can be used with its MP cost. If the user's MP is below the cost, it will instead drain that amount in HP.
I am not good with code, I am trying to figure it out, but all the descriptions online seem to me to require I have good knowledge of javascript. Which I do not have.
The thing I want to do is that, basically, any skill can be used with its MP cost. If the user's MP is below the cost, it will instead drain that amount in HP.
Ah, now that's a different mechanic. When you said it drains MP and should drain HP if there's not enough MP, I believed you were using an MP Drain skill and you wanted the skill to drain the target's HP if they didn't have enough MP.

For costs, you can use this:
Code:
<JS MP Cost>
cost = user.mp >= skill.mpCost ? skill.mpCost : 0;
</JS MP Cost>
<JS HP Cost>
cost = user.mp >= skill.mpCost ? 0 : 500;
</JS HP Cost>
If the battler can pay the MP cost, it's their MP cost. If they can't, the MP cost is waived and it'll have an HP cost instead. Change the 500 in the bottom one for whatever that HP cost should be.
Ah, now that's a different mechanic. When you said it drains MP and should drain HP if there's not enough MP, I believed you were using an MP Drain skill and you wanted the skill to drain the target's HP if they didn't have enough MP.

For costs, you can use this:
Code:
<JS MP Cost>
cost = user.mp >= skill.mpCost ? skill.mpCost : 0;
</JS MP Cost>
<JS HP Cost>
cost = user.mp >= skill.mpCost ? 0 : 500;
</JS HP Cost>
If the battler can pay the MP cost, it's their MP cost. If they can't, the MP cost is waived and it'll have an HP cost instead. Change the 500 in the bottom one for whatever that HP cost should be.
This worked perfectly, thank you!!
I'd like to offer a solution for non VS users as well - make changes as needed:
JavaScript:
(($) => {
    // Alias skill cost to allow overage to drain hp if mp is 0
    const alias = $.paySkillCost;
    $.paySkillCost = function(skill) {
        const cost = this.skillMpCost(skill);
        if (cost > this._mp) {
            this._hp -= cost - this._mp;
            this._mp = 0;
            this._tp -= this.skillTpCost(skill);
        } else {
            alias.call(this, skill);
        }
    }
    // rewrite condition to allow payment for skill based on hp and mp
    $.canPaySkillCost = function(skill) {
        const mpCost    = this.skillMpCost(skill);
        const condition = this._tp >= this.skillTpCost(skill) &&
            (this._mp >= mpCost || this._hp + this._mp >= mpCost);
        return condition;
    }
})(Game_BattlerBase.prototype);

Thanks for double checking @rpgLord69 - updated!
I'd like to offer a solution for non VS users as well - make changes as needed:
JavaScript:
(($) => {
    // Alias skill cost to allow overage to drain hp if mp is 0
    const alias = $.paySkillCost;
    $.paySkillCost = function(skill) {
        const cost = this.skillMpCost(skill);
        if (cost > this._mp) {
            const overage = (cost - this._mp);
            this._hp -= overage;
            this._mp -= cost;
            this._tp -= this.skillTpCost(skill);
        } else {
            alias.call(this, skill);
        }
    }
    // rewrite condition to allow payment for skill based on hp and mp
    $.canPaySkillCost = function(skill) {
        const mpCost    = this.skillMpCost(skill);
        const condition = this._tp >= this.skillTpCost(skill) &&
            (this._mp >= mpCost || this._hp + this._mp >= mpCost);
        return condition;
    }
})(Game_BattlerBase.prototype);
Would this be put into a common event script call? Or can I just put it into note tags without VS?
Would this be put into a common event script call? Or can I just put it into note tags without VS?
My apologies, this would be a separate plugin for your project. Save the code as a .js file (using your text document editor) and load it into your plugin manager.
My apologies, this would be a separate plugin for your project. Save the code as a .js file (using your text document editor) and load it into your plugin manager.
amazing, thank you, if I get frustrated with VS this will be very useful 😀
Note that the VS tags you were given it's either MP or HP (if you can't pay all MP) cost. Your plugin it's HP cost for the part that your actor can't pay as MP.

EDIT: I think you should also edit that mp reduction, because if it's like that, the value can show a negative for a moment, before it updates to 0.
Note that the VS tags you were given it's either MP or HP (if you can't pay all MP) cost. Your plugin it's HP cost for the part that your actor can't pay as MP.

EDIT: I think you should also edit that mp reduction, because if it's like that, the value can show a negative for a moment, before it updates to 0.
It does indeed do that, yeah. As mentioned, I'm not good at coding at all and while I can kind of understand what's going on in the code, I'm not sure how I'd get about editing it.
I think it's like: this._mp -= Math.min(cost, this._mp);

EDIT: Actually, it already checks if (cost > this._mp), so you can just set this._mp = 0;
Yup, that fixed it! Thank you so much!

Original thread: https://forums.rpgmakerweb.com/threads/how-could-i-set-up-a-skill-so-that-it-drains-hp.179071/