MV [YEP Buffs and States Core] Scaling State Counter

I want the scale the number of counters applied by the user's MAT stat. To stop the numbers from getting to high, I decided that it should only increase for every power of ten. This is the code I came up with.

<Custom Apply Effect>
var stack = Math.log10(user.MAT);
target.addStateCounter(8, stack);
</Custom Apply Effect>

When I test it out, it results in the state counter having a value of NaN. As I understand, that should only happen if user.MAT is a negative number. So, what am I doing wrong?

Edit:
I had assumed the issue was with the log10 function, but it seems to result in ten no matter what equation I use, even user.MAT alone. Is that just not how you refer to the stat in code?

Edit 2:
After changing to user.mat, it has even stranger behavior. Math.log10(user.mat) feeds out 1 no matter how high the MAT value is. Using user.mat on its own, similarly always results in a value of 10.
maybe you should change log10 to something like value * 10?
see if something change there.

or what does it say if you use the console log? does it print there corrently?
maybe you should change log10 to something like value * 10?
see if something change there.

or what does it say if you use the console log? does it print there corrently?
Multiplying it by ten, as I suspected, does not change the outcome. Instead of always being 10, it's always 100. No scaling.

Nothing is printed in the console log.
Code is case-sensitive: user.MAT is undefined. Use user.mat instead.

Also, I'm guessing that will display a lot of decimal places. In that case you can round stack before applying it, e.g. round to 1 decimal place (nearest 0.1):

stack = Math.round(stack * 10) / 10;
When I test it out, it results in the state counter having a value of NaN. As I understand, that should only happen if user.MAT is a negative number.
That's not entirely correct. You would get NaN back from that function if the result is an imaginary number (the log of a negative value), but you also get it when you provide an argument that is actually Not a Number in the first place (such as your undefined MAT member variable).

If you'd been doing any other math that wasn't using a function (+ - * / instead of Math.log10()), you'd have gotten 0 as a result.

After changing to user.mat, it has even stranger behavior. Math.log10(user.mat) feeds out 1 no matter how high the MAT value is. Using user.mat on its own, similarly always results in a value of 10.
Well, the first is clearly a result of the second - log10 of 10 is, in fact, 1.

What do you have as the entered value of the MAT on the battler this state is going on? What should it be?

A few things to double check:
- You're testing this in the game, in a new play test. Using the Battle Test in the editor doesn't work correctly once you start using plugins.

- You're referencing the correct battler. In this case, user is the battler the state is going onto. If you wanted to reference the MAT of the battler casting the state onto someone else, you'd be looking at origin.mat
Like Turan says, I wonder if you're confusing user (the one who has the state) and origin (the one who applied the state)?

I checked my copy of YEP Buffs & States Core and it looks like it should handle non-integer counter values OK. For debugging purposes, you could try something like this:

<Custom Apply Effect> var stack = Math.log10(user.mat); console.log('user.mat is:', user.mat, '\nstack is:', stack); target.addStateCounter(8, stack); </Custom Apply Effect>
This should log the input and output values to the console for a better idea of what's going on. 👋

(The dev tools window can be opened by pressing F8 during playtest; these messages should appear in the Console tab of that window.)
That's not entirely correct. You would get NaN back from that function if the result is an imaginary number (the log of a negative value), but you also get it when you provide an argument that is actually Not a Number in the first place (such as your undefined MAT member variable).

If you'd been doing any other math that wasn't using a function (+ - * / instead of Math.log10()), you'd have gotten 0 as a result.


Well, the first is clearly a result of the second - log10 of 10 is, in fact, 1.

What do you have as the entered value of the MAT on the battler this state is going on? What should it be?

A few things to double check:
- You're testing this in the game, in a new play test. Using the Battle Test in the editor doesn't work correctly once you start using plugins.

- You're referencing the correct battler. In this case, user is the battler the state is going onto. If you wanted to reference the MAT of the battler casting the state onto someone else, you'd be looking at origin.mat
I checked it with roughly four different values, though not thoroughly. At level 1, the MAT was sixteen. It was around 30 at level five if I recall correctly. For testing purposes, I made an item which increases MAT by 100.

Edit:
Just realized you're the one who suggested using origin and it wasn't Caethril. Sorry for thanking the wrong person. ^^
Like Turan says, I wonder if you're confusing user (the one who has the state) and origin (the one who applied the state)?

I checked my copy of YEP Buffs & States Core and it looks like it should handle non-integer counter values OK. For debugging purposes, you could try something like this:

<Custom Apply Effect> var stack = Math.log10(user.mat); console.log('user.mat is:', user.mat, '\nstack is:', stack); target.addStateCounter(8, stack); </Custom Apply Effect>

This should log the input and output values to the console for a better idea of what's going on. 👋

(The dev tools window can be opened by pressing F8 during playtest; these messages should appear in the Console tab of that window.)
You are entirely correct. Replacing user with origin was the solution. Now, how do I round down or nearest? I'll decide what is better for balancing once I have the system more together.
Just as a quick note, we're not supposed to double post - you can simply click Reply on both of our posts, use the +Quote button, or @tag us.
Now, how do I round down or nearest?
Use Math.round() for nearest or Math.floor() for explicitly rounding down.
Just as a quick note, we're not supposed to double post - you can simply click Reply on both of our posts, use the +Quote button, or @tag us.

