Help turning a script into a plug-in

I'm creating a script that, instead of adding things to the main engine, does some numbercrunching on its own.  I designed it to emulate a d20 engine, where a d20 is rolled, have a tallied-up bonus to the result, and is compared to a set number to determine Success or Failure.

Below is the plug-in I'm making right now.  The actual scripts themselves are sound enough, barring noobie syntax errors.  It's setting the script up into a Plugin so I can use in MV that's the trick.  Any help here will be greatly appreciated 🙂 Thanks in advance.

Code:
//=============================================================================// The Elminister Engine// by David Foxfire// Version 0.10 Alpha   //=============================================================================  /*: * @plugindesc The Elminister Engine emulates D&D 5E rules into exploration and interaction.   // Describe your plugin * @author David Foxfire        // your name goes here * * @param xxxxx      //name of a parameter you want the user to edit * @desc yyyyy       //short description of the parameter * @default zzzzz    // set default value for the parameter  */ /* This is put out there for help in how to build a plug-in for MV.  Unlike most plugins, this only adds the number of funcitons I needed to implement a d20 style random roll for exploration and interaction. Similar to D&D, the plugin tallies up an modifier based on attributes and skills being used, it is added to a d20 roll, and its result is sent to the event that calls for this roll. The funcitons itself are sound--although some proofreading for syntax is appreciated, it is converting it into a working plugin that plays well with RPG Maker MV that I need help with.  Every bit of assistance will be greatly appreciated. Thanks in advance. */"use strict";var ElministerEngine = ElministerEngine || {};ElministerEngine["Partitioned Random"] = "v1.00a";ElministerEngine.Partitioned_Random = {/*The array is set for five indifidual characters, each with six attributes: STR, DEX, CON, INT, WIS, and CHA.in LoadCharacterArray (), this array is loaded in the game.variables for use further down this plugin.*/	function LoadCharacterArray () {	    var Attribute_Array = [ [0, 1, 1, 3, 3, 2],  	                            [3, 1, 3, 0, 1, 3],  	                            [0, 2, 0, 1, 1, 3], 	                            [2, 2, 1, 2, 1, 1], 	                            [1, 3, 0, 2, 1, 2] ];	    var Table_Start = 100 //could be game.variables(50)	    function load_array () {	        for (var a=0, a<5, a++) {	            for (var b=0, b<6, b++) {	                game.variables (Table_Start + (a * 6) +  = Attribute_Array[a,b];	            }	        }	    }	}	function callAttributeModifier (pcNumber, pcAttribute) {	    var attribution_index = 100 + ( pcNumber * 6) + pcAttribute ;	    return game.variable (attribution_index);	}	function Roll20 (modifier, advantage) {		var rollOne = Math.floor((Math.random()*20)+1);		var rollTwo = Math.floor((Math.random()*20)+1);		var dieResult = 0;		switch (advantage){			case -1:				if (rollOne < RollTwo){					dieResult = rollOne;				}				else {					dieResult = rollTwo;				}				break;			case 0:				dieResult = rollOne;				break;			case 1:				if (rollOne > rollTwo){					dieResult = rollOne;				}				else {					dieResult = rollTwo;				}		}		if (dieResult) === 20 {			return ("Nat Crit!");		}		else{			return (dieResult + modifier);		}	}	function individual_check (pcNumber, pcAttribute, pcSkill) {	    var pcAttriModifier = callAttributeModifier (pcNumber, pcAttribute);	    //aquire Level-based proficiency	    var pcLevelProficiency = 1 + parseInt ($game_actors[pcNumber].level / 10);	    //aquire additional modifiers. Base them on particular skills	    var additionalModifiers = 0;	    var advantageFlag = 0;	    var checkBoost = 0;	    if ($game.switch (51) === 1){	        advantageFlag = -1;	    }	    switch (pcSkill){	        case null:	        //add nothing, it's just an attribute check.	        break;	        case Acro: // Acrobatics	        //If it's Shandie doing it, do it with advantage.	        if ($game_party.members.include?(4)){	            advantageFlag++;	        }	        break;	        case Anim: // Animal Handling	        //Delina's good with animals, add 2 as an assist.	        if (pcNumber === 2){	            advantageFlag++;	        }	        else {	            if ($game_party.members.include?(2)){ // check to see that this is the right function <----	                additionalModifiers = 2;	            }	        }	        break;	        case Arca: // Arcana	        //If either Florence or Delina doing it, add advantage. Otherwise, add 2, 4 if Delina is present	        if (pcNumber instanceof [0,2]) {	            advantageFlag++;	        }	        else {	            additionalModifiers = 2;	            if ($game_party.members.include?(2)){ // check to see that this is the right function <----	                additionalModifiers = 4;	            }	        }	        break;	        case Athl: // Athletics	        // If Minsc is doing it, add advantage, Otherwise, he assists	        if (pcNumber === 1) {	            advantageFlag++;	        }	        else {	            additionalModifiers = 2;	        }	        break;	        case Dece: // Deception	        // Krydle is proficient, and can assist if present	        if (pcNumber instanceof [3]) {	            advantageFlag++;	        }	        else {	            if ($game_party.members.include?(3)){ // check to see that this is the right function <----	                additionalModifiers = 2;	            }	        }	        break;	        case Hist: //History	        // Florence and Krydle are proficienct, and can assist	        if (pcNumber instanceof [0,3]) {	            advantageFlag++;	        }	        else {	            additionalModifiers = 2;	            if ($game_party.members.include?(3)){ // check to see that this is the right function <----	                additionalModifiers = 4;	            }	        }	        break;	        case Insi: // Insight	        //Florence is not just proficient, but she has the Chosen of Oghma feature, flash of insight	        if (pcNumber === 0) {	            checkBoost = determine_Flash.of.Insight (); // design new function here!! <-----	            advantageFlag++;	        }	        else{	            additionalModifiers = 2;	        }	        break;	        case Inti: //Intimidation	        // Minsc is proficient	        if (pcNumber === 1) {	            advantageFlag++;	        }	        else {	            additionalModifiers = 2;	        }	        break;	        case Inve: //Investigation	        // Florence is proficient, in fact, she's has expertise in it	        if (pcNumber === 0) {	            advantageFlag++;	            checkBoost = 5;	        }	        else {	            additionalModifiers = 5;	        }	        break;	        case Medi: //Medicine	        // Florence is proficient	        if (pcNumber === 0) {	            advantageFlag++;	        }	        else {	            additionalModifiers = 2;	        }	        break;	        case Natu: //Nature	        // Minsc and Delina are proficient	        if (pcNumber instanceof [1,2]) {	            advantageFlag++;	        }	        else {	            additionalModifiers = 2;	        }	        break;	        case Perc: //Perception	        // Perception is a special case. More often, it's done on the map itself, 	        // where a glitter is shown over a clue, either outright or when the player	        // is close enough to the clue to make it appear. But there will be times	        // when a check is needed.	        //	        // Florence is proficient	        if (pcNumber === 0) {	            advantageFlag++;	        }	        else {	            additionalModifiers = 2;	        }	        break;	        case Perf: //Performance	        // _Nobody_ is proficient in this. What do you expect, to have Pippkin	        // or Johnny Briz in here? And nobody's dating a spoony bard!	        break;	        case Pers: //Persuasion	        // Florence and Krydle are proficient	        if (pcNumber instanceof [0,3]) {	            advantageFlag++;	        }	        else {	            additionalModifiers = 2;	            if ($game_party.members.include?(3)){ // check to see that this is the right function <----	                additionalModifiers = 4;	            }	        }	        break;	        case Pick: //Pick Lock	        // Shandie is proficient, and will use lockpicks	        if (pcNumber === 5) {	            advantageFlag++;	        }	        checkBoost = Determine_Lockpick (); // New Function here <-----	        break;	        case Reli: //Religion	        // Florence is proficient, and can assist	        if (pcNumber === 0) {	            advantageFlag++;	        }	        else {	            additionalModifiers = 2;	        }	        break;	        case Slig: //Slight of Hand	        //Krydle and Shandie are proficient.	        if (pcNumber instanceof [3,4]) {	            advantageFlag++;	        }	        break;	        case Stea: //Stealth	        // This is usually a group check, because while Krydle and Shandie are proficient, 	        // and Krydle might break off to do Anonymous Work, neither Krydle and Shandie will	        // split from the party to do solo missions. But there may be instances where either	        // one will split off and take point.	        if (pcNumber instanceof [3,4]) {	            advantageFlag++;	        }	        break;	        case Surv: //Survival	        //Minsc is proficient and will asssist.	        if (pcNumber === 1) {	            advantageFlag++;	        }	        else {	            additionalModifiers = 2;	        }	        break;	        case Thie: //Thievery	        // Krydle and Shandie are proficient. If Krydle is present, he will assist Shandie.	        if (pcNumber instanceof [3,4]) {	            advantageFlag++;	        }	        else {	            if ($game_party.members.include?(3)){ // check to see that this is the right function <----	                additionalModifiers = 2;	            }	        }	        break;	    }	    // Now we got our modifiers, let's roll dice:	    if (advantageFlag === 0){	       if ($game.switch (50) === 1){	          advantage.flag = 1;	       }	    }	    var total_modifier = pcLevelProficiency + additionalModifiers + checkBoost;	    var dice_result = Roll20 (total_modifier, advantageFlag);	    $game.switch (50) = false;	    $game.switch (51) = false;	    return dice_result;	}	function Team_Check (pcAttribute, pcSkill){	    //this is for a team effort. The modifiers are tallied up and then averaged, which 	    //will be added to the d20 roll.	    var Team_Modifiers = [];	    var Team_Attendance = [];	    var checkBoost = 0;	    for (var a=0; a<5, a++){	        if ($game_party.members.include?(a)) {	            Team_Attendance [a] = true;	            Team_Modifiers [a] = callAttributeModifier (a, pcAttribute) + 1 + parseInt ($game_actors[pcNumber].level / 10);	        }	        else{	            Team_Attendance [a] = false;	        }	    }	    switch (pcSkill){	        case null:	        //add nothing, it's just an attribute check.	        break;	        case Acro: // Acrobatics	        //If it's Shandie doing it, do it with advantage.	        break;	        case Anim: // Animal Handling	        //Delina's good with animals, add 2 as an assist.	        if (Team_Attendance [2]){ // check to see that this is the right function <----	            Team_Modifiers [2] += 2;	        }	        break;	        case Arca: // Arcana	        //If either Florence or Delina doing it, add advantage. Otherwise, add 2, 4 if Delina is present	        Team_Modifiers [0] += 2;	        if (Team_Attendance [2]){ // check to see that this is the right function <----	            Team_Modifiers [2] += 2;	        }	        break;	        case Athl: // Athletics	        // If Minsc is doing it, add advantage, Otherwise, he assists	        Team_Modifiers [1] += 2;	        break;	        case Dece: // Deception	        // Krydle is proficient, and can assist if present	        if (Team_Attendance [3]){ // check to see that this is the right function <----	            Team_Modifiers [3] += 2;	        }	        break;	        case Hist: //History	        // Florence and Krydle are proficienct, and can assist	        Team_Modifiers [0] += 2;	        if (Team_Attendance [2]){ // check to see that this is the right function <----	            Team_Modifiers [2] += 2;	        }	        break;	        case Insi: // Insight	        //Florence is not just proficient, but she has the Chosen of Oghma feature, flash of insight	        checkBoost = determine_Flash.of.Insight (); // design new function here!! <-----	        Team_Modifiers [0] += (2 + checkBoost);	        for (var b=1; b<5; b++ ){	            if (Team_Attendance [b]){	                Team_Modifiers [b] += checkBoost;	            }	        }	        break;	        case Inti: //Intimidation	        // Minsc is proficient	        Team_Modifiers [1] += 2;	        break;	        case Inve: //Investigation	        // Florence is proficient, in fact, she's has expertise in it	        Team_Modifiers [0] += 5;	        break;	        case Medi: //Medicine	        // Florence is proficient	        Team_Modifiers [0] += 2;	        break;	        case Natu: //Nature	        // Minsc and Delina are proficient	        Team_Modifiers [1] += 2;	        if (Team_Attendance [2]){ // check to see that this is the right function <----	            Team_Modifiers [2] += 2;	        }	        break;	        case Perc: //Perception	        // Perception is a special case. More often, it's done on the map itself, 	        // where a glitter is shown over a clue, either outright or when the player	        // is close enough to the clue to make it appear. But there will be times	        // when a check is needed.	        break;	        case Perf: //Performance	        // _Nobody_ is proficient in this. What do you expect, to have Pippkin	        // or Johnny Briz in here? And nobody's dating a spoony bard!	        break;	        case Pers: //Persuasion	        // Florence and Krydle are proficient	        Team_Modifiers [0] += 2;	        if (Team_Attendance [3]){ // check to see that this is the right function <----	            Team_Modifiers [3] += 2;	        }	        break;	        case Pick: //Pick Lock	        // Shandie is proficient, and will use lockpicks	        break;	        case Reli: //Religion	        // Florence is proficient, and can assist	        Team_Modifiers [0] += 2;	        break;	        case Slig: //Slight of Hand	        //Krydle and Shandie are proficient.	        break;	        case Stea: //Stealth	        // This is usually a group check, because while Krydle and Shandie are proficient, 	        // and Krydle might break off to do Anonymous Work, neither Krydle and Shandie will	        // split from the party to do solo missions. But there may be instances where either	        // one will split off and take point.	        Team_Modifiers [4] += 2;	        if (Team_Attendance [3]){ // check to see that this is the right function <----	            Team_Modifiers [3] += 2;	        }	        break;	        case Surv: //Survival	        //Minsc is proficient and will asssist.	        Team_Modifiers [1] += 2;	        break;	        case Thie: //Thievery	        // Krydle and Shandie are proficient. If Krydle is present, he will assist Shandie.	        break;	    }	    // Now let's average the modifiers and roll dice.	    var total_modifier = 0;	    var total_present = 0;	    	    for (var c=0; c<5, c++){	        if (Team_Attendance [c] {	            total_present++;	            total_modifier += Team_Modifiers [c];	        }	    }	    	    total_modifier = parseInt(total_modifier/total_present);	    var dice_result = Roll20 (total_modifier, 0);	    return dice_result;	}}
I'm interested in this part:

function load_array () { for (var a=0, a<5, a++) { for (var b=0, b<6, b++) { game.variables (Table_Start + a + = Attribute_Array[a,b]; } } }So it seems to me that both game.variables (Table_Start + a + 😎 = Attribute_Array[a,b] and game.variables (Table_Start + b + a) = Attribute_Array[b,a] will be run.

But as Table_Start + a + b === Table_Start + b + a, I think that both Attribute_Array[a,b] and Attribute_Array[b,a] will be assigned to the same game variable 🙂
I'm interested in this part:

function load_array () { for (var a=0, a<5, a++) { for (var b=0, b<6, b++) { game.variables (Table_Start + a + = Attribute_Array[a,b]; } } }So it seems to me that both game.variables (Table_Start + a + 😎 = Attribute_Array[a,b] and game.variables (Table_Start + b + a) = Attribute_Array[b,a] will be run.

But as Table_Start + a + b === Table_Start + b + a, I think that both Attribute_Array[a,b] and Attribute_Array[b,a] will be assigned to the same game variable 🙂
Whoops!  I forgot something important there.   It was supposed to be Table_Start + (a*6) + b is it.   Thanks for bringing that to my attention.

Original thread: https://forums.rpgmakerweb.com/threads/help-turning-a-script-into-a-plug-in.47936/