MZ Visustella Skill HP Cost as Bonus Damage?

So I've been working with Visustella's Skills/States Core and I'm wondering if there's a way of adding code to the damage formula of a skill that will cause it to do bonus damage based on the HP cost of the skill. So if the skill costs 15 HP to use, it deals an additional 15 damage, the idea being that different States and Passives can adjust the HP cost for more/less bonus damage.
There is a way, yes.
The code used to calculate the hp cost is in the plugin settings 'Skill Cost Types'. That's where you see how it checks all the traits. Don't know if VS has single method that just gives you the final cost value without doing anything else, but I guess you can put that stuff in your own function and use it to get the value.

You could also check your actor hp with Battle Core notetags <JS Pre-Start Action> and <JS Pre-Damage> and compare the user.hp (save it in some variable) and in the pre-damage add that to the damage value. Something like (didn't test):

<JS Pre-Start Action>
$gameVariables.setValue(11, user.hp);
</JS Pre-Start Action>

<JS Pre-Damage>
$gameVariables.setValue(12, user.hp);
value += $gameVariables.value(11) - $gameVariables.value(12);
</JS Pre-Damage>
The code used to calculate the hp cost is in the plugin settings 'Skill Cost Types'. That's where you see how it checks all the traits. Don't know if VS has single method that just gives you the final cost value without doing anything else, but I guess you can put that stuff in your own function and use it to get the value.

You could also check your actor hp with Battle Core notetags <JS Pre-Start Action> and <JS Pre-Damage> and compare the user.hp (save it in some variable) and in the pre-damage add that to the damage value. Something like (didn't test):

<JS Pre-Start Action>
$gameVariables.setValue(11, user.hp);
</JS Pre-Start Action>

<JS Pre-Damage>
$gameVariables.setValue(12, user.hp);
value += $gameVariables.value(11) - $gameVariables.value(12);
</JS Pre-Damage>
That code actually worked 100% perfectly, no changes necessary! Definitely hadn't considered doing it that way, but it's very smart.

The only other thing is, I want the bonus damage to only apply when the player is affected by a state, so I added this code:

if ($gameActors.actor($gameTemp.lastActionData(2)).isStateAffected(72))

But this makes it so the bonus damage will also apply for enemies using these abilities as long as the player is affected by the state, too. What would be the best way to phrase it so that it only applied the bonus damage for the player?
You should be able to use user.isStateAffected(72) and itll only apply if the user has the state. Theres no need to check the specific actor unless theyre the only battler who will ever use the skill
You should be able to use user.isStateAffected(72) and itll only apply if the user has the state. Theres no need to check the specific actor unless theyre the only battler who will ever use the skill
Awesome, yeah I had a feeling the code I was using was needlessly long.

Curious if it'd be possible to just insert the code into the Pre-Start Action and Pre-Damage Steps in the Battle Core settings. It'd save me the trouble of having to insert the code into the notes of EVERY skill that has an HP cost. I tried just adding in the code (minus the <JS Code> part) to each but I get the error "TypeError Assignment to constant variable."
Yeah in the plugin settings for Pre-Damage at the start it already declares a const value = arguments[0] I suppose that is the damage value (haven't tested though). Change that to let value = arguments[0]
Yeah in the plugin settings for Pre-Damage at the start it already declares a const value = arguments[0] I suppose that is the damage value (haven't tested though). Change that to let value = arguments[0]
Wow, it was really that simple. Well, everything works perfectly, so I've got no further questions! Thanks!

Original thread: https://forums.rpgmakerweb.com/threads/visustella-skill-hp-cost-as-bonus-damage.181696/