MV Trying to call the stats for the class of the caster of a skill to use in a math function to add the difference of an enemy stats to their own.

Hello again!

I have another coding problem that I'd like to get addressed. I am trying to make a skill that copies the base stats of a target and duplicates the changes in the form of a buff/debuff to the caster of the spell. The only problem I'm facing is trying to get the skill to reference the class of the caster to use as bases for the math, since I want to incorporate equipment changes as well instead of just being a raw copy where personal stat changes becomes useless. My code is below:

Code:
<After Eval>
$gameVariables.setValue(3, target.param(2) - $dataClasses[user.currentClass().id].params[2, user.level]);
$gameVariables.setValue(4, target.param(3) - $dataClasses[user.currentClass().id].params[3, user.level]);
$gameVariables.setValue(5, target.param(4) - $dataClasses[user.currentClass().id].params[4. user.level]);
$gameVariables.setValue(6, target.param(5) - $dataClasses[user.currentClass().id].params[5, user.level]);
$gameVariables.setValue(7, target.param(6) - $dataClasses[user.currentClass().id].params[6, user.level]);
user.addState(13);
</After Eval>

I looked at all the reference material I could stomach, but I just could not get it to subtract the classes' stats at the user's level from the enemy's stats. I'm using Yanfly's Skill Core and Base Param Control for this one. If anyone can help push me in the right direction, I would greatly appreciate it.
actor.currentClass() returns the class data entry, so $dataClasses[user.currentClass().id] is a roundabout way of getting user.currentClass()
then params within that data entry is an array of arrays. so youd be looking at user.currentClass().params[2][user.level]

but also, actors have a paramBase() method that just goes over to the actor's current class and grabs the given parameter for the selected parameter id at the actor's current level. so to simplify even further,
Code:
user.paramBase(2)
Again, real lifesavers you guys are. Updated the code as such for the skill:

Code:
<After Eval>
$gameVariables.setValue(3, target.paramBase(2) - user.paramBase(2));
$gameVariables.setValue(4, target.paramBase(3) - user.paramBase(3));
$gameVariables.setValue(5, target.paramBase(4) - user.paramBase(4));
$gameVariables.setValue(6, target.paramBase(5) - user.paramBase(5));
$gameVariables.setValue(7, target.paramBase(6) - user.paramBase(6));
user.addState(13);
</After Eval>

I knew target.param(x) - user.param(x) worked, but I had no clue there was one for bases. I do have a question about this method in particular: Say I want to later introduce a way to increase the bases of a given actor's class. Would calling paramBase() call an updated version of the actor's base parameters or would it keep the original base parameters?
Say I want to later introduce a way to increase the bases of a given actor's class.
You can't readily do that - the class parameters are referenced from the class' entry in your database when needed.

They're not stored dynamically someplace that you can edit them - that's why the parameters are referenced the way they are, you have the base values from the class then things that modify it to produce the end value.

The other question would be - what are you then doing with all of these game variables?
You can't readily do that - the class parameters are referenced from the class' entry in your database when needed.

They're not stored dynamically someplace that you can edit them - that's why the parameters are referenced the way they are, you have the base values from the class then things that modify it to produce the end value.

The other question would be - what are you then doing with all of these game variables?
I mainly asked because Yanfly base param controls plugin has the ability to change the base parameters at runtime using functions, and I don't know what the best method is of increasing a players stats, whether that be modifying their bases, flats or pluses.

What I'm doing with all these game variables is storing some temporary math to apply a buff to the player characters. You may ask yourself "Why not use an array" and the answer is "I would if I knew how". I know the code has a bunch of flaws with it, because it implies that it'll be ran once by one specific character that has the skill and nobody else. If I knew how to make an array work, one that referenced the Actor ID or party member slot as well as an index for each of the increased stats, I would do it, but I simply don't know how, and I've been bashing my head at this for a few days and I'm stumped on implementing it.
I mainly asked because Yanfly base param controls plugin has the ability to change the base parameters at runtime using functions
It doesn't, actually. There are notetags you can put in the class that will add or subtract to the base value, but they have to be a static value (you type a number there).

There isn't any supplied way to change the base values from the class in a dynamic/calculated way during runtime.

