MZ Javascript help with Item Crafting System VisuStella MZ (Call common event & check variable in javascript).

Hello there, hope you're doing well!

I need help with my game, there's a short description first and a long one further down.
I really hope some of you fine folk can help me out.

I am implementing the Item Crafting System VisuStella MZ into my game, and I have a problem. This plugin is open for Javascript code, and I need to know how to do the following in Javascript code:

Call a common Event (which will set a value to either 1 or 0)
Check if the variable is 1 (or not)
Set the crafted item number to zero if it isn't.

Longer explanation following:
My game features a skill system where every skill is expressed as a number between 1 and 100. When using a skill, the game takes the current skill value and add a random number between 1 to 100, if this result exceeds the Challenge Rating (usually 100) the skill succeeds, and the common event spits out a 1. If it fails, it spits out a 0.
In the case of a 1, the player gets some XP, in the case of a 0, the player gets more XP.
This all works perfectly.

What I want is for when player uses the plugin to create an item (food mostly), the plugin runs the common event for Cooking, then checks if the player succeeded or not. If they did (variable is 1), the plugin just runs like normal but if they fail the plugin sets the amount of created items to zero, resulting in the player losing their ingredients but gaining nothing but xp (and bitter tears).

To be clear, I need a javascript code that:
1: Runs a common event.
2: Checks if a variable is 1 or 0.
3: Sets the plugin variable for items to 0. (This one I might be able to fix myself, as it is included in the plugin description, and requires familiarity with this specific plugin).

Appreciate any help on my project!

Thanks in advance!
- Lars.

Edited: Replaced Java with Javascript after being told that these are in fact two separate languages.
I dont own MZ, but keep in mind, MZ DONT use java, but javascript!
it's 2 completely different languages.

if the param is 1 or 0, it mostly checks 1 (true) or 0 (false).
while I dont know the params for those, I cannot be certain.

if it's a range of 1 = 100%, and 0 = 0%, you need 0.3 (30%).
but if it's explained in the helpfile, follow it, there is also a MZ Demo
that can be used if it's explained in there.
I dont own MZ, but keep in mind, MZ DONT use java, but javascript!
it's 2 completely different languages.

if the param is 1 or 0, it mostly checks 1 (true) or 0 (false).
while I dont know the params for those, I cannot be certain.

if it's a range of 1 = 100%, and 0 = 0%, you need 0.3 (30%).
but if it's explained in the helpfile, follow it, there is also a MZ Demo
that can be used if it's explained in there.
I apparently don't even know what I don't know at this point.
Thank you for your information about the Javascript/Java thing, I assumed it was the same thing.

I will check out the MZ demo or helpfile and see if I can find something there.

"if it's a range of 1 = 100%, and 0 = 0%, you need 0.3 (30%)."
I did not understand that at all. The variable is assigned in a Common Event, which works. I just need to know how to tell the Javascript code to Check variable and then do an act if 1 or 0. (or if 1, or ELSE).

Anyway, thanks for replying!
To be clear, I need a javascript code that:
1: Runs a common event.
2: Checks if a variable is 1 or 0.
3: Sets the plugin variable for items to 0. (This one I might be able to fix myself, as it is included in the plugin description, and requires familiarity with this specific plugin).
1: this snippet of code will manually execute a common event
JavaScript:
// where COMMON_EVENT_ID is the id of the comment event you want to execute.
$gameTemp.reserveCommonEvent(COMMON_EVENT_ID);
2: probably would happen within the common event you're executing. If you absolutely need javscript for it...
JavaScript:
// where VARIABLE_ID is the id of the variable you are checking.
$gameVariables.value(VARIABLE_ID) === 1;
// will return a boolean of either true or false.
3: I'm not familiar with the plugin. I downloaded it, looked at it, and decided to write my own crafting system lol.
This will not work in the way you want it to.

While you can use the code snippet posted above to reserve a common event, the event itself will not occur until the player is back on the map scene. As I expect the item crafting plugin uses some sort of menu scene, the player will never be on the map scene at the same time the crafting is going on, so any common event reserved in the middle of crafting will not execute until long after the craft has completed, and as such, it will not be able to modify the quantity of items given.

You could use whatever JS parameter you've got to make a random roll check using $gameVariables.setValue(varId, value), using Math.random() to roll from 0-1 multiply by 100 and compare to your skill level variable. I don't have the VisuMZ crafting plugin, though, so even if you could do that, you'd have to hope there's a way of changing the returned number of crafted items AFTER that check was made. Overall their vision for what the system is, and how it can be modified is pretty rigid, so it might not be easy, or even possible to do this.

There are other crafting plugins available that support crafting experience and skill levels and whatnot though. Some of them even have tutorials on this very website 😉

Original thread: https://forums.rpgmakerweb.com/threads/javascript-help-with-item-crafting-system-visustella-mz-call-common-event-check-variable-in-javascript.134507/