Battles are instances. I'm going to give you a rough idea of exactly what you need:
Code:
// rpg_manager.js
BattleManager.setup = function(troopId, canEscape, canLose) {
this.initMembers();
this._canEscape = canEscape;
this._canLose = canLose;
$gameTroop.setup(troopId);
$gameScreen.onBattleStart();
this.makeEscapeRatio();
};
// rpg_object.js
Game_Troop.prototype.setup = function(troopId) {
this.clear();
this._troopId = troopId;
this._enemies = [];
this.troop().members.forEach(function(member) {
if ($dataEnemies[member.enemyId]) {
var enemyId = member.enemyId;
var x = member.x;
var y = member.y;
var enemy = new Game_Enemy(enemyId, x, y);
if (member.hidden) {
enemy.hide();
}
this._enemies.push(enemy);
}
}, this);
this.makeUniqueNames();
};
To script a battle you'll have to call both BattleManager and Game_Troop from the scene but to get a default battle you'll have to copy and paste with a few changes.
All of the "this" in the BattleManager.setup function becomes "BattleManager" and all of the "this" in the Game_Troop.setup function must become "$gameTroop".
The "$gameTroop.setup(troopId);" inside BattleManager.setup must then be replaced by all of the Game_Troop.setup's code.
You'll get something roughly like this:
Code:
//You are now missing parameters troopId, canEscape, canLose. Those must be filled in with values
var troopId = 2; // This is the base troop
var canEscape = true;
var canLose = true;
BattleManager.initMembers();
BattleManager._canEscape = canEscape;
BattleManager._canLose = canLose;
// Game_Troop.prototype.setup
$gameTroop.clear();
$gameTroop._troopId = troopId;
$gameTroop._enemies = [];
$gameTroop.troop().members.forEach(function(member) {
if ($dataEnemies[member.enemyId]) {
var enemyId = member.enemyId;
var x = member.x;
var y = member.y;
var enemy = new Game_Enemy(enemyId, x, y);
if (member.hidden) {
enemy.hide();
}
$gameTroop._enemies.push(enemy);
}
}, $gameTroop);
$gameTroop.makeUniqueNames();
//
$gameScreen.onBattleStart();
BattleManager.makeEscapeRatio();
Now things will get tricky. Inside the $gameTroop.troop().members.forEach is where enemies are generated and pushed into the current instance. To add enemies you'll have to generate enemies and push them in. It can be done like so, as an example:
Code:
//You are now missing parameters troopId, canEscape, canLose. Those must be filled in with values
var troopId = 2; // This is the base troop
var canEscape = true;
var canLose = true;
BattleManager.initMembers();
BattleManager._canEscape = canEscape;
BattleManager._canLose = canLose;
// Game_Troop.prototype.setup
$gameTroop.clear();
$gameTroop._troopId = troopId;
$gameTroop._enemies = [];
$gameTroop.troop().members.forEach(function(member) {
if ($dataEnemies[member.enemyId]) {
var enemyId = member.enemyId;
var x = member.x;
var y = member.y;
var enemy = new Game_Enemy(enemyId, x, y);
if (member.hidden) {
enemy.hide();
}
$gameTroop._enemies.push(enemy);
}
}, $gameTroop);
$gameTroop.makeUniqueNames();
//
// Manual generation of an enemy Id 3 at location 300, 300 on the battle screen
var enemyId = 3;
var x = 300;
var y = 300;
var enemy = new Game_Enemy(enemyId, x, y);
if (false) { // Do you want the enemy to be hidden?
enemy.hide();
}
$gameTroop._enemies.push(enemy);
//
$gameScreen.onBattleStart();
BattleManager.makeEscapeRatio();
Now that setup is done just run:
Code:
SceneManager.push(Scene_Battle);
A bit of warning because you are injecting directly into the instance the injection will be deleted when the instance is deleted and because the instance won't match the database, default troop event calls and other plugins will most likely be buggy.