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.
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();
}
}
}
};