Help making a skill that adds a stacking state

I'm trying to create an alternate Basic Attack for a weapon type where each use of the skill adds a stack of Combo, which increases the user's physical damage by 10% for each stack, but gets reset when the user doesn't use the basic attack.

Preferably I'd want the states to be added after the skill is finished, as the attack has multiple hits. Putting the addState function in the damage formula would add too many stacks at once.
There's really no reason to put addState in the damage formula – adding it as an effect will be exactly the same. Pretty sure that's still once per hit rather than once per attack, though.

Without plugins, probably the only way to do something once per attack when the attack has multiple hits is with a common event… and since it needs to reference the last target, it's only possible without plugins in MZ. For MV you'd need at minimum a plugin that lets you refer to the last target in a common event.
Which engine are you using? You posted in MZ Support but your profile says you use MV.

As @Solar_Flare indicates, that will affect the answers you get, whether it's feasible via common event or which plugins you'd need to end up using.

There's no such thing innately as a stacking state, so at the minimum you'll need to use Yanfly's Skill Core or Buffs and States Core for MV, or my Eval Tags/VisuStella's Skills and States for MZ so you can increment a property on the battler when the state is applied.
Sorry, I haven't used this in a while so I haven't updated it. I am using MZ.

I do have a handful of VisuStella's plugins for a few other attacks, and I've looked through all the custom functions but either haven't understood it properly or haven't found what I'm looking for.

I'll go through how I want the State/Attack to function:
Basic Attack is Used -> Attack Hits, All Hits Connect -> Gain a stack of Combo
Player has 7 stacks of Combo, +10% ATK per Stack
Player Guards -> Clears all stacks of Combo
You'll need a couple of plugins to make this function properly.

Basic Attack is Used -> Attack Hits, All Hits Connect -> Gain a stack of Combo
VisuStella Battle Core, put the following notetag into your skill:
Code:
<JS Post-Apply>
if (!user.gotState)
{
    user.gotState = true;
    user.addState(42);
}
</JS Post-Apply>
replacing the number 42 with the ID of your Combo state. Then, with VisuStella Skills and States, put the following notetags into your Combo state:
Code:
<JS On Add State>
user.comboStacks ??= 0;
user.comboStacks++;
</JS On Add State>

<JS Pre-End Turn>
delete user.gotState;
</JS Pre-End Turn>

<JS On Erase State>
delete user.comboStacks;
</JS On Erase State>

This should apply the Combo state once every time they use the skill, and increment a comboStacks property every time it's applied, which is erased when the state is removed.

Player has 7 stacks of Combo, +10% ATK per Stack
With VisuStella Core Engine, put in your Combo state the notetag:
Code:
<JS atk Plus: Math.round(user.paramBase(2) * (user.comboStacks || 0) * .1)>

Player Guards -> Clears all stacks of Combo
Give your Guard skill the Remove State Trait for Combo.
Give Guard the VisuStella Battle Core notetag:
If I wanted every other action BUT the Basic Attack that inflicts Combo to clear all Combo stacks, would I have to put this into each and every skill?
If I wanted every other action BUT the Basic Attack that inflicts Combo to clear all Combo stacks, would I have to put this into each and every skill?
No. I'm guessing at this variable since it's not actually in VisuStella's documentation, but based on where they say the notetag is being called from, it's worth trying. Add to your Combo state:
Code:
<JS Pre-Start Action>
if (!action.isAttack())
    user.removeState(42);
</JS Pre-Start Action>
again, replacing the ID as appropriate.
Okay, so the initial applying of Combo and clearing of Combo work, but it doesn't seem to be giving me any extra damage. Looking over the code, I think it's because the state only ever applies once since the skill can only ever exist once (to my knowledge).

Lack of a visual indicator also doesn't really help, but I would have no idea on where to even start on that.
Okay, so the initial applying of Combo and clearing of Combo work, but it doesn't seem to be giving me any extra damage. Looking over the code, I think it's because the state only ever applies once since the skill can only ever exist once (to my knowledge).
No, that's not correct (I assume you meant to type the state can only ever exist once). The notetag for add state should run every time addState() is called - even without plugins, other things happen if a state is added that the target already has (e.g. the duration is refreshed).

Lack of a visual indicator also doesn't really help, but I would have no idea on where to even start on that.
In the JS On Add State notetag, after the existing two lines, you can add
console.log("stacks are ", user.comboStacks, ", atk is ", user.atk)
and then during the game press F8 and go to the Console tab - you should see the increasing numbers pop up there.
Chance it could be something different altogether from how the console log looks, it didn't even output what it should have.

Here is the damage formula for the skill.
Code:
1.85 * Math.sqrt((a.atk * 10) / (b.def * 2))

Also provided screenshot of console log after attack a few times.
There's no such thing innately as a stacking state
From an engine standpoint a stacking state is actually quite simple to do, I believe – just call addNewState instead of addState. With that method, you can add a duplicate of a state, thus doubling all of its effects. I haven't tried it myself though, so I don't know if there are any downsides to doing this. There might be more work required to get it all working perfectly.

In the context of VisuStella, it's possible that this method could allow you to dispense with the comboStacks variable.
Okay, I've been messing around a bit and I don't think anything in <JS On Add State> function is going off. Not only that, but user.paramBase(x) also doesn't seem to work properly.
I've managed to make the Attack and Combo Stacks work in (mostly) the way that I want it to, though I'm having trouble with how I want it to clear the stacks.

Attacking with the Gauntlets' Basic Attack specifically gives you a stack, and using a skill that isn't the Basic Attack or Swapping Weapons doesn't cause it to clear... but I only want the Gauntlets' Basic Attack to not clear the stacks. If I swap to a different weapon and use its Basic Attack, the stacks don't clear.

I haven't been able to find the script or function to make it work, though I might need to find an additional plugin to make it work the way I want it to.

Basically:
(Assuming Gauntlets are already equipped at the start)
Basic Attack -> +1 Stack of Combo
Swap Weapon to Different Weapon -> Keep Stacks
Attack with Different Weapon/Do literally anything else -> Clear Stacks (after damage)

There's probably a different, more efficient way to work this, but I am going to try making it so that each Non-Gauntlet Basic Attack clears Combo Stacks in the Notetags.
I completely missed this thread when it was newer, so apologies if this info is no longer needed

Also provided screenshot of console log after attack a few times.
user.paramBase(x) also doesn't seem to work properly.
<JS atk Plus: Math.round(user.paramBase(2) * (user.comboStacks || 0) * .1)>
"user" isnt a variable in the eval for that tag actually. You'd need to use "this" in this case instead


Lack of a visual indicator also doesn't really help, but I would have no idea on where to even start on that.
you could play an animation on state application or use the battler.setStateDisplay function to add the number of stacks to the state icon ingame

Basically:
(Assuming Gauntlets are already equipped at the start)
Basic Attack -> +1 Stack of Combo
Swap Weapon to Different Weapon -> Keep Stacks
Attack with Different Weapon/Do literally anything else -> Clear Stacks (after damage)
and each weapon has its own standard attack? you need to change the condition you use that removes the state then. you could set it to look to see if the action being used is a skill of a certain id, but lets do this instead...

Code:
<JS Pre-Start Action>
if (!action.item().meta.KeepCombo)
    user.removeState(state.id)
</JS Pre-Start Action>
what this'll do is that itll remove the state so long as the action being used doesnt have a <KeepCombo> notetag, and now you can make any skills you want retain the combo easily by giving it that notetag

Original thread: https://forums.rpgmakerweb.com/threads/help-making-a-skill-that-adds-a-stacking-state.181220/