MZ Skill no longer works (JS and Visustella)

Hello computer friends, I hope you're well.

I set up a skill to consume all of the users TP and to scale the damage with how much TP was used. I found this wonderful thread as reference. The skill had worked just fine, but at some point something broke. I've made sure to keep my plugins up to date (specifically the Tier 0 and Tier 1 Visustella plugins since I think this works off the SkillStatesCore plugin).

EDIT: It seems the damage of the skill is being calculated *after* the TP is spent. The skill still costs all the user's TP, but the damage does not change regardless of how much the actor had before the skill was activated.

Here are the specifics of the skill in question.

Damage formula is 100 + a.atk + a.currTp * 20 - b.def * 2 and in the Note box is

Code:
<JS TP Cost>
user.currTp=user.tp;
cost=Math.max(user.tp, 1);
</JS TP Cost>

And like I said before, up until very recently (sadly I'm not sure exactly when it broke) it worked just fine.

Anyone have any thoughts? Thanks in advance!
You might want to add what's actually broken. There might be someone seeing an error without knowing, but generally speaking "It doesn't work" is worthless information.
I can't believe I forgot to actually say what isn't working...

It seems the damage of the skill is being calculated *after* the TP is spent. The skill still costs all the user's TP, but the damage does not change regardless of how much the actor had before the skill was activated.
Well, I don't think your dmg formula has access to the variable you set in the notetag. Might be wrong tho.

Either way, the dmg formula doesn't need this variable at all. Why not just use a.tp?
1770338008168.png


If that doesn't work, maybe there was a change you made that changed the moment when dmg is calculated or something and we might need to backtrack what changes you made when it was working. (Or maybe someone smarter will stop by 😛)
Why not just use a.tp?
by the time damage execution happens, the tp would have already been spent and the formula wouldnt be able to use the spent tp. the value does have to be saved elsewhere first.

And like I said before, up until very recently (sadly I'm not sure exactly when it broke) it worked just fine.
can you remember doing anything that would require calculating the tp cost of the skill after paying the cost, like displaying it anywhere else? normally, that code would be only ran when the skill costs are drawn for the menu and when its time to pay the cost, which should be fine for this.

have you tried disabling your plugins except for whats needed for this and testing to see if it was something youve added recently causing it?
Why don't you try using MP Cost, or even no Cost at all?
In my game, there are several skills that use TP to deal damage to targets. They all work well and require almost no plugins to function.
Ex: a.addState(x); a.tp * 20
- Inflict damage to the target equal to the user's TP x 20, and at the end of the turn, the user's TP becomes 0.

* You need to create a state that will reset the user's TP. (TP Regeneration -100%)
Why don't you try using MP Cost, or even no Cost at all?
In my game, there are several skills that use TP to deal damage to targets. They all work well and require almost no plugins to function.
Ex: a.addState(x); a.tp * 20
- Inflict damage to the target equal to the user's TP x 20, and at the end of the turn, the user's TP becomes 0.

* You need to create a state that will reset the user's TP. (TP Regeneration -100%)
that comes with a few caveats based on the battle system. the biggest thing IMO would be that the actor would lose any TP they gained between paying the cost and the turn ending.

As an example - the actor is the first to act during that turn, uses the skill, and later takes a hit that gives them 20TP from the damage they took. if the state removes the TP at the end of the turn, then the 20 TP they gained during the turn is lost where if it were the cost, they'd still end the turn with 20TP.

Then theres some other stuff like...
- if his battlers are able to act multiple times in a turn, they could also use the skill twice or use that skill and some other skill that costs TP without penalty.
- the menu wouldnt be able to show the true skill cost.
-if the state was removed (eg. dying) before the end of the turn, the tp would be kept.
have you tried disabling your plugins except for whats needed for this and testing to see if it was something youve added recently causing it?
I tried disabling everything and it did work, so it's probably something with one of the visustella plugins. I'll work on troubleshooting which one might be causing the problem.
It's the Visustella Auto Skill Triggers plugin that seems to be causing the problem. Now to figure out why it's conflicting.
It's the Visustella Auto Skill Triggers plugin that seems to be causing the problem. Now to figure out why it's conflicting.
any insight?
Well, after banging my head against it for a couple of days...I have no clue. I'm really not sure why it's conflicting and I'm not savvy enough with the back end part of RPG Maker to figure it out on my own. All I can say for sure is, if that plugin is not in use, the <JS TP Cost> code works, and it the plugin is in use, then the code does not work. I wish I could provide better info, but sadly that's all I've got.
if that plugin is not in use, the <JS TP Cost> code works, and it the plugin is in use, then the code does not work
i wager that the code is working, but its as i said earlier.
can you remember doing anything that would require calculating the tp cost of the skill after paying the cost
it might be that the auto trigger plugin is checking the requirements of the battler's skills as a part of looking for skills to trigger, and that would include TP costs. if your TP cost code runs at any point between the initial payment and damage execution, then your currTp property would be overwritten with 0.

you could probably change the code to set the property only if it doesnt exist, and then have something else clear the property after damage execution like a passive that checks after actions or a post damage effect on the skill.

Code:
<JS TP Cost>
user.currTp ??= user.tp;
cost = Math.max(user.tp, 1);
</JS TP Cost>

<JS Post-Apply>
delete user.currTp;
</JS Post-Apply>
If that's the case you should submit a bug report I think, as any solution is bound to be a workaround

Robro's solution is quite clever tbh, I would maybe switch post-apply to <JS Post-End Action> but that's just me
I would maybe switch post-apply to <JS Post-End Action> but that's just me
that was my first thought, but the VS documentation said that while <JS Pre-Start Action> is a valid tag for skills, <JS Post-End Action> is not. Maybe itll still work as their documentation isnt 100% accurate all the time. Its worth the OP checking as the post apply setup assumes the skill hits one target once
I think you can also just go to VisuStella Skill and States Core plugin settings -> Skill Cost Types -> TP -> JS: Paying Cost (different from JS: Cost Calculation) and make the code set the cost to a game variable every time you actually pay the TP cost.
I think you can also just go to VisuStella Skill and States Core plugin settings -> Skill Cost Types -> TP -> JS: Paying Cost (different from JS: Cost Calculation) and make the code set the cost to a game variable every time you actually pay the TP cost.
Oh that's smart thinking if you do it more than a couple times...
I had a problem a couple of months ago with the Protect state no longer working. I isolated the issue to a VisuStella plug-in. I submitted a bug report and they fixed it the next day. I had a similar experience with the Battle Cursor plug-in last year. Submitted the report, fixed within days. I've been very impressed with their customer service.

You do have to state the problem clearly, and submit a sample project illustrating the problem. But the results are worth that small time investment.
I think you can also just go to VisuStella Skill and States Core plugin settings -> Skill Cost Types -> TP -> JS: Paying Cost (different from JS: Cost Calculation) and make the code set the cost to a game variable every time you actually pay the TP cost.
My two cents about this

In Skill Cost - TP - JS Paying Cost
JavaScript:
// Declare Variables
const user = this;
const skill = arguments[0];
const cost = arguments[1];

// Store TP before payment
user._prePaymentTp = user._tp;

// Process Payment
user._tp -= cost;

then update the formula like this
100 + a.atk + a._prePaymentTp * 20 - b.def * 2

you can use whichever name you like, I just used prepaymenttp because I have no imagination at this time of day

Original thread: https://forums.rpgmakerweb.com/threads/skill-no-longer-works-js-and-visustella.182296/