MV Looking for help with a plugin I am working on.

Hello folks, I am working on creating my first plugin after a couple years of learning/fighting with JS and RMMV's code structure blah blah and I need some help as I still have not enough clues as to what I am doing.
So the idea here is to create a simple plugin (since it's my first) that will allow your enemies to transform into variant forms (Ex: Elite/Champion/Etc) at the beginning of battles based upon a percentage chance that will later be configureable in parameter settings. I left those out for now to see if I could just produce something that works.
Thanks to Trihan's help a few years ago I got the basic functionality to run this as a script inside of the engine and call it via eventing. Sometime later I thought to myself I wanted to expand upon this however there is a limitation of what you can put in a script box as far as lines and the resources I came across here mentioned it was better to move it into a plugin, so here we are.

This and many other iterations I came up with but I can't seem to get it to work. I know am missing something but I can't seem to figure it out.

JavaScript:
function MyPlugin() {
    this.create();
}

MyPlugin.prototype.create = function() {
    this._scene = this;
    SceneManager.registerCallback('create', this, 'onCreate');
};

MyPlugin.prototype.onCreate = function(scene) {
    if (this._scene === scene) {
        $gameParty._championTransformer = new ChampionTransformer();
        $gameTroop.onTroopCreated.add(this.onTroopCreated.bind(this));
        this.transformEnemies();
    }
};

MyPlugin.prototype.onTroopCreated = function() {
    $gameTroop.onTroopCreated.remove(this.onTroopCreated.bind(this));
    if ($gameParty._championTransformer) {
        $gameParty._championTransformer.transformEnemies();
    }
};

var ChampionTransformer = function() {};
ChampionTransformer.prototype.transformEnemies = function() {
    for (const member of $gameTroop.members()) {
        const chance = Math.randomInt(101);
        if (chance >= 99) {
            const championId = member.enemy().meta.Champion;
            if (championId) {
                member.transform(Number(championId)) & member.recoverAll();
            }
        } else if (chance >= 50) {
            const eliteId = member.enemy().meta.Elite;
            if (eliteId) {
                member.transform(Number(eliteId)) & member.recoverAll();
            }
        }
    }
};
Okay, so right off the bat - what isn't working? Just saying
I can't seem to get it to work. I know am missing something but I can't seem to figure it out.
doesn't tell us anything. Does it crash? Are there errors in the Console? What do you expect to happen, and what's happening instead?

Telling us nothing is expecting the people willing to help you to read through your code, figure out what it's supposed to be doing, and tell what's being done wrong. 😉

But just scanning through:
JavaScript:
    SceneManager.registerCallback('create', this, 'onCreate');
...
MyPlugin.prototype.onCreate = function(scene) {
    if (this._scene === scene) {
This doesn't seem like it would work. Where is onCreate() being called with a type of scene passed as an argument such that the first line of code in it could ever test true?

And where is SceneManager.registerCallback() even coming from? It's not a default JavaScript function, it's not defined in MV's code, and it's not defined in your code.

So at this point, I need to stop there and ask whether you've even written this code or if it's AI-generated.
FWIW, if you have yanfly's plugins theres one that sounds like it does what you want out of the box
it i havent tried it to see if you can weigh the chance by putting multiple of the enemies in the same tag, but you probably wont have to edit it to do what you want
Okay, so right off the bat - what isn't working? Just saying

doesn't tell us anything. Does it crash? Are there errors in the Console? What do you expect to happen, and what's happening instead?

Telling us nothing is expecting the people willing to help you to read through your code, figure out what it's supposed to be doing, and tell what's being done wrong. 😉

But just scanning through:

This doesn't seem like it would work. Where is onCreate() being called with a type of scene passed as an argument such that the first line of code in it could ever test true?

And where is SceneManager.registerCallback() even coming from? It's not a default JavaScript function, it's not defined in MV's code, and it's not defined in your code.

So at this point, I need to stop there and ask whether you've even written this code or if it's AI-generated.
Sorry, I guess that would of been helpful to explain better...
The members of the troop are not transforming. The plugin runs and throws no console errors. I expect the troop members to transform and they do not.

Code:
for (const member of $gameTroop.members()) {
        const chance = Math.randomInt(101);
        if (chance >= 99) {
            const championId = member.enemy().meta.Champion;
            if (championId) {
                member.transform(Number(championId)) & member.recoverAll();
            }
        } else if (chance >= 50) {
            const eliteId = member.enemy().meta.Elite;
            if (eliteId) {
                member.transform(Number(eliteId)) & member.recoverAll();

This was written, the rest is AI. I attempted to take a working script and move it to a plugin.
Every single attempt ive made on my own is causing me to pull my hair out.
using AI and your mostly on your own as this forum doesn't allow AI content.
if you tell clear what you want to achieve and what it should do, just request
it and anyone willingly might take the request to make it it for you.

but there is also YEP_Transformations that probably do what you want unless
this does far differently.
This was written, the rest is AI.
And that's why it doesn't work. It really makes no logical sense to expect AI to be able to give you functional code of any complexity - it doesn't know things, by definition it's a generator, it makes things up.

If AI can't reliably answer grade school math questions or give you recipes that include edible ingredients, why would you trust it to be able to write code?

In any case, most knowledgeable coders here aren't willing to fix AI-generated code. And in this specific example, there's very little to fix - there's so much garbage that it basically needs to be entirely rewritten.

If you're interested in learning JavaScript and you have questions or things you need explained, there are people happy to help with that.

If you need to request or commission a plugin to be made for you entirely - and you can't just use the existing plugin that @Robro33 already suggested - there are people who can help with that. But most posters here are going to be turned off by someone who resorts to using AI instead of people who know things.
And that's why it doesn't work. It really makes no logical sense to expect AI to be able to give you functional code of any complexity - it doesn't know things, by definition it's a generator, it makes things up.

If AI can't reliably answer grade school math questions or give you recipes that include edible ingredients, why would you trust it to be able to write code?

In any case, most knowledgeable coders here aren't willing to fix AI-generated code. And in this specific example, there's very little to fix - there's so much garbage that it basically needs to be entirely rewritten.

If you're interested in learning JavaScript and you have questions or things you need explained, there are people happy to help with that.

If you need to request or commission a plugin to be made for you entirely - and you can't just use the existing plugin that @Robro33 already suggested - there are people who can help with that. But most posters here are going to be turned off by someone who resorts to using AI instead of people who know things.
From my long past experiences, no one is willing to help unless I go on discord. Unfortunately my discord wont work anymore thanks to some great authentication error after moving countries. I resort to AI for that reason, desperation, to avoid these forums, and discord. Theres such a flood of people that need help with stuff everywhere I try to do my best to figure it out on my own while grinding my head into the keyboard with the tools and limited knowledge I have available so that theres one less thing for someone else to try deal with so perhapes their time could be better spent elsewhere.

I never trusted it to write the code in it's entirety to a finished product, but I sure hoped it could give me something I could modify to complete and learn from. It is good to know it does nothing but create garbage though.

On another note, I just wanted to try and make something we all could use but according to Robro and Shadow it's already been done so I have no interest in it anymore. Thanks though.
I've played around with ChatGPT. Not everything it outputs is garbage, but it does flat out make up functions and properties that don't exist. It can also give you seemingly working code on the surface that's also mixed in with junk code.

It's an exercise in filtering out the chaff from the wheat and still requires you to have some level of programming knowledge to recognize what's good code or not and how to make it usable.
From my long past experiences, no one is willing to help
and from a guess, that is most likely due to you not giving the information needed to help.
like you didn't state whatz exactly is wrong in your topic here or failed to mention directly that it is AI generated (which is required by the forum rules).

If you check the million support topics that are answered (and quite a number by myself) you should see that questions ARE being answered, and ask yourself "why are mine not answered?".

A lot of those people who support here (all using their own free time for it, no one gets paid here) are simply tired of playing twenty questions first to even find out what the problem is, so that they can start looking for the cause only after said twenty questions.
And I openly admit - if I have to ask a question twice and still get no answer after explaining what and why I want that answer, then I usually stop helping in that topic. Because I don't have enough free time for all my own projects and don't see any need to help if my questions to the one seeking help are ignored.
I don't want to become over as rude or offensive.

but if you need a plugin or guidance what you need or what did work
with evented by Trihan's that you want to extend, be clear what it exactly does.
and how to extend that code instead in the way you need too.

a lot of good coders can give you info or help finish the code for you.
AI can be good as I use it for information only, but some use it to make plugins
that works, but in order to do that effectively, you need to know what you do,
how to debug, how to correct them etc.

Human code is far more effective, more readable, and far more compatible than
AI coding as it made a lot up, and use code used before elsewhere on the web.
which is on the other side "stealing" in some way.

if you can be clear what it exactly does, Robro suggestion can work, if it require
lunatic code to do it exactly what you needed, than you don't had to be do it so
complicated (unless it's a paid plugin and need an alternative), which is fine.
I never trusted it to write the code in it's entirety to a finished product, but I sure hoped it could give me something I could modify to complete and learn from.
I know how to code and even had a couple people pay me for it, and yet I've only made two standalone plugins. Almost everything I do is small blocks of code to run in the engine or edits to existing plugins.

If I don't know how to do something, I use an existing plugin that does something similar and edit its code until it does what I want (of course make sure it has edit permissions and properly attribute the original author).

Personally it's a lot faster and easier to make edits to existing plugins than write something from scratch.
From my long past experiences, no one is willing to help unless I go on discord.
I can't speak to that - you've started 3 threads aside from this one. Two of them received answers to your questions (one by me).

The only unanswered question you've asked here was for a very niche and rather complicated bit of code, which you never even bumped past the initial ask.

So, given you have a 3 out of 4 response rate and a 2 out of 3 answer rate, to tell us "no one is willing to help" is frankly a bit insulting.

And, beyond you, if you look at the number of threads in the Plugin Support, Plugin Requests, and Learning JavaScript sections that have replies and resolutions, your stance seems completely baseless.

I'm glad you found something that will do what you want in your game.
It's odd, the OP is at least the third person I've seen say they prefer to ask ChatGPT for help than these forums.

ChatGPT may be servicable for quick answers to simple problems that have been implemented thousands of times before, and thus has a large sample size of solutions to draw from, but not writing a custom plugin in full, which requires adherence to specific RPG Maker syntax and multiple moving parts working together.

The fastest way to solve your problem would still be to ask the forums "Is there a plugin that will do x?" then edit it if it's not a perfect fit for your use case.
I can't speak to that - you've started 3 threads aside from this one. Two of them received answers to your questions (one by me).

The only unanswered question you've asked here was for a very niche and rather complicated bit of code, which you never even bumped past the initial ask.

So, given you have a 3 out of 4 response rate and a 2 out of 3 answer rate, to tell us "no one is willing to help" is frankly a bit insulting.

And, beyond you, if you look at the number of threads in the Plugin Support, Plugin Requests, and Learning JavaScript sections that have replies and resolutions, your stance seems completely baseless.

I'm glad you found something that will do what you want in your game.
Sorry for insulting you. Yes it is baseless, sorry for writing dumb sht out of frustration.

I didn't check into the suggested options yet. Figuring it out on my own is infurating to the point of madness but.. I want it.
I went back in and rewrote everything my self and what I didn't know I went and look at examples of how others were doing it.
I have something now.. It works sorta.. but doesn't iterate through every enemy troop memeber I have to figure out how to use for and forEach now..

but if you need a plugin or guidance what you need or what did work
with evented by Trihan's that you want to extend, be clear what it exactly does.
and how to extend that code instead in the way you need too.
Yeah, everytime I come here I forget how precise i need to be when asking for help on these topics.. and always leave out important information. Side effect of being an idiot.

It's odd, the OP is at least the third person I've seen say they prefer to ask ChatGPT for help than these forums.

ChatGPT may be servicable for quick answers to simple problems that have been implemented thousands of times before, and thus has a large sample size of solutions to draw from, but not writing a custom plugin in full, which requires adherence to specific RPG Maker syntax and multiple moving parts working together.
Not that it's really relivant but, I used a custom model and tried to teach it everything that MV does and how it works and supplied it all the files for referencing etc..
It did help some, but no where near useable for modifying or learning much from.
I prefer not to ask for help in general unless desperate, personal character flaw i guess.
ask, leave details what you need is best. (I'm still learning too).
as for the coders does those willingly for free if it's an easy plugin for
the rest to use.

each coder has it's own way of coding, but you can understand it.

forEach loop isn't always the best way as you can use sometimes
the "for (enemy of enemies)" to interate or "i = 0, i < len" for another way.

there are ways to iterate the array, the best way depends on the situation.
but tell us what you seek and let us try to help you out.

this is far more efficient if one is able, not telling will leave you with no help.
something you don't want in the future if you keep ignoring the questions
we ask you.
ask, leave details what you need is best. (I'm still learning too).
as for the coders does those willingly for free if it's an easy plugin for
the rest to use.

each coder has it's own way of coding, but you can understand it.

forEach loop isn't always the best way as you can use sometimes
the "for (enemy of enemies)" to interate or "i = 0, i < len" for another way.

there are ways to iterate the array, the best way depends on the situation.
but tell us what you seek and let us try to help you out.

this is far more efficient if one is able, not telling will leave you with no help.
something you don't want in the future if you keep ignoring the questions
we ask you.
Ok. So heres what I did and I am not sure how much of it needs to be seen to understand it so I will just put all of it below.. I apologize for the length..

Currently it works but not as intended, no console errors. I think I got it checkin each member but not sure if it is behaving correctly? but/or it looks like the math of how it applies chance is very wrong. There are way to many transforms for a total 6% probability per each. Maybe the parameters are setup wrong.
JavaScript:
/*: @plugindesc Testing Plugin
Short description here.  Plugin Test

* @author Name goes here.

* @help
* This is where the help text will go.
How it works..


* @param ---Settings---
* @default

* @param Elite Chance
* @parent ---Settings---
* @type number
* @min 0
* @max 101
* @desc Chance (in %) for an enemy to be transformed into an Elite
* Default: 3%
* @default 3

* @param Champion Chance
* @parent ---Settings---
* @type number
* @min 0
* @max 101
* @desc Chance (in %) for an enemy to be transformed into a Champion
* Default: 1%
* @default 1

* @param Mimic Chance
* @parent ---Settings---
* @type number
* @min 0
* @max 102
* @desc Chance (in %) for an enemy to be transformed into a Mimic
* Default: 1%
* @default 1
*/


// Parameter setup
var Jrs = Jrs || {};
Jrs.Parameters = PluginManager.parameters('A_Spawn');
Jrs.Param = Jrs.Param || {};

Jrs.Param.TFElite = Number(Jrs.Parameters['Elite Chance']);
Jrs.Param.TFChamp = Number(Jrs.Parameters['Champion Chance']);
Jrs.Param.TFMimic = Number(Jrs.Parameters['Mimic Chance']);



// Roll chance for each enemy troop member and exec.
Game_Battler.prototype.transformEnemies = function () {
    for (const member of $gameTroop.members()) {
      const chance = Math.randomInt(102);
    
    if (chance >= Jrs.Param.TFMimic) {
      const mimicId = member.enemy().meta.Mimic;
      if (mimicId) member.transform(Number(mimicId)) & member.recoverAll();
        console.log('Transformation successful');
      }
    
    else if (chance >= Jrs.Param.TFChamp) {
      const championId = member.enemy().meta.Champion;
      if (championId) member.transform(Number(championId)) & member.recoverAll();
        console.log('Transformation successful');
    }

    else if (chance >= Jrs.Param.TFElite) {
      const eliteId = member.enemy().meta.Elite;
      if (eliteId) member.transform(Number(eliteId)) & member.recoverAll();
        console.log('Transformation successful');
    }

  }
}
//Ignore testing lines
//$gameTroop.members().forEach(function(enemy) {
//  enemy.recoverAll();
//});

// Call the transformEnemies function at the beginning of every battle.
Jrs.Game_Battler_onBattleStart = Game_Battler.prototype.onBattleStart;
Game_Battler.prototype.onBattleStart = function() {
    Jrs.Game_Battler_onBattleStart.call(this);
    this.transformEnemies();
  };

I seek to have it pick a random number for a member of the enemy troop. Then the number should be checked between the transform conditions starting at the first condition, the checking the second, etc.
Not sure if that is a good or optimal way to check conditions per the use case.
Then it should move on to the next member of the troop until all troop members are checked.

I am also not sure if I need to put in some sorta safety check to return a null? if no conditions were met?
& should be && not a single one if you want both to happen.
chance can also be individual per enemy.

what ID would be the enemy be or transform into?
the way you do <mimic: 4> to transform to id 3?
& should be && not a single one if you want both to happen.
chance can also be individual per enemy.

what ID would be the enemy be or transform into?
the way you do <mimic: 4> to transform to id 3?
I wanted to do chance individual per enemy. It appears to work but with unusually high rates even when set VERY low, almost like its iterating over an enemy multiple times.

The ID would be,
<ExampleType: 4> Transforms to ID 4
try if this works as I don't want to test it as it can use both note tag
and parameter change (helpfile adjusted).

keep it filename "A_Spawn" for as that's how the parameter is readed.
change it and it fails it (based on helpfile how you name it).

see if it works (console logs are there if succeed or failed (try both ways)
to be sure its working or not. (no promises though) but it can give you the way
to go from.
try if this works as I don't want to test it as it can use both note tag
and parameter change (helpfile adjusted).

keep it filename "A_Spawn" for as that's how the parameter is readed.
change it and it fails it (based on helpfile how you name it).

see if it works (console logs are there if succeed or failed (try both ways)
to be sure its working or not. (no promises though) but it can give you the way
to go from.

Thanks, ill have a look into it more indepth later after coffee and brain cogs are moving.

Original thread: https://forums.rpgmakerweb.com/threads/looking-for-help-with-a-plugin-i-am-working-on.173978/