MZ States that apply a buff based off of a user's stat?

Hello.

When searching, this question has been asked before, but none of them were really answered properly from what I could find.

I'm looking to make a state or buff in which the potency of the buff scales off of the user's stat. For example, an ATK buff that buffs the target by 25% of the user's ATK.

I'm currently using many VisuStella plugins, so if there is a way they can perform this function somewhat easier, that would be good to know. I couldn't find anything like this from looking through their help guides, though.

Any help is appreciated.
Before I answer you, I need to confirm:
How do you want to achieve this effect?


A status effect or a buff?
A buff can stack twice, with each stack increasing the effect by 25%.

EDIT: Alright, I think I understand the effect you want.

The answer is: You need to record who cast the buff in order to achieve this effect.
The data structure for buffs makes this difficult to implement,
whereas a status effect would be easier to handle.

If you want to track who cast each buff, including buffs of the same type,
the required changes to the data structure will be more significant
Yeah, it looks like using states is the only reasonable way to do this. I might have to forego using the engine's default buff system entirely since it would just make things too weird.

After doing some digging, I did manage to get something to work. It's not normally possible to put a script function into a state, but VisuStella's SkillsStatesCore enables it with these notetags:
<JS on Add State> </JS on Add State>
<JS on Erase State> </JS on Erase State>

Using this script and testing it a bit, it seems to function as intended:

Paste this into <JS on Add State>:
JavaScript:
 if (target._boostFromSkill) {
    target.addParam(3, -target._boostFromSkill);
  } // Removes buff if already in effect to reapply it and prevent infinite stacking

  let buffStat = Math.floor(origin.param(3) * 0.5); // Uses caster's selected parameter multiplied by inputted value
  target._boostFromSkill = buffStat;
  target.addParam(3, buffStat); // Adds selected parameter equal to the amount above to the target

Then paste this into <JS on Erase State>:
JavaScript:
  if (target._boostFromSkill) {
    target.addParam(3, -target._boostFromSkill);
    delete target._boostFromSkill;
  } // Removes buff added by the state when it expires or is removed

This example here is adding 50% of the caster's DEF to the target's DEF. If two different states are to stack their effects, "_boostFromSkill" can just be different per state. The "Skill" bit can be changed to the Skill/State name, or whatever else works best. Else, they will conflict and overwrite each other.

I think my issue has been resolved, so this topic can probably be closed, unless anyone sees any potential bugs here?

Original thread: https://forums.rpgmakerweb.com/threads/states-that-apply-a-buff-based-off-of-a-users-stat.177893/