MV YEP_BuffsStatesCore and DoT formula misunderstanding

So, formula looks like this

a.level * (v[x] / 5 + 1) * (v[y] * v[y] / 100 + 1)

And I need it to be DoT damage dealt by state in JS code
v[x] is a variable for state's counter which applies to an Enemy by Actor's skills
v[y] is a variable for collected items of certain type
I tried method from Yanfly's DoT video but messed up with variables. Can't figure out what to put in here instead of v[x] and v[y].
For now it looks like this

<Custom Apply Effect>
// Calculate the damage to be dealt by the formula.
target._newSpace = Math.ceil(origin.level * 1 * 1);
</Custom Apply Effect>

<Custom Remove Effect>
// Remove the damage effect.
target._newSpace = undefined;
</Custom Remove Effect>

<Custom Regenerate Effect>
// Default the DoT formula.
target._newSpace = target._newSpace || Math.ceil(origin.level * 1 * 1);
// Reduce the target's HP
target.gainHp(-target._newSpace);
// Start the damage popup.
target.startDamagePopup();
// Check if the target is dead.
if (target.isDead()) {
// Make the target collapse.
target.performCollapse();
}
// Clear the target's results.
target.clearResult();
</Custom Regenerate Effect>

1's are placeholder for missing parts of original formula.
v[x] is a variable for state's counter which applies to an Enemy by Actor's skills
target.getStateCounter(stateId)
v[y] is a variable for collected items of certain type
a specific item's count? or multiple items?
target.getStateCounter(stateId)

a specific item's count? or multiple items?
Sorry for late respond.
It's specific. Variable which is count of one certain key item (yes, I need it as variable)

+I tried target.getStateCounter(stateID) and encountered another problem.
Lets set up that origin.level is 1 and target.getStateCounter(10) is "0" (there is no state on the target)
According to formula, it should go like this: 1 * (0 / 5 + 1) * 1 which is 1 * (0 + 1) * 1 which is 1 * 1 * 1 which is 1 damage in the end.
But game gives me double 0 as the result damage, which doesn't happen when there IS some count of state's stacks

1755030878648.png

Picture. First enemy have 6 stacks, other's 0 and there are these results of calculating.
Log says 6 stacks for the first enemy and "unidentified" for others ("black hole" state is that one DoT effect which takes a number of stacks of other effect). I guess I have to tell the game if there are no any of this effect - the value is 0. Maybe it will fix the problem? Or not?

EDIT: I fixed it.
It's specific. Variable which is count of one certain key item (yes, I need it as variable)
$gameParty.numItems($dataItems[x])
should do then. replace x with the item's id

EDIT: I fixed it.
you did fix it, but just to note in the future, I would need to see your code to be able to say anything about whats happening there.
$gameParty.numItems($dataItems[x])
should do then. replace x with the item's id


you did fix it, but just to note in the future, I would need to see your code to be able to say anything about whats happening there.
Lets resolve it right away.

I linked target.getStateCounter(stateID) to a variable in a way it becomes 0 instead of NaN
And just to be sure, I did the same for the key item because there potentially might be the situation when player don't have any of these (idk if it will result NaN or 0 instead).

<Custom Apply Effect>
// Calculate the damage to be dealt by the formula.
var shards = target.getStateCounter(10) || 0;
var flowers = $gameParty.numItems($dataItems[2]) || 0;
target._newSpace = Math.ceil(origin.level * (shards / 5 + 1) * (flowers / 100 + 1));
</Custom Apply Effect>

<Custom Remove Effect>
// Remove the damage effect.
target._newSpace = undefined;
</Custom Remove Effect>

<Custom Regenerate Effect>
// Default the DoT formula.
target._newSpace = target._newSpace || Math.ceil(origin.level * (shards / 5 + 1) * (flowers / 100 + 1));
// Reduce the target's HP
target.gainHp(-target._newSpace);
// Start the damage popup.
target.startDamagePopup();
// Check if the target is dead.
// Make the target collapse.
if (target.isDead()) {
target.performCollapse();
}
// Clear the target's results.
target.clearResult();
</Custom Regenerate Effect>

Works as intended at least
idk if it will result NaN or 0 instead
For your apply effect. the issue if any would be shards. if the target doesnt have state 10, then itd be undefined and any math used with it would be NaN. you were right in adding the || 0 to it. the numItems doesnt need it, but its just not going to do anything. it wont cause a problem

the issue in your regenerate effect is that neither shards nor flowers would be defined. variables dont exist outside the notetag you made them in. you would have to redefine them there, or else your damage will be NaN if the battler has the state but didnt get a _newSpace written onto them
For your apply effect. the issue if any would be shards. if the target doesnt have state 10, then itd be undefined and any math used with it would be NaN. you were right in adding the || 0 to it. the numItems doesnt need it, but its just not going to do anything. it wont cause a problem

the issue in your regenerate effect is that neither shards nor flowers would be defined. variables dont exist outside the notetag you made them in. you would have to redefine them there, or else your damage will be NaN if the battler has the state but didnt get a _newSpace written onto them
Now I did put shards/flowers there BUT
For some reason, when I apply more stacks of shards while DoTstate still exists, damage doesn't update 🙁
f.e. It deals X damage when Enemy have 6 shards
In the end of next turn, it still deals X damage instead of Y damage though Enemy have 12 shards on self now.

<Custom Apply Effect>
// Calculate the damage to be dealt by the formula.
var shards = target.getStateCounter(10) || 0;
var flowers = $gameParty.numItems($dataItems[2]) || 0;
target._newSpace = Math.ceil(origin.level * (shards / 5 + 1) * (flowers / 100 + 1));
</Custom Apply Effect>

<Custom Remove Effect>
// Remove the damage effect.
target._newSpace = undefined;
</Custom Remove Effect>

<Custom Regenerate Effect>
var shards = target.getStateCounter(10) || 0;
var flowers = $gameParty.numItems($dataItems[2]) || 0;
// Default the DoT formula.
target._newSpace = target._newSpace || Math.ceil(origin.level * (shards / 5 + 1) * (flowers / 100 + 1));
// Reduce the target's HP
target.gainHp(-target._newSpace);
// Start the damage popup.
target.startDamagePopup();
// Check if the target is dead.
// Make the target collapse.
if (target.isDead()) {
target.performCollapse();
}
// Clear the target's results.
target.clearResult();
</Custom Regenerate Effect>
For some reason, when I apply more stacks of shards while DoTstate still exists, damage doesn't update
yes. that is what youve done here
target._newSpace = target._newSpace || Math.ceil(origin.level * (shards / 5 + 1) * (flowers / 100 + 1));
that line makes it so that if _newSpace exists, it cannot be overwritten. if you want it to actively update, then you would want to remove the first portion (which would then remove the need for having _newSpace entirely)

Code:
// Default the DoT formula.
var shards = target.getStateCounter(10) || 0;
var flowers = $gameParty.numItems($dataItems[2]);

var dmg = Math.ceil(origin.level * (shards / 5 + 1) * (flowers / 100 + 1));
// Reduce the target's HP
target.gainHp(-dmg);
...
yes. that is what youve done here

that line makes it so that if _newSpace exists, it cannot be overwritten. if you want it to actively update, then you would want to remove the first portion (which would then remove the need for having _newSpace entirely)

Code:
// Default the DoT formula.
var shards = target.getStateCounter(10) || 0;
var flowers = $gameParty.numItems($dataItems[2]);

var dmg = Math.ceil(origin.level * (shards / 5 + 1) * (flowers / 100 + 1));
// Reduce the target's HP
target.gainHp(-dmg);
...
So, Yanfly's tutorial was just about applying, not updating xddd
Now, variant below works 100% clearly as intended
And I also removed Custom Apply Effect because there was no real need.

<Custom Remove Effect>
// Remove the damage effect.
target._newSpace = undefined;
</Custom Remove Effect>

<Custom Regenerate Effect>
// Default the DoT formula.
var shards = target.getStateCounter(10) || 0;
var flowers = $gameParty.numItems($dataItems[2]) || 0;
var dmg = Math.ceil(origin.level * (shards / 5 + 1) * (flowers / 100 + 1));
// Reduce the target's HP
target.gainHp(-dmg);
// Start the damage popup.
target.startDamagePopup();
// Check if the target is dead.
// Make the target collapse.
if (target.isDead()) {
target.performCollapse();
}
// Clear the target's results.
target.clearResult();
</Custom Regenerate Effect>

guess I should learn the basics of JS first before getting into this.

oops. Accidentally replied instead of editing

Well... I also wanted to say I deleted Custom Remove Effect too

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/yep_buffsstatescore-and-dot-formula-misunderstanding.179473/