Use Math.round() for nearest or Math.floor() for explicitly rounding down.
Like this?
<Custom Apply Effect>
var stack = Math.round(Math.log10(origin.mat));
target.addStateCounter(8, stack);
</Custom Apply Effect>

It does seem to work, it just kind of doesn't look right to have a method nested in a method like that. Sorry if my terminology is off.

The choice between floor and round would be where the threshold is.
With round it would be 50, 500, 5000.
With floor it would be 100, 1000, 10000, assuming I raise the cap.
Like this?
Absolutely.
Before the thread gets marked as resolved, is there any way to check the number of stacks on a different state? For example, if on apply, one state has four stacks and the other state has 3, so three get consumed and the effect gets scaled with that?
From the plugin documentation:
battler.getStateCounter(stateId)
- This will return the current state counter value.
Then now I just need two functions.
One that would compare the two values for target.getStateCounter for both states, and output the value of the smaller one.
The second would catch any instance in which a counter might go below one, in which case it should be removed.
Then now I just need two functions.
One that would compare the two values for target.getStateCounter for both states, and output the value of the smaller one.
Code:
let counter;
if (target.getStateCounter(x) < target.getStateCounter(y))
    counter=target.getStateCounter(x);
else
    counter=target.getStateCounter(y);

or, to be more efficient,
Code:
let counter=Math.min(target.getStateCounter(x), target.getStateCounter(y));

The second would catch any instance in which a counter might go below one, in which case it should be removed.
You just add a check wherever you have addStateCounter()
Code:
if (target.getStateCounter(x) < 1)
    target.removeState(x);
Code:
let counter;
if (target.getStateCounter(x) < target.getStateCounter(y))
    counter=target.getStateCounter(x);
else
    counter=target.getStateCounter(y);

or, to be more efficient,
Code:
let counter=Math.min(target.getStateCounter(x), target.getStateCounter(y));


You just add a check wherever you have addStateCounter()
Code:
if (target.getStateCounter(x) < 1)
    target.removeState(x);
Getting around to implementing now. A few questions.
What does let do?


This should be everything, right?

<Custom Apply Effect> var stack = Math.round(Math.log10(origin.mat)); target.addStateCounter(5, stack); </Custom Apply Effect> <Custom Apply Effect> if (target.isStateAffected(6)) { let stack=Math.min(target.getStateCounter(5),target.getStateCounter(6)); target.addStateCounter(5,-stack); if (target.getStateCounter(5)<1); target.removeState(5); target.removeStateCounter(6,-stack); if (target.getStateCounter(6)<1); target.removeState(6); target.addStateCounter(9,stack); } </Custom Apply Effect> <Custom Apply Effect> if (target.isStateAffected(8)) { let stack=Math.min(target.getStateCounter(5),target.getStateCounter(6)); target.addStateCounter(5,-stack); if (target.getStateCounter(5)<1); target.removeState(5); target.removeStateCounter(8,-stack); if (target.getStateCounter(8)<1); target.removeState(8); target.addStateCounter(10,stack); } </Custom Apply Effect>


I spent about half an hour googling for a script call that would simply damage the target, with arguments for the element and damage amount. I could not find anything relevant on google.
What does let do?
It declares a variable.

Are you showing things from multiple different states in that post? You have three chunks of code, all labeled as Custom Apply Effect...you can't have two of the same notetag in one database entry.
It declares a variable.

Are you showing things from multiple different states in that post? You have three chunks of code, all labeled as Custom Apply Effect...you can't have two of the same notetag in one database entry.
Oh, okay. I thought it would just execute them one by one. It's gonna be tedious merging them.

It didn't turn out to be as tedious as I thought it would. Deleting a total of six lines. Anyway, is there a script call for damaging the target?

Unless there's a simpler way, this should do it.

<Custom Turn End Effect> if (target.isStateEffected(6)){ let stack = target.getStateCounter(6); target.addStateCounter(9,stack); target.removeState(6); target.gainHP(-stack*10*target.elementRate(9)); } </Custom Turn End Effect>

After testing it out, it either doesn't trigger at all or just doesn't show up in the damage numbers. It makes sense why it wouldn't show up in the damage numbers, but that doesn't change that that's not how I want it to behave.
Try adding target.startDamagePopup(); after target.gainHp(...);.
Try adding target.startDamagePopup(); after target.gainHp(...);.
Do I put in the same equation or will it automatically recognize it should take the value of the last bit of damage?


It seems I have been misinformed. target.gainHP is not a function.
1666529372818.png


I did find a the function Game_Interpreter.prototype.changeHP.call() but because it's not a function of the target, I don't know how to feed it the target. Simply putting "target" into that slot does not work, and results in this. I do not know why the error is being associated with AutoPassiveStates.

1666535244837.png

Original thread: https://forums.rpgmakerweb.com/threads/yep-buffs-and-states-core-scaling-state-counter.152077/