MV Yanfly's Stockpile Skill and MaxHP and other stats.

Hello!

I am trying to make the stockpile skill from here to increase the user's maxHP temporarily by a flat amount, let's say 5.
I have it working that whenever I use the skill, it does increase hte maxHP, but it goes beyond the stockpile's stack counter which is 3 as default.

Code:
<Custom Apply Effect>
// Default the stockpile stacks to 0.
user._stockpile = user._stockpile || 0;
// Increase the stockpile stack by 1
user._stockpile += 1;
// Cap the stockpile stack at 3
user._stockpile = Math.min(user._stockpile, 3);
// Update the state counter for the stockpile stack
user.setStateCounter(stateId, user._stockpile);
var boost = 5;
user.addParam(0, boost);  // mhp up
user.gainHp(boost);  // hp up
</Custom Apply Effect>

<Custom Remove Effect>
// Set the user's stockpile stack to 0
user._stockpile = 0;
// Update the state counter for the stockpile stack
user.setStateCounter(stateId, user._stockpile);
var boost = 5;
user.gainHp(-boost);  // hp down
user.addParam(0, -boost);  // mhp down
</Custom Remove Effect>

This is what I have so far. I couldn't find anyone who is using these stacking skills + increasing a stat.
I would also like to know how to increase a skill DMG by a flat amount using the same stockpile skill.

Thank you!
I have it working that whenever I use the skill, it does increase hte maxHP, but it goes beyond the stockpile's stack counter which is 3 as default.
Right, because you just have the code there saying "apply this boost to the parameter," you're not doing anything to say "only apply this boost if the stockpile is a new value".

Try this:
Code:
<Custom Apply Effect>
// Default the stockpile stacks to 0.
user._stockpile = user._stockpile || 0;
// If the stockpile isn't at max
if (user._stockpile<3)
{
    // Increase the stockpile stack by 1
    user._stockpile += 1;
    // Update the state counter for the stockpile stack
    user.setStateCounter(stateId, user._stockpile);
    var boost = 5;
    user.addParam(0, boost);  // mhp up
    user.gainHp(boost);  // hp up
}
</Custom Apply Effect>

Your logic for the Remove Effect is also flawed, because you're adding 5 HP every time you gain a stack, which is a potential boost of 15. But you're only removing 5, regardless of how many stacks you had. So if the player stockpiles three times, they're permanently gaining 10 HP.

You'd change it to:
Code:
<Custom Remove Effect>
// Determine boosted value
let boost = 5*user._stockpile;
// Set the user's stockpile stack to 0
user._stockpile = 0;
// There's no reason to update the state counter for the stockpile stack because it gets created when you apply the state
user.gainHp(-boost);  // hp down
user.addParam(0, -boost);  // mhp down
</Custom Remove Effect>

I would also like to know how to increase a skill DMG by a flat amount using the same stockpile skill.
You just...do it? Either reference a._stockpile in your damage formula or use one of Yanfly's Buffs & States notetags that give examples of how to modify the damage value.

Just make sure if you put it in the damage formula that you check for it to exist, e.g.
Code:
a.atk*4 - b.def*2 + a._stockpile ? a._stockpile : 0
Right, because you just have the code there saying "apply this boost to the parameter," you're not doing anything to say "only apply this boost if the stockpile is a new value".

Try this:
Code:
<Custom Apply Effect>
// Default the stockpile stacks to 0.
user._stockpile = user._stockpile || 0;
// If the stockpile isn't at max
if (user._stockpile<3)
{
    // Increase the stockpile stack by 1
    user._stockpile += 1;
    // Update the state counter for the stockpile stack
    user.setStateCounter(stateId, user._stockpile);
    var boost = 5;
    user.addParam(0, boost);  // mhp up
    user.gainHp(boost);  // hp up
}
</Custom Apply Effect>

Your logic for the Remove Effect is also flawed, because you're adding 5 HP every time you gain a stack, which is a potential boost of 15. But you're only removing 5, regardless of how many stacks you had. So if the player stockpiles three times, they're permanently gaining 10 HP.

You'd change it to:
Code:
<Custom Remove Effect>
// Determine boosted value
let boost = 5*user._stockpile;
// Set the user's stockpile stack to 0
user._stockpile = 0;
// There's no reason to update the state counter for the stockpile stack because it gets created when you apply the state
user.gainHp(-boost);  // hp down
user.addParam(0, -boost);  // mhp down
</Custom Remove Effect>


You just...do it? Either reference a._stockpile in your damage formula or use one of Yanfly's Buffs & States notetags that give examples of how to modify the damage value.

Just make sure if you put it in the damage formula that you check for it to exist, e.g.
Code:
a.atk*4 - b.def*2 + a._stockpile ? a._stockpile : 0


Thank you! I will test them out later and let you know how it goes.
Right, because you just have the code there saying "apply this boost to the parameter," you're not doing anything to say "only apply this boost if the stockpile is a new value".

Try this:
Code:
<Custom Apply Effect>
// Default the stockpile stacks to 0.
user._stockpile = user._stockpile || 0;
// If the stockpile isn't at max
if (user._stockpile<3)
{
    // Increase the stockpile stack by 1
    user._stockpile += 1;
    // Update the state counter for the stockpile stack
    user.setStateCounter(stateId, user._stockpile);
    var boost = 5;
    user.addParam(0, boost);  // mhp up
    user.gainHp(boost);  // hp up
}
</Custom Apply Effect>

Your logic for the Remove Effect is also flawed, because you're adding 5 HP every time you gain a stack, which is a potential boost of 15. But you're only removing 5, regardless of how many stacks you had. So if the player stockpiles three times, they're permanently gaining 10 HP.

You'd change it to:
Code:
<Custom Remove Effect>
// Determine boosted value
let boost = 5*user._stockpile;
// Set the user's stockpile stack to 0
user._stockpile = 0;
// There's no reason to update the state counter for the stockpile stack because it gets created when you apply the state
user.gainHp(-boost);  // hp down
user.addParam(0, -boost);  // mhp down
</Custom Remove Effect>


You just...do it? Either reference a._stockpile in your damage formula or use one of Yanfly's Buffs & States notetags that give examples of how to modify the damage value.

Just make sure if you put it in the damage formula that you check for it to exist, e.g.
Code:
a.atk*4 - b.def*2 + a._stockpile ? a._stockpile : 0
It works how I wanted it to, thank you very much for the help!
Right, because you just have the code there saying "apply this boost to the parameter," you're not doing anything to say "only apply this boost if the stockpile is a new value".

Try this:
Code:
<Custom Apply Effect>
// Default the stockpile stacks to 0.
user._stockpile = user._stockpile || 0;
// If the stockpile isn't at max
if (user._stockpile<3)
{
    // Increase the stockpile stack by 1
    user._stockpile += 1;
    // Update the state counter for the stockpile stack
    user.setStateCounter(stateId, user._stockpile);
    var boost = 5;
    user.addParam(0, boost);  // mhp up
    user.gainHp(boost);  // hp up
}
</Custom Apply Effect>

Your logic for the Remove Effect is also flawed, because you're adding 5 HP every time you gain a stack, which is a potential boost of 15. But you're only removing 5, regardless of how many stacks you had. So if the player stockpiles three times, they're permanently gaining 10 HP.

You'd change it to:
Code:
<Custom Remove Effect>
// Determine boosted value
let boost = 5*user._stockpile;
// Set the user's stockpile stack to 0
user._stockpile = 0;
// There's no reason to update the state counter for the stockpile stack because it gets created when you apply the state
user.gainHp(-boost);  // hp down
user.addParam(0, -boost);  // mhp down
</Custom Remove Effect>


You just...do it? Either reference a._stockpile in your damage formula or use one of Yanfly's Buffs & States notetags that give examples of how to modify the damage value.

Just make sure if you put it in the damage formula that you check for it to exist, e.g.
Code:
a.atk*4 - b.def*2 + a._stockpile ? a._stockpile : 0

I figured out the damage formula too!

Code:
a._stockpile > 0 ? 5 * a._stockpile + 2 : 0 + 2

So at 0 stacks it will always do 2 damage, and every stacks will give +5 damage.

Thank you again, this can be closed.

Original thread: https://forums.rpgmakerweb.com/threads/yanflys-stockpile-skill-and-maxhp-and-other-stats.157721/