I don't know what the best method is of increasing a players stats, whether that be modifying their bases, flats or pluses.
There's no such thing as "best" - which one does what you want? There's really no difference between changing the base and the plus, unless you're modifying the entire parameter formula for some reason.

So with that out of the way, the only actual difference is between the plus and the flat - is the change affected by (de)buffs and trait multipliers or not?

You may ask yourself "Why not use an array" and the answer is "I would if I knew how".
I wasn't at all, but there are a handful of threads that teach how to use arrays in game variables if you think that's helpful.

I was literally asking what I asked: "what are you doing with the variables?" As in what's the plugin parameter or notetag or whatever that you thought would apply the variable's value to the actor's parameter.

I know the code has a bunch of flaws with it, because it implies that it'll be ran once by one specific character that has the skill and nobody else. If I knew how to make an array work, one that referenced the Actor ID or party member slot as well as an index for each of the increased stats, I would do it, but I simply don't know how, and I've been bashing my head at this for a few days and I'm stumped on implementing it.
Why can't you just use the script calls that are provided by the plugin instructions?

1735401724001.png


Code:
<After Eval>
user.addAtk(target.paramBase(2) - user.paramBase(2));
user.addDef(target.paramBase(3) - user.paramBase(3));
user.addMat(target.paramBase(4) - user.paramBase(4));
user.addMdf(target.paramBase(5) - user.paramBase(5));
user.addAgi(target.paramBase(6) - user.paramBase(6));
user.addState(13);
</After Eval>
Coming back to this to say I figured it out finally. Took me a long while, but I got there.

Skill's Code:
Code:
<Before Eval>
if (!Array.isArray($gameVariables.value(1))){
    $gameVariables.setValue(1, []);
}
if (user.isStateAffected(13)){
    user.removeState(13);
}
</Before Eval>

<After Eval>
$gameVariables.value(1).push([user.actorId(), target.paramBase(2) - user.paramBase(2), target.paramBase(3) - user.paramBase(3), target.paramBase(4) - user.paramBase(4), target.paramBase(5) - user.paramBase(5), target.paramBase(6) - user.paramBase(6)]);
user.addState(13);
</After Eval>

And then State 13's Code:
Code:
<Custom Apply Effect>
for (x in $gameVariables.value(1)){
    if ($gameVariables.value(1)[x][0] == target.actorId()){
        target.addAtk($gameVariables.value(1)[x][1]);
        target.addDef($gameVariables.value(1)[x][2]);
        target.addMat($gameVariables.value(1)[x][3]);
        target.addMdf($gameVariables.value(1)[x][4]);
        target.addAgi($gameVariables.value(1)[x][5]);
    }
}
</Custom Apply Effect>

<Custom Remove Effect>
for (x in $gameVariables.value(1)){
    if ($gameVariables.value(1)[x][0] == target.actorId()){
        target.addAtk(-$gameVariables.value(1)[x][1]);
        target.addDef(-$gameVariables.value(1)[x][2]);
        target.addMat(-$gameVariables.value(1)[x][3]);
        target.addMdf(-$gameVariables.value(1)[x][4]);
        target.addAgi(-$gameVariables.value(1)[x][5]);
        $gameVariables.value(1).splice(x, 1);
    }
}
</Custom Remove Effect>

My issue was thinking that I could use the push function to just make an array go into the $gameVariables without having to instantiate it as an array, but that wasn't working and I needed to instantiate it first, which I proceeded to do with the first if statement during the before skill evaluation step if it detects that it is not an array. Removal of the state happens before eval as well since trying to do it after eval caused the state to not apply for some reason after the fact, which then factors into the state's application and removal which does a for-loop to find the value that compares to the target's actorId, and then it applies for that actor only. Once the effect is removed, it undoes the stat changes and finds the variable in the array to remove the entry with the splice function.
I'm still a little unsure why you're doing such convoluted stuff with a game variable and iterating through it every time the state is applied and removed, rather than simply putting the values you're modified into properties on the actor.

But it looks like it should work.

Original thread: https://forums.rpgmakerweb.com/threads/trying-to-call-the-stats-for-the-class-of-the-caster-of-a-skill-to-use-in-a-math-function-to-add-the-difference-of-an-enemy-stats-to-their-own.174195/