MZ Visustella: run a common event BEFORE damage calculation in a skill

What am I doing wrong?

I thought this would be the right command (sounds intuitive enough)

<JS Pre-Damage>
$gameTemp.reserveCommonEvent(9)
</JS Pre-Damage>

But when I test this skill, the common event is run AFTER the skill has damaged the enemy. Should I use another JS tag?
you RESERVE the common event a slot in the regular list of the execution.
that script command was never meant for immediate execution, and that is why it doesn't start the common event.

I know yanfly in MV had a specific notetag for starting common event, but I don't know how Visustella handled that.
I'm a bit lost.
So any command included between <JS Pre-Damage> and </JS Pre-Damage> including things such as variable changes is not actually performed "pre-damage" (before the damage)?
If so, is there a tag that would make this possible, so that the sequence of events happens before the damage is calculated? I'm using a variable in the damage calculation and I need to calculate its value before damage execution.
So any command included between <JS Pre-Damage> and </JS Pre-Damage> including things such as variable changes is not actually performed "pre-damage" (before the damage)?
wrong.

The javascript command is performed exactly at that moment.

At the exact moment of the pre-damage calculation you tell the engine "please reserve a spot in the common event execution list to execute this common event whenever you are processing that list in the future".

you just didn't give the command "execute this common event NOW", because that command does not exist in the default engine.
Yanfly had to write his own code for "execute CE now", because that code did not exist in MV either.

you need to find out which command Visustella made as the equivalent of that "execute now" from yanfly, and add that command into the <JS Pre-Damage> notetag instead of the default "please reserve for later".
So is this the same for any command or just the "reserve common event" one?

For instance would:

<JS Pre-Damage>
$gameVariables.setValue(1, 0);
</JS Pre-Damage>

be run before damage or after?
it is only for the "reserve" type functions.
your example with the variables setvalue would be executed before the damage calculation.

and as said I know that yanfly wrote MV code to execute common events directly, without using the reserve slot function - but I don't know how visustella handled that.
Then I can't get the value of the variable to change before the damage calculation.

Is this the proper syntax?

<JS Pre-Damage>
$gameVariables.setValue(1, 0);
</JS Pre-Damage>

Then after that the variable is included in the damage formula using v[1].
Then I can't get the value of the variable to change before the damage calculation.

Is this the proper syntax?

<JS Pre-Damage>
$gameVariables.setValue(1, 0);
</JS Pre-Damage>

Then after that the variable is included in the damage formula using v[1].
That would set variable 1 to have a value of 0, which would mean it had no effect on the formula.
Yup but it was to keep it simple here, the real code sets the value to 20000, sorry if I was unclear.
What happens is that the first use of that skill does 'normal' damage like 1000, and the second use of it a 20000+ damage, which means the tag was actually run after damage.
It's probably because you're using the variable in the damage formula and although pre-damage executes before the damage is applied, it doesn't actually recalculate the formula (which was evaluated before the notetag). You'd need to recalculate value.
Ah, I see.
Would there be a way to force a recalculation then?
value = yourformulahere

Or just change the variable in a <Pre-Apply> tag instead.
Just something like

Value = v[1]+a.atk-b.def;

?
Just something like

Value = v[1]+a.atk-b.def;

?
value = $gamevariables.value(1) + a.atk - b.def

Note that doing it this way will undo the application of defences and variance, though.
Thanks. What do you mean by defences?
Variance can be simulated directly in the formula but would it still evaluate element resistance? (maybe that's what you mean by defences?)
Thanks. What do you mean by defences?
Variance can be simulated directly in the formula but would it still evaluate element resistance? (maybe that's what you mean by defences?)
Yeah, that's what I meant. By the time you get to this point element rate and whatnot have already been calculated.
Ah. That's technically a bit of a problem.
Might have to drop elements for that skill then (unless another solution is found).
Ah. That's technically a bit of a problem.
Might have to drop elements for that skill then (unless another solution is found).
I gave you another solution above. use JS Pre-Apply instead of JS Pre-Damage.
I'm on phone now so I'll have to try it later. Thanks for the suggestion!

EDIT: Pre-Apply worked. Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/visustella-run-a-common-event-before-damage-calculation-in-a-skill.145466/