Is it possible to generate a troop encounter by using script calls?

Status
Not open for further replies.

jetboost

Veteran
Veteran
Joined
Sep 29, 2016
Messages
84
Reaction score
26
First Language
Dutch
Primarily Uses
RMMV
I don't have any time left today to search through google and the code of RPG maker MV to find my answer so i'm hoping someone can help me answer this and show me how.

My earlier assumption was that a troop was generated from the info stored in $dataTroops[id] and so I made a line of code to test it in the debug console:
Code:
var b = [1,2];var posX = [281,251];var posY = [444,343];
for(i=0;i<b.length;i++){
var c = $dataTroops[25].members.length;$dataTroops[25].members.push({});
$dataTroops[25].members[c][c]={enemyId:b[i],hidden:false,x:posX[i],y:posY[i]}
}
And called the battle like this:
Code:
BattleManager.setup(25, true, true);
$gamePlayer.makeEncounterCount();
SceneManager.push(Scene_Battle);
But I simply get the an empty troop encounter (As it is in the database).

Any help/answer is appreciated.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
Code:
$dataTroops[25].members[c][c]={enemyId:b[i],hidden:false,x:posX[i],y:posY[i]}
You have two cs there. You should only have one.
 

jetboost

Veteran
Veteran
Joined
Sep 29, 2016
Messages
84
Reaction score
26
First Language
Dutch
Primarily Uses
RMMV
Code:
$dataTroops[25].members[c][c]={enemyId:b[i],hidden:false,x:posX[i],y:posY[i]}
You have two cs there. You should only have one.
If I would change that then the structure as I see it in the debug console will differ in comparison with an troop created in the database.
If you type this in the debug:
Code:
$dataTroops[someID].members
You will see that they have put the troop member's info inside an object named "0"
Also the object is stored in an array thus at array index [0] is an object named "0".

I'm still willing to test your method, however currently I can't it has to wait till tonight or tomorrow.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
No, it's not in object called 0! It's an object that's in the first place inside an array and hence it has an index 0.
 

EthanFox

Veteran
Veteran
Joined
Oct 15, 2018
Messages
439
Reaction score
330
First Language
English
Primarily Uses
RMMV
Not sure if it helps, but there are plugins that allow you to "summon" enemies from other troops into a battle. This means you could start a battle and summon the necessary troops on startup, which would kinda allow you to do this.
 

jetboost

Veteran
Veteran
Joined
Sep 29, 2016
Messages
84
Reaction score
26
First Language
Dutch
Primarily Uses
RMMV
No, it's not in object called 0! It's an object that's in the first place inside an array and hence it has an index 0.
Well....... It works must have gotten confused somewhere.

Thank you very much for pointing it out to me now I can continue with it.

Now i'm really gone gotta go to work someone else is doing dinner now.
 

jetboost

Veteran
Veteran
Joined
Sep 29, 2016
Messages
84
Reaction score
26
First Language
Dutch
Primarily Uses
RMMV
Not sure if it helps, but there are plugins that allow you to "summon" enemies from other troops into a battle. This means you could start a battle and summon the necessary troops on startup, which would kinda allow you to do this.
This would be nice but not entirely what i'm searching for but i'd like to still have a look at it.

Poryg was right about what the problem was so I can continue.
Still thanks for offering a hand though.
 

Wavelength

MSD Strong
Global Mod
Joined
Jul 22, 2014
Messages
5,624
Reaction score
5,104
First Language
English
Primarily Uses
RMVXA

I've moved this thread to Learning JavaScript. Please be sure to post your threads in the correct forum next time. Thank you.


Learning JS is a good board to ask questions about how MV's default codebase works so that you can replicate and modify stuff on your own.

Additionally:

@jetboost, please avoid double posting, as it is against the forum rules. You can use the "Edit" function on your posts to add additional information you've forgotten or respond to multiple people. You can review our forum rules here. Thank you.


If you need to quote multiple posts, use the Multi-Quote function (click on the "+ Quote" link below each post, then click the "Insert Quotes" button below the box where you type your response).
 

Adventurer_inc.

Technically a Programmer
Veteran
Joined
Sep 12, 2015
Messages
99
Reaction score
41
First Language
English
Primarily Uses
RMMV
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.
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
@Adventurer_inc. Not for nothing, but all these shenanigans got automated by the OP creating a new entry inside $dataTroops and hence are not needed. The only thing worth noting is that the $dataTroops gets reset to its normal state after game restart, but that's why there's the troop definition.
 

Adventurer_inc.

Technically a Programmer
Veteran
Joined
Sep 12, 2015
Messages
99
Reaction score
41
First Language
English
Primarily Uses
RMMV
@Poryg True, but it seemed like jetboost was trying to call a battle and inject enemies into a battle. The process I went through is exactly how you would do it, messy as it is. No script edits, no plugin, and little conflicts; just clean in one way and out the other. It can now be easily automated however you want.
 

Ms Littlefish

Dangerously Caffeinated
Global Mod
Joined
Jan 15, 2014
Messages
6,417
Reaction score
8,102
First Language
English
Primarily Uses
RMMV

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,975
Members
137,563
Latest member
cexojow
